From edc06386406803179eb5ac94a4c28b88c40538f9 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Sun, 21 Mar 2010 17:07:09 +0000 Subject: [PATCH] Backport of svn revision 512: Style compatibilization between two similar constructions addressed in two separate recent patches. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@513 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- threadutil/src/ThreadPool.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/threadutil/src/ThreadPool.c b/threadutil/src/ThreadPool.c index 14e88a1..3d3608b 100644 --- a/threadutil/src/ThreadPool.c +++ b/threadutil/src/ThreadPool.c @@ -241,33 +241,28 @@ static void FreeThreadPoolJob(ThreadPool *tp, ThreadPoolJob *tpj) *****************************************************************************/ static int SetPolicyType(PolicyType in) { + int retVal = 0; #ifdef __CYGWIN__ /* TODO not currently working... */ - return 0; + retVal = 0; #elif defined(__OSX__) || defined(__APPLE__) || defined(__NetBSD__) setpriority(PRIO_PROCESS, 0, 0); - return 0; + retVal = 0; #elif defined(WIN32) - return sched_setscheduler(0, in); + retVal = sched_setscheduler(0, in); #elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 struct sched_param current; - int rc; + int sched_result; - memset(¤t, 0, sizeof(current)); /* purify? */ + memset(¤t, 0, sizeof(current)); sched_getparam(0, ¤t); current.sched_priority = DEFAULT_SCHED_PARAM; - - /* Solaris returns -1 if failure ..., but can return - * non-zero values for 0, ..., 5 [former scheduling values.] */ - rc = sched_setscheduler(0, in, ¤t); - if (rc == -1) { - return rc; - } else { - return 0; - } + sched_result = sched_setscheduler(0, in, ¤t); + retVal = (sched_result != -1 || errno == EPERM) ? 0 : errno; #else - return 0; + retVal = 0; #endif + return retVal; } /**************************************************************************** @@ -286,6 +281,7 @@ static int SetPolicyType(PolicyType in) *****************************************************************************/ static int SetPriority(ThreadPriority priority) { + int retVal = 0; #if defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 int currentPolicy; int minPriority = 0; @@ -310,16 +306,19 @@ static int SetPriority(ThreadPriority priority) actPriority = maxPriority; break; default: - return EINVAL; + retVal = EINVAL; + goto exit_function; }; newPriority.sched_priority = actPriority; sched_result = pthread_setschedparam(ithread_self(), currentPolicy, &newPriority); - return (0 == sched_result || EPERM == errno) ? 0 : -1; + retVal = (sched_result == 0 || errno == EPERM) ? 0 : sched_result; #else - return 0; + retVal = 0; #endif +exit_function: + return retVal; } /****************************************************************************