void UpnpDisplayFileAndLine(FILE *fd, const char *DbgFileName, int DbgLineNo) { #define NLINES 2 #define MAX_LINE_SIZE 512 #define NUMBER_OF_STARS 80 const char *lines[NLINES]; char buf[NLINES][MAX_LINE_SIZE]; int i; /* Initialize the pointer array */ for (i = 0; i < NLINES; i++) lines[i] = buf[i]; /* Put the debug lines in the buffer */ sprintf(buf[0], "DEBUG - THREAD ID: 0x%lX", #ifdef WIN32 (unsigned long int)ithread_self().p #else (unsigned long int)ithread_self() #endif ); if (DbgFileName) sprintf(buf[1], "FILE: %s, LINE: %d", DbgFileName, DbgLineNo); /* Show the lines centered */ UpnpDisplayBanner(fd, lines, NLINES, NUMBER_OF_STARS); fflush(fd); }
/**************************************************************************** * Function: SetPriority * * Description: * Sets the priority of the currently running thread. * Internal only. * Parameters: * ThreadPriority priority * Returns: * 0 on success, nonzero on failure * EINVAL invalid priority * Returns result of GerLastError on failure. * *****************************************************************************/ static int SetPriority( ThreadPriority priority ) { #if defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 int currentPolicy; int minPriority = 0; int maxPriority = 0; int actPriority = 0; int midPriority = 0; struct sched_param newPriority; pthread_getschedparam( ithread_self(), ¤tPolicy, &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; case MED_PRIORITY: actPriority = midPriority; break; case HIGH_PRIORITY: actPriority = maxPriority; break; default: return EINVAL; }; newPriority.sched_priority = actPriority; return pthread_setschedparam(ithread_self(), currentPolicy, &newPriority ); #else return 0; #endif }
/*! * \brief Sets the priority of the currently running thread. * * \internal * * \return * \li \c 0 on success. * \li \c EINVAL invalid priority or the result of GerLastError. */ static int SetPriority( /*! . */ ThreadPriority priority) { #if defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 int retVal = 0; int currentPolicy; int minPriority = 0; int maxPriority = 0; int actPriority = 0; int midPriority = 0; struct sched_param newPriority; int sched_result; pthread_getschedparam(ithread_self(), ¤tPolicy, &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; case MED_PRIORITY: actPriority = midPriority; break; case HIGH_PRIORITY: actPriority = maxPriority; break; default: retVal = EINVAL; goto exit_function; }; newPriority.sched_priority = actPriority; sched_result = pthread_setschedparam(ithread_self(), currentPolicy, &newPriority); retVal = (sched_result == 0 || errno == EPERM) ? 0 : sched_result; exit_function: return retVal; #else return 0; priority = priority; #endif }