From: <jpg...@us...> - 2008-07-02 22:34:07
|
Revision: 1444 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1444&view=rev Author: jpgrayson Date: 2008-07-02 15:34:14 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Use more conventional "struct prioboost" instead of typedef. Modified Paths: -------------- trunk/lib/unixfuncs.c Modified: trunk/lib/unixfuncs.c =================================================================== --- trunk/lib/unixfuncs.c 2008-07-01 16:40:52 UTC (rev 1443) +++ trunk/lib/unixfuncs.c 2008-07-02 22:34:14 UTC (rev 1444) @@ -174,7 +174,8 @@ typedef void *(*pthread_function_t)(void *); -typedef struct { +struct prioboost +{ int priority; pthread_t ThreadID; @@ -187,11 +188,11 @@ pthread_t WatchDogThread; int IsWatchDogThreadValid; -} prioboost; +}; -static prioboost *pb; +static struct prioboost *pb; -static int CanaryProc( prioboost *b) +static int CanaryProc(struct prioboost *b) { int result = 0; struct sched_param schat = { 0 }; @@ -209,7 +210,7 @@ return result; } -static int WatchDogProc( prioboost *b ) +static int WatchDogProc(struct prioboost *b ) { struct sched_param schp = { 0 }; int maxPri; @@ -298,7 +299,7 @@ return 0; } -static void StopWatchDog( prioboost *b ) +static void StopWatchDog(struct prioboost *b) { /* Cancel WatchDog thread if there is one. */ if( b->IsWatchDogThreadValid ) @@ -322,7 +323,7 @@ } -static int StartWatchDog( prioboost *b) +static int StartWatchDog(struct prioboost *b) { int hres; int result = 0; @@ -364,7 +365,7 @@ int iaxci_prioboostbegin() { struct sched_param schp = { 0 }; - prioboost *b = calloc(sizeof(*b),1); + struct prioboost *b = calloc(sizeof(*b),1); int result = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-07-02 22:36:58
|
Revision: 1445 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1445&view=rev Author: jpgrayson Date: 2008-07-02 15:37:01 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Cache min and max priority values in struct prioboost. Modified Paths: -------------- trunk/lib/unixfuncs.c Modified: trunk/lib/unixfuncs.c =================================================================== --- trunk/lib/unixfuncs.c 2008-07-02 22:34:14 UTC (rev 1444) +++ trunk/lib/unixfuncs.c 2008-07-02 22:37:01 UTC (rev 1445) @@ -177,6 +177,9 @@ struct prioboost { int priority; + int min_priority; + int max_priority; + pthread_t ThreadID; struct timeval CanaryTime; @@ -213,13 +216,12 @@ static int WatchDogProc(struct prioboost *b ) { struct sched_param schp = { 0 }; - int maxPri; /* Run at a priority level above main thread so we can still run if it hangs. */ /* Rise more than 1 because of rumored off-by-one scheduler bugs. */ schp.sched_priority = b->priority + 4; - maxPri = sched_get_priority_max(SCHEDULER_POLICY); - if( schp.sched_priority > maxPri ) schp.sched_priority = maxPri; + if( schp.sched_priority > b->max_priority ) + schp.sched_priority = b->max_priority; if (pthread_setschedparam(pthread_self(), SCHEDULER_POLICY, &schp) != 0) { @@ -369,8 +371,9 @@ int result = 0; - b->priority = (sched_get_priority_max(SCHEDULER_POLICY) - - sched_get_priority_min(SCHEDULER_POLICY)) / 2; + b->min_priority = sched_get_priority_min(SCHEDULER_POLICY); + b->max_priority = sched_get_priority_max(SCHEDULER_POLICY); + b->priority = (b->max_priority - b->min_priority) / 2; schp.sched_priority = b->priority; b->ThreadID = pthread_self(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-07-02 22:40:58
|
Revision: 1446 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1446&view=rev Author: jpgrayson Date: 2008-07-02 15:41:06 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Whitespace changes. Modified Paths: -------------- trunk/lib/unixfuncs.c Modified: trunk/lib/unixfuncs.c =================================================================== --- trunk/lib/unixfuncs.c 2008-07-02 22:37:01 UTC (rev 1445) +++ trunk/lib/unixfuncs.c 2008-07-02 22:41:06 UTC (rev 1446) @@ -215,10 +215,12 @@ static int WatchDogProc(struct prioboost *b ) { - struct sched_param schp = { 0 }; + struct sched_param schp = { 0 }; + struct sched_param schat = { 0 }; - /* Run at a priority level above main thread so we can still run if it hangs. */ - /* Rise more than 1 because of rumored off-by-one scheduler bugs. */ + /* Run at a priority level above main thread so we can still run if it + * hangs. Rise more than 1 because of rumored off-by-one scheduler + * bugs. */ schp.sched_priority = b->priority + 4; if( schp.sched_priority > b->max_priority ) schp.sched_priority = b->max_priority; @@ -229,16 +231,16 @@ goto killAudio; } - DBUG("prioboost: WatchDog priority set to level %d!\n", schp.sched_priority); + DBUG("prioboost: WatchDog priority set to level %d!\n", + schp.sched_priority); /* Compare watchdog time with audio and canary thread times. */ /* Sleep for a while or until thread cancelled. */ - while( b->WatchDogRun ) + while ( b->WatchDogRun ) { + int delta; + struct timeval currentTime; - int delta; - struct timeval currentTime; - usleep( WATCHDOG_INTERVAL_USEC ); gettimeofday( ¤tTime, NULL ); @@ -266,19 +268,18 @@ return 0; lowerAudio: + if ( pthread_setschedparam(b->ThreadID, SCHED_OTHER, &schat) != 0 ) { - struct sched_param schat = { 0 }; - if( pthread_setschedparam(b->ThreadID, SCHED_OTHER, &schat) != 0) - { - ERR_RPT("WatchDogProc: failed to lower audio priority. errno = %d\n", errno ); - /* Fall through into killing audio thread. */ - } - else - { - ERR_RPT("WatchDogProc: lowered audio priority to prevent hogging of CPU.\n"); - goto cleanup; - } + ERR_RPT("WatchDogProc: failed to lower audio priority. " + "errno = %d\n", errno); + /* Fall through into killing audio thread. */ } + else + { + ERR_RPT("WatchDogProc: lowered audio priority to prevent " + "hogging of CPU.\n"); + goto cleanup; + } killAudio: ERR_RPT("WatchDogProc: killing hung audio thread!\n"); @@ -366,8 +367,8 @@ int iaxci_prioboostbegin() { - struct sched_param schp = { 0 }; - struct prioboost *b = calloc(sizeof(*b),1); + struct sched_param schp = { 0 }; + struct prioboost *b = calloc(1, sizeof(*b)); int result = 0; @@ -384,13 +385,18 @@ } else { - DBUG("prioboost: priority set to level %d!\n", schp.sched_priority); /* We are running at high priority so we should have a watchdog in case audio goes wild. */ + DBUG("prioboost: priority set to level %d!\n", schp.sched_priority); + /* We are running at high priority so we should have a watchdog + * in case audio goes wild. */ result = StartWatchDog( b ); } - if(result == 0) { + if (result == 0) + { pb = b; - } else { + } + else + { pb = NULL; schp.sched_priority = 0; pthread_setschedparam(b->ThreadID, SCHED_OTHER, &schp); @@ -401,7 +407,8 @@ int iaxci_prioboostend() { - if(pb) StopWatchDog(pb); + if ( pb ) + StopWatchDog(pb); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-07-02 22:42:16
|
Revision: 1447 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1447&view=rev Author: jpgrayson Date: 2008-07-02 15:42:26 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Fix memory leak where struct prioboost was never free()ed. Modified Paths: -------------- trunk/lib/unixfuncs.c Modified: trunk/lib/unixfuncs.c =================================================================== --- trunk/lib/unixfuncs.c 2008-07-02 22:41:06 UTC (rev 1446) +++ trunk/lib/unixfuncs.c 2008-07-02 22:42:26 UTC (rev 1447) @@ -400,6 +400,7 @@ pb = NULL; schp.sched_priority = 0; pthread_setschedparam(b->ThreadID, SCHED_OTHER, &schp); + free(b); } return result; @@ -408,7 +409,10 @@ int iaxci_prioboostend() { if ( pb ) + { StopWatchDog(pb); + free(pb); + } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-07-02 22:49:07
|
Revision: 1448 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1448&view=rev Author: jpgrayson Date: 2008-07-02 15:49:16 -0700 (Wed, 02 Jul 2008) Log Message: ----------- Fix bug where on some linux systems, the user does not have permission to set the priority sufficiently high. Thanks to Jean-Denis for bug report and initial patch. Modified Paths: -------------- trunk/lib/unixfuncs.c Modified: trunk/lib/unixfuncs.c =================================================================== --- trunk/lib/unixfuncs.c 2008-07-02 22:42:26 UTC (rev 1447) +++ trunk/lib/unixfuncs.c 2008-07-02 22:49:16 UTC (rev 1448) @@ -217,20 +217,32 @@ { struct sched_param schp = { 0 }; struct sched_param schat = { 0 }; + int pri = b->priority + 4; /* Run at a priority level above main thread so we can still run if it * hangs. Rise more than 1 because of rumored off-by-one scheduler * bugs. */ - schp.sched_priority = b->priority + 4; - if( schp.sched_priority > b->max_priority ) - schp.sched_priority = b->max_priority; + if ( pri > b->max_priority ) + pri = b->max_priority; - if (pthread_setschedparam(pthread_self(), SCHEDULER_POLICY, &schp) != 0) + for ( ; pri > b->priority; pri-- ) { - ERR_RPT("WatchDogProc: cannot set watch dog priority!\n"); - goto killAudio; + schp.sched_priority = pri; + + if ( pthread_setschedparam(pthread_self(), SCHEDULER_POLICY, + &schp) ) + ERR_RPT("WatchDogProc: cannot set watch dog priority!" + " %d\n", pri); + else + break; } + /* If the watchdog thread cannot get a higher priority than the canary, + * the whole scheme falls apart. Bail. + */ + if ( pri <= b->priority ) + goto killAudio; + DBUG("prioboost: WatchDog priority set to level %d!\n", schp.sched_priority); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |