Forward port of svn revision 505:

SF Patch Tracker [ 2836704 ] Patch for Solaris10 compilation and usage.
	Submitted By: zephyrus ( zephyrus00jp )



git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@506 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2010-03-21 11:50:26 +00:00
parent cbbbb14e21
commit f6a30b842c
3 changed files with 146 additions and 77 deletions

View File

@@ -48,6 +48,7 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* for memset()*/
/****************************************************************************
@@ -63,12 +64,12 @@
* Returns:
* the difference in milliseconds, time1-time2.
*****************************************************************************/
static unsigned long DiffMillis( struct timeval *time1, struct timeval *time2 )
static unsigned long DiffMillis(struct timeval *time1, struct timeval *time2)
{
double temp = 0;
assert( time1 != NULL );
assert( time2 != NULL );
assert(time1 != NULL);
assert(time2 != NULL);
temp = time1->tv_sec - time2->tv_sec;
/* convert to milliseconds */
@@ -91,9 +92,9 @@ static unsigned long DiffMillis( struct timeval *time1, struct timeval *time2 )
* Parameters:
* ThreadPoolStats *stats must be valid non null stats structure
*****************************************************************************/
static void StatsInit( ThreadPoolStats *stats )
static void StatsInit(ThreadPoolStats *stats)
{
assert( stats != NULL );
assert(stats != NULL);
stats->totalIdleTime = 0;
stats->totalJobsHQ = 0;
@@ -113,19 +114,19 @@ static void StatsInit( ThreadPoolStats *stats )
stats->maxThreads = 0; stats->totalThreads = 0;
}
static void StatsAccountLQ( ThreadPool *tp, unsigned long diffTime )
static void StatsAccountLQ(ThreadPool *tp, unsigned long diffTime)
{
tp->stats.totalJobsLQ++;
tp->stats.totalTimeLQ += diffTime;
}
static void StatsAccountMQ( ThreadPool *tp, unsigned long diffTime )
static void StatsAccountMQ(ThreadPool *tp, unsigned long diffTime)
{
tp->stats.totalJobsMQ++;
tp->stats.totalTimeMQ += diffTime;
}
static void StatsAccountHQ( ThreadPool *tp, unsigned long diffTime )
static void StatsAccountHQ(ThreadPool *tp, unsigned long diffTime)
{
tp->stats.totalJobsHQ++;
tp->stats.totalTimeHQ += diffTime;
@@ -145,36 +146,36 @@ static void StatsAccountHQ( ThreadPool *tp, unsigned long diffTime )
* ThreadPriority p
* ThreadPoolJob *job
*****************************************************************************/
static void CalcWaitTime( ThreadPool *tp, ThreadPriority p, ThreadPoolJob *job )
static void CalcWaitTime(ThreadPool *tp, ThreadPriority p, ThreadPoolJob *job)
{
struct timeval now;
unsigned long diff;
assert( tp != NULL );
assert( job != NULL );
assert(tp != NULL);
assert(job != NULL);
gettimeofday( &now, NULL );
diff = DiffMillis( &now, &job->requestTime );
switch ( p ) {
gettimeofday(&now, NULL);
diff = DiffMillis(&now, &job->requestTime);
switch (p) {
case LOW_PRIORITY:
StatsAccountLQ( tp, diff );
StatsAccountLQ(tp, diff);
break;
case MED_PRIORITY:
StatsAccountMQ( tp, diff );
StatsAccountMQ(tp, diff);
break;
case HIGH_PRIORITY:
StatsAccountHQ( tp, diff );
StatsAccountHQ(tp, diff);
break;
default:
assert( 0 );
assert(0);
}
}
static time_t StatsTime( time_t *t )
static time_t StatsTime(time_t *t)
{
struct timeval tv;
gettimeofday( &tv, NULL );
gettimeofday(&tv, NULL);
if (t) {
*t = tv.tv_sec;
}
@@ -182,12 +183,12 @@ static time_t StatsTime( time_t *t )
return tv.tv_sec;
}
#else /* STATS */
static UPNP_INLINE void StatsInit( ThreadPoolStats *stats ) {}
static UPNP_INLINE void StatsAccountLQ( ThreadPool *tp, unsigned long diffTime ) {}
static UPNP_INLINE void StatsAccountMQ( ThreadPool *tp, unsigned long diffTime ) {}
static UPNP_INLINE void StatsAccountHQ( ThreadPool *tp, unsigned long diffTime ) {}
static UPNP_INLINE void CalcWaitTime( ThreadPool *tp, ThreadPriority p, ThreadPoolJob *job ) {}
static UPNP_INLINE time_t StatsTime( time_t *t ) { return 0; }
static UPNP_INLINE void StatsInit(ThreadPoolStats *stats) {}
static UPNP_INLINE void StatsAccountLQ(ThreadPool *tp, unsigned long diffTime) {}
static UPNP_INLINE void StatsAccountMQ(ThreadPool *tp, unsigned long diffTime) {}
static UPNP_INLINE void StatsAccountHQ(ThreadPool *tp, unsigned long diffTime) {}
static UPNP_INLINE void CalcWaitTime(ThreadPool *tp, ThreadPriority p, ThreadPoolJob *job) {}
static UPNP_INLINE time_t StatsTime(time_t *t) { return 0; }
#endif /* STATS */
/****************************************************************************
@@ -199,15 +200,15 @@ static UPNP_INLINE time_t StatsTime( time_t *t ) { return 0; }
* void * - job A
* void * - job B
*****************************************************************************/
static int CmpThreadPoolJob( void *jobA, void *jobB )
static int CmpThreadPoolJob(void *jobA, void *jobB)
{
ThreadPoolJob *a = ( ThreadPoolJob *) jobA;
ThreadPoolJob *b = ( ThreadPoolJob *) jobB;
ThreadPoolJob *a = (ThreadPoolJob *) jobA;
ThreadPoolJob *b = (ThreadPoolJob *) jobB;
assert( jobA != NULL );
assert( jobB != NULL );
assert(jobA != NULL);
assert(jobB != NULL);
return ( a->jobId == b->jobId );
return a->jobId == b->jobId;
}
/****************************************************************************
@@ -250,12 +251,20 @@ static int SetPolicyType(PolicyType in)
return sched_setscheduler(0, in);
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
struct sched_param current;
int sched_result;
int rc;
memset(&current, 0, sizeof(current)); /* purify? */
sched_getparam(0, &current);
current.sched_priority = DEFAULT_SCHED_PARAM;
sched_result = sched_setscheduler(0, in, &current);
return (-1 != sched_result || EPERM == errno) ? 0 : -1;
/* Solaris returns -1 if failure ..., but can return
* non-zero values for 0, ..., 5 [former scheduling values.] */
rc = sched_setscheduler(0, in, &current);
if (rc == -1) {
return rc;
} else {
return 0;
}
#else
return 0;
#endif
@@ -286,11 +295,11 @@ static int SetPriority(ThreadPriority priority)
struct sched_param newPriority;
int sched_result;
pthread_getschedparam( ithread_self(), &currentPolicy, &newPriority );
minPriority = sched_get_priority_min( currentPolicy );
maxPriority = sched_get_priority_max( currentPolicy );
midPriority = ( maxPriority - minPriority ) / 2;
switch ( priority ) {
pthread_getschedparam(ithread_self(), &currentPolicy, &newPriority);
minPriority = sched_get_priority_min(currentPolicy);
maxPriority = sched_get_priority_max(currentPolicy);
midPriority = (maxPriority - minPriority) / 2;
switch (priority) {
case LOW_PRIORITY:
actPriority = minPriority;
break;
@@ -325,44 +334,43 @@ static int SetPriority(ThreadPriority priority)
* Parameters:
* ThreadPool *tp
*****************************************************************************/
static void BumpPriority( ThreadPool *tp )
static void BumpPriority(ThreadPool *tp)
{
int done = 0;
struct timeval now;
unsigned long diffTime = 0;
ThreadPoolJob *tempJob = NULL;
int done = 0;
struct timeval now;
unsigned long diffTime = 0;
ThreadPoolJob *tempJob = NULL;
assert( tp != NULL );
assert(tp != NULL);
gettimeofday(&now, NULL);
while( !done ) {
if( tp->medJobQ.size ) {
tempJob = ( ThreadPoolJob *) tp->medJobQ.head.next->item;
diffTime = DiffMillis( &now, &tempJob->requestTime );
if( diffTime >= ( tp->attr.starvationTime ) ) {
// If job has waited longer than the starvation time
// bump priority (add to higher priority Q)
StatsAccountMQ( tp, diffTime );
ListDelNode( &tp->medJobQ, tp->medJobQ.head.next, 0 );
ListAddTail( &tp->highJobQ, tempJob );
continue;
}
}
if( tp->lowJobQ.size ) {
tempJob = ( ThreadPoolJob *) tp->lowJobQ.head.next->item;
diffTime = DiffMillis( &now, &tempJob->requestTime );
if( diffTime >= ( tp->attr.maxIdleTime ) ) {
// If job has waited longer than the starvation time
// bump priority (add to higher priority Q)
StatsAccountLQ( tp, diffTime );
ListDelNode( &tp->lowJobQ, tp->lowJobQ.head.next, 0 );
ListAddTail( &tp->medJobQ, tempJob );
continue;
}
}
done = 1;
}
gettimeofday(&now, NULL);
while (!done) {
if (tp->medJobQ.size) {
tempJob = (ThreadPoolJob *)tp->medJobQ.head.next->item;
diffTime = DiffMillis(&now, &tempJob->requestTime);
if (diffTime >= tp->attr.starvationTime) {
/* If job has waited longer than the starvation time
* bump priority (add to higher priority Q) */
StatsAccountMQ(tp, diffTime);
ListDelNode(&tp->medJobQ, tp->medJobQ.head.next, 0);
ListAddTail(&tp->highJobQ, tempJob);
continue;
}
}
if (tp->lowJobQ.size) {
tempJob = (ThreadPoolJob *)tp->lowJobQ.head.next->item;
diffTime = DiffMillis(&now, &tempJob->requestTime);
if (diffTime >= tp->attr.maxIdleTime) {
/* If job has waited longer than the starvation time
* bump priority (add to higher priority Q) */
StatsAccountLQ(tp, diffTime);
ListDelNode(&tp->lowJobQ, tp->lowJobQ.head.next, 0);
ListAddTail(&tp->medJobQ, tempJob);
continue;
}
}
done = 1;
}
}
/****************************************************************************
@@ -1657,4 +1665,3 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
return 0;
}
#endif /* WIN32 */