Library was not compiling on FreeBSD 7. Code now no longer uses

ftime(), using gettimeofday() instead. Thanks to Josh Carroll.


git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@270 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2007-12-17 01:15:53 +00:00
parent 8faf828b50
commit 9bfac585af
5 changed files with 49 additions and 32 deletions

View File

@@ -2,6 +2,10 @@
Version 1.6.3 Version 1.6.3
******************************************************************************* *******************************************************************************
2007-12-16 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Library was not compiling on FreeBSD 7. Code now no longer uses
ftime(), using gettimeofday() instead. Thanks to Josh Carroll.
******************************************************************************* *******************************************************************************
Version 1.6.2 Version 1.6.2

1
THANKS
View File

@@ -23,6 +23,7 @@ exempt of errors.
- Jiri Zouhar - Jiri Zouhar
- John Dennis - John Dennis
- Jonathan (no_dice) - Jonathan (no_dice)
- Josh Carroll
- Keith Brindley - Keith Brindley
- Leuk_He - Leuk_He
- Loigu - Loigu

View File

@@ -98,13 +98,16 @@ AC_INIT([libupnp], [1.6.3], [mroberto@users.sourceforge.net])
# Release 1.6.3: # Release 1.6.3:
# "current:revision:age" # "current:revision:age"
# #
# - Code has changed in threadutil
# revision: 0 -> 1
#
#AC_SUBST([LT_VERSION_IXML], [2:4:0]) #AC_SUBST([LT_VERSION_IXML], [2:4:0])
#AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2]) #AC_SUBST([LT_VERSION_THREADUTIL], [4:1:2])
#AC_SUBST([LT_VERSION_UPNP], [3:2:0]) #AC_SUBST([LT_VERSION_UPNP], [3:2:0])
# #
############################################################################### ###############################################################################
AC_SUBST([LT_VERSION_IXML], [2:4:0]) AC_SUBST([LT_VERSION_IXML], [2:4:0])
AC_SUBST([LT_VERSION_THREADUTIL], [4:0:2]) AC_SUBST([LT_VERSION_THREADUTIL], [4:1:2])
AC_SUBST([LT_VERSION_UPNP], [3:2:0]) AC_SUBST([LT_VERSION_UPNP], [3:2:0])
############################################################################### ###############################################################################
# Repeating the algorithm so that it is closer to the modificatin place: # Repeating the algorithm so that it is closer to the modificatin place:

View File

@@ -83,12 +83,11 @@ typedef enum priority {LOW_PRIORITY,
#endif #endif
#include "LinkedList.h" #include "LinkedList.h"
#include <sys/timeb.h> #include <sys/time.h> /* for gettimeofday() */
#include "FreeList.h" #include "FreeList.h"
#include "ithread.h" #include "ithread.h"
#include <errno.h> #include <errno.h>
#include <sys/timeb.h>
#define EXPORT #define EXPORT
typedef int PolicyType; typedef int PolicyType;
#define DEFAULT_POLICY SCHED_OTHER #define DEFAULT_POLICY SCHED_OTHER
@@ -144,7 +143,7 @@ typedef struct THREADPOOLJOB
start_routine func; start_routine func;
void *arg; void *arg;
free_routine free_func; free_routine free_func;
struct timeb requestTime; struct timeval requestTime;
int priority; int priority;
int jobId; int jobId;
} ThreadPoolJob; } ThreadPoolJob;

View File

@@ -168,26 +168,36 @@ SetPriority( ThreadPriority priority )
* *
* Description: * Description:
* Returns the difference in milliseconds between two * Returns the difference in milliseconds between two
* timeb structures. * timeval structures.
* Internal Only. * Internal Only.
* Parameters: * Parameters:
* struct timeb *time1, * struct timeval *time1,
* struct timeb *time2, * struct timeval *time2,
* Returns: * Returns:
* the difference in milliseconds, time1-time2. * the difference in milliseconds, time1-time2.
*****************************************************************************/ *****************************************************************************/
static double static unsigned long
DiffMillis( struct timeb *time1, DiffMillis( struct timeval *time1,
struct timeb *time2 ) struct timeval *time2 )
{ {
double temp = 0; double temp = 0;
assert( time1 != NULL ); assert( time1 != NULL );
assert( time2 != NULL ); assert( time2 != NULL );
temp = ( ( double )( time1->time ) - time2->time ); struct timeval {
temp = temp * 1000; time_t tv_sec; /* seconds */
temp += ( time1->millitm - time2->millitm ); suseconds_t tv_usec; /* and microseconds */
};
temp = time1->tv_sec - time2->tv_sec;
/* convert to milliseconds */
temp *= 1000;
/* convert microseconds to milliseconds and add to temp */
/* implicit flooring of unsigned long data type */
temp += ( (time1->tv_usec - time2->tv_usec) / 1000 );
return temp; return temp;
} }
@@ -207,13 +217,13 @@ static void
BumpPriority( ThreadPool * tp ) BumpPriority( ThreadPool * tp )
{ {
int done = 0; int done = 0;
struct timeb now; struct timeval now;
double diffTime = 0; unsigned long diffTime = 0;
ThreadPoolJob *tempJob = NULL; ThreadPoolJob *tempJob = NULL;
assert( tp != NULL ); assert( tp != NULL );
ftime( &now ); gettimeofday(&now, NULL);
while( !done ) { while( !done ) {
if( tp->medJobQ.size ) { if( tp->medJobQ.size ) {
@@ -272,16 +282,16 @@ static void
SetRelTimeout( struct timespec *time, SetRelTimeout( struct timespec *time,
int relMillis ) int relMillis )
{ {
struct timeb now; struct timeval now;
int sec = relMillis / 1000; int sec = relMillis / 1000;
int milliSeconds = relMillis % 1000; int milliSeconds = relMillis % 1000;
assert( time != NULL ); assert( time != NULL );
ftime( &now ); gettimeofday(&now, NULL);
time->tv_sec = now.time + sec; time->tv_sec = now.tv_sec + sec;
time->tv_nsec = ( now.millitm + milliSeconds ) * 1000000; time->tv_nsec = ( (now.tv_usec/1000) + milliSeconds ) * 1000000;
} }
/**************************************************************************** /****************************************************************************
@@ -334,11 +344,11 @@ static void StatsInit( ThreadPoolStats * stats )
static void CalcWaitTime( ThreadPool * tp, static void CalcWaitTime( ThreadPool * tp,
ThreadPriority p, ThreadPriority p,
ThreadPoolJob * job ) { ThreadPoolJob * job ) {
struct timeb now; struct timeval now;
double diff; unsigned long diff;
assert( tp != NULL ); assert( tp != NULL );
assert( job != NULL ); assert( job != NULL );
ftime( &now ); gettimeofday(&now, NULL);
diff = DiffMillis( &now, &job->requestTime ); switch ( p ) { diff = DiffMillis( &now, &job->requestTime ); switch ( p ) {
case HIGH_PRIORITY: case HIGH_PRIORITY:
tp->stats.totalJobsHQ++; tp->stats.totalTimeHQ += diff; break; case MED_PRIORITY: tp->stats.totalJobsHQ++; tp->stats.totalTimeHQ += diff; break; case MED_PRIORITY:
@@ -360,15 +370,15 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default:
* *
*****************************************************************************/ *****************************************************************************/
static void SetSeed() { static void SetSeed() {
struct timeb t; struct timeval t;
ftime( &t ); gettimeofday(&t, NULL);
#if defined(WIN32) #if defined(WIN32)
srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id().p ); srand( ( unsigned int )t.tv_usec + (unsigned int)ithread_get_current_thread_id().p );
#elif defined(__FreeBSD__) || defined(__OSX__) #elif defined(__FreeBSD__)
srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id() ); srand( ( unsigned int )t.tv_usec + (unsigned int)ithread_get_current_thread_id() );
#elif defined(__linux__) #elif defined(__linux__)
srand( ( unsigned int )t.millitm + ithread_get_current_thread_id() ); srand( ( unsigned int )t.tv_usec + ithread_get_current_thread_id() );
#else #else
{ {
volatile union { volatile pthread_t tid; volatile unsigned i; } idu; volatile union { volatile pthread_t tid; volatile unsigned i; } idu;
@@ -607,7 +617,7 @@ static void SetSeed() {
if( newJob ) { if( newJob ) {
( *newJob ) = ( *job ); ( *newJob ) = ( *job );
newJob->jobId = id; newJob->jobId = id;
ftime( &newJob->requestTime ); gettimeofday( &newJob->requestTime, NULL );
} }
return newJob; return newJob;
} }