Merge of current trunk to branch 1.6.x.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@251 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
@@ -547,6 +547,10 @@ int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal);
|
||||
EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats);
|
||||
|
||||
EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats);
|
||||
#else
|
||||
static UPNP_INLINE int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats) {}
|
||||
|
||||
static UPNP_INLINE void ThreadPoolPrintStats(ThreadPoolStats *stats) {}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -42,131 +42,158 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#endif
|
||||
|
||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||
/* This system has SuS2-compliant mutex attributes.
|
||||
* E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
|
||||
*/
|
||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
|
||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
|
||||
#else
|
||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
|
||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
|
||||
#endif
|
||||
/* This system has SuS2-compliant mutex attributes.
|
||||
* E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
|
||||
*/
|
||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
|
||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
|
||||
#else /* PTHREAD_MUTEX_RECURSIVE */
|
||||
#define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
|
||||
#define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
|
||||
#endif /* PTHREAD_MUTEX_RECURSIVE */
|
||||
|
||||
|
||||
#define ITHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
|
||||
#define ITHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
|
||||
|
||||
|
||||
#define ITHREAD_CANCELED PTHREAD_CANCELED
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Name: ithread_t
|
||||
*
|
||||
* Description:
|
||||
* Thread handle.
|
||||
* typedef to pthread_t.
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_t ithread_t;
|
||||
/***************************************************************************
|
||||
* Name: ithread_t
|
||||
*
|
||||
* Description:
|
||||
* Thread handle.
|
||||
* typedef to pthread_t.
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_t ithread_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_attr_t
|
||||
*
|
||||
* Description:
|
||||
* Thread attribute.
|
||||
* typedef to pthread_attr_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_attr_t ithread_attr_t;
|
||||
/****************************************************************************
|
||||
* Name: ithread_attr_t
|
||||
*
|
||||
* Description:
|
||||
* Thread attribute.
|
||||
* typedef to pthread_attr_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_attr_t ithread_attr_t;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: start_routine
|
||||
*
|
||||
* Description:
|
||||
* Thread start routine
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef void * (*start_routine) (void *arg);
|
||||
/****************************************************************************
|
||||
* Name: start_routine
|
||||
*
|
||||
* Description:
|
||||
* Thread start routine
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef void * (*start_routine) (void *arg);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_cond_t
|
||||
*
|
||||
* Description:
|
||||
* condition variable.
|
||||
* typedef to pthread_cond_t
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_cond_t ithread_cond_t;
|
||||
/****************************************************************************
|
||||
* Name: ithread_cond_t
|
||||
*
|
||||
* Description:
|
||||
* condition variable.
|
||||
* typedef to pthread_cond_t
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_cond_t ithread_cond_t;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_mutexattr_t
|
||||
*
|
||||
* Description:
|
||||
* Mutex attribute.
|
||||
* typedef to pthread_mutexattr_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_mutexattr_t ithread_mutexattr_t;
|
||||
/****************************************************************************
|
||||
* Name: ithread_mutexattr_t
|
||||
*
|
||||
* Description:
|
||||
* Mutex attribute.
|
||||
* typedef to pthread_mutexattr_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_mutexattr_t ithread_mutexattr_t;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_mutex_t
|
||||
*
|
||||
* Description:
|
||||
* Mutex.
|
||||
* typedef to pthread_mutex_t
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_mutex_t ithread_mutex_t;
|
||||
/****************************************************************************
|
||||
* Name: ithread_mutex_t
|
||||
*
|
||||
* Description:
|
||||
* Mutex.
|
||||
* typedef to pthread_mutex_t
|
||||
* Internal Use Only.
|
||||
***************************************************************************/
|
||||
typedef pthread_mutex_t ithread_mutex_t;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_condattr_t
|
||||
*
|
||||
* Description:
|
||||
* Condition attribute.
|
||||
* typedef to pthread_condattr_t
|
||||
* NOT USED
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_condattr_t ithread_condattr_t;
|
||||
/****************************************************************************
|
||||
* Name: ithread_condattr_t
|
||||
*
|
||||
* Description:
|
||||
* Condition attribute.
|
||||
* typedef to pthread_condattr_t
|
||||
* NOT USED
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_condattr_t ithread_condattr_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_mutexattr_init
|
||||
*
|
||||
* Description:
|
||||
* Initializes a mutex attribute variable.
|
||||
* Used to set the type of the mutex.
|
||||
* Parameters:
|
||||
* ithread_mutexattr_init * attr (must be valid non NULL pointer to
|
||||
* pthread_mutexattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_mutexattr_init
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_rwlockattr_t
|
||||
*
|
||||
* Description:
|
||||
* Mutex attribute.
|
||||
* typedef to pthread_rwlockattr_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_rwlockattr_t ithread_rwlockattr_t;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ithread_rwlock_t
|
||||
*
|
||||
* Description:
|
||||
* Condition attribute.
|
||||
* typedef to pthread_rwlock_t
|
||||
* Internal Use Only
|
||||
***************************************************************************/
|
||||
typedef pthread_rwlock_t ithread_rwlock_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_mutexattr_init
|
||||
*
|
||||
* Description:
|
||||
* Initializes a mutex attribute variable.
|
||||
* Used to set the type of the mutex.
|
||||
* Parameters:
|
||||
* ithread_mutexattr_init * attr (must be valid non NULL pointer to
|
||||
* pthread_mutexattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_mutexattr_init
|
||||
***************************************************************************/
|
||||
#define ithread_mutexattr_init pthread_mutexattr_init
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_mutexattr_destroy
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources held by the mutex attribute.
|
||||
* Currently there are no resources associated with the attribute
|
||||
* Parameters:
|
||||
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||
* pthread_mutexattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_mutexattr_destroy
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_mutexattr_destroy
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources held by the mutex attribute.
|
||||
* Currently there are no resources associated with the attribute
|
||||
* Parameters:
|
||||
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||
* pthread_mutexattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_mutexattr_destroy
|
||||
***************************************************************************/
|
||||
#define ithread_mutexattr_destroy pthread_mutexattr_destroy
|
||||
|
||||
|
||||
@@ -180,7 +207,7 @@ extern "C" {
|
||||
* ITHREAD_MUTEX_ERRORCHECK_NP
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
|
||||
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||
* ithread_mutexattr_t)
|
||||
* int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
||||
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
||||
@@ -190,9 +217,9 @@ extern "C" {
|
||||
* See man page for pthread_mutexattr_setkind_np
|
||||
*****************************************************************************/
|
||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_settype
|
||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_settype
|
||||
#else
|
||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
|
||||
#define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -205,7 +232,7 @@ extern "C" {
|
||||
* ITHREAD_MUTEX_ERRORCHECK_NP
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_mutexattr_t * mutex (must be valid non NULL pointer to
|
||||
* ithread_mutexattr_t * attr (must be valid non NULL pointer to
|
||||
* pthread_mutexattr_t)
|
||||
* int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
|
||||
* or ITHREAD_MUTEX_ERRORCHECK_NP)
|
||||
@@ -215,9 +242,9 @@ extern "C" {
|
||||
* See man page for pthread_mutexattr_getkind_np
|
||||
*****************************************************************************/
|
||||
#ifdef PTHREAD_MUTEX_RECURSIVE
|
||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
|
||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
|
||||
#else
|
||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
|
||||
#define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
|
||||
#endif
|
||||
|
||||
|
||||
@@ -237,7 +264,8 @@ extern "C" {
|
||||
* See man page for pthread_mutex_init
|
||||
*****************************************************************************/
|
||||
#define ithread_mutex_init pthread_mutex_init
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_mutex_lock
|
||||
*
|
||||
@@ -291,7 +319,170 @@ extern "C" {
|
||||
*****************************************************************************/
|
||||
#define ithread_mutex_destroy pthread_mutex_destroy
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlockattr_init
|
||||
*
|
||||
* Description:
|
||||
* Initializes a rwlock attribute variable to default values.
|
||||
* Parameters:
|
||||
* const ithread_rwlockattr_init *attr (must be valid non NULL pointer to
|
||||
* pthread_rwlockattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlockattr_init
|
||||
***************************************************************************/
|
||||
#define ithread_rwlockattr_init pthread_rwlockattr_init
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlockattr_destroy
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources held by the rwlock attribute.
|
||||
* Parameters:
|
||||
* ithread_rwlockattr_t *attr (must be valid non NULL pointer to
|
||||
* pthread_rwlockattr_t)
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlockattr_destroy
|
||||
***************************************************************************/
|
||||
#define ithread_rwlockattr_destroy pthread_rwlockattr_destroy
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlockatttr_setpshared
|
||||
*
|
||||
* Description:
|
||||
* Sets the rwlock type in the attribute.
|
||||
* Valid types are: ITHREAD_PROCESS_PRIVATE
|
||||
* ITHREAD_PROCESS_SHARED
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_rwlockattr_t * attr (must be valid non NULL pointer to
|
||||
* ithread_rwlockattr_t)
|
||||
* int kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success. Nonzero on failure.
|
||||
* Returns EINVAL if the kind is not supported.
|
||||
* See man page for pthread_rwlockattr_setkind_np
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlockatttr_setpshared pthread_rwlockatttr_setpshared
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlockatttr_getpshared
|
||||
*
|
||||
* Description:
|
||||
* Gets the rwlock type in the attribute.
|
||||
* Valid types are: ITHREAD_PROCESS_PRIVATE
|
||||
* ITHREAD_PROCESS_SHARED
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_rwlockattr_t * attr (must be valid non NULL pointer to
|
||||
* pthread_rwlockattr_t)
|
||||
* int *kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success. Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlockatttr_getpshared
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlockatttr_getpshared pthread_rwlockatttr_getpshared
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlock_init
|
||||
*
|
||||
* Description:
|
||||
* Initializes rwlock.
|
||||
* Must be called before use.
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||
* const ithread_rwlockattr_t * rwlock_attr
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlock_init
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlock_init pthread_rwlock_init
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlock_rdlock
|
||||
*
|
||||
* Description:
|
||||
* Locks rwlock for reading.
|
||||
* Parameters:
|
||||
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||
* rwlock must be initialized.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlock_rdlock
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlock_rdlock pthread_rwlock_rdlock
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlock_wrlock
|
||||
*
|
||||
* Description:
|
||||
* Locks rwlock for writting.
|
||||
* Parameters:
|
||||
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||
* rwlock must be initialized.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlock_wrlock
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlock_wrlock pthread_rwlock_wrlock
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlock_unlock
|
||||
*
|
||||
* Description:
|
||||
* Unlocks rwlock.
|
||||
*
|
||||
* Parameters:
|
||||
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||
* rwlock must be initialized.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlock_unlock
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlock_unlock pthread_rwlock_unlock
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_rwlock_destroy
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources held by the rwlock.
|
||||
* rwlock can no longer be used after this call.
|
||||
* rwlock is only destroyed when there are no longer any threads waiting on it.
|
||||
* rwlock cannot be destroyed if it is locked.
|
||||
* Parameters:
|
||||
* ithread_rwlock_t * rwlock (must be valid non NULL pointer to pthread_rwlock_t)
|
||||
* rwlock must be initialized.
|
||||
* Returns:
|
||||
* 0 on success. Nonzero on failure.
|
||||
* Always returns 0.
|
||||
* See man page for pthread_rwlock_destroy
|
||||
*****************************************************************************/
|
||||
#define ithread_rwlock_destroy pthread_rwlock_destroy
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ithread_cond_init
|
||||
*
|
||||
|
@@ -31,7 +31,7 @@
|
||||
|
||||
#include "LinkedList.h"
|
||||
#include <sys/param.h>
|
||||
#if (defined(BSD) && BSD >= 199306)
|
||||
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__)
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
|
@@ -90,22 +90,23 @@ FreeThreadPoolJob( ThreadPool * tp,
|
||||
static int
|
||||
SetPolicyType( PolicyType in )
|
||||
{
|
||||
#ifdef __CYGWIN__
|
||||
/* TODO not currently working... */
|
||||
return 0;
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#ifdef __CYGWIN__
|
||||
/* TODO not currently working... */
|
||||
return 0;
|
||||
#elif defined(__OSX__)
|
||||
setpriority(PRIO_PROCESS, 0, 0);
|
||||
return 0;
|
||||
#elif defined(WIN32)
|
||||
return sched_setscheduler( 0, in);
|
||||
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
|
||||
#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
|
||||
struct sched_param current;
|
||||
|
||||
sched_getparam( 0, ¤t );
|
||||
current.sched_priority = DEFAULT_SCHED_PARAM;
|
||||
return sched_setscheduler( 0, in, ¤t );
|
||||
#else
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -364,7 +365,7 @@ static void SetSeed() {
|
||||
ftime( &t );
|
||||
#if defined(WIN32)
|
||||
srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id().p );
|
||||
#elif defined(__FreeBSD__)
|
||||
#elif defined(__FreeBSD__) || defined(__OSX__)
|
||||
srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id() );
|
||||
#elif defined(__linux__)
|
||||
srand( ( unsigned int )t.millitm + ithread_get_current_thread_id() );
|
||||
@@ -1510,36 +1511,33 @@ static void SetSeed() {
|
||||
}
|
||||
|
||||
#ifdef STATS
|
||||
void ThreadPoolPrintStats( ThreadPoolStats * stats ) {
|
||||
assert( stats != NULL ); if( stats == NULL ) {
|
||||
return;}
|
||||
void ThreadPoolPrintStats(ThreadPoolStats * stats)
|
||||
{
|
||||
assert( stats != NULL );
|
||||
if (stats == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
printf( "ThreadPoolStats at Time: %d\n", time( NULL ) );
|
||||
#else
|
||||
printf( "ThreadPoolStats at Time: %ld\n", time( NULL ) );
|
||||
#endif
|
||||
printf
|
||||
( "Average Wait in High Priority Q in milliseconds: %f\n",
|
||||
stats->avgWaitHQ );
|
||||
printf
|
||||
( "Average Wait in Med Priority Q in milliseconds: %f\n",
|
||||
stats->avgWaitMQ );
|
||||
printf
|
||||
( "Averate Wait in Low Priority Q in milliseconds: %f\n",
|
||||
stats->avgWaitLQ );
|
||||
printf( "Max Threads Active: %d\n", stats->maxThreads );
|
||||
printf( "Current Worker Threads: %d\n",
|
||||
stats->workerThreads );
|
||||
printf( "Current Persistent Threads: %d\n",
|
||||
stats->persistentThreads );
|
||||
printf( "Current Idle Threads: %d\n", stats->idleThreads );
|
||||
printf( "Total Threads : %d\n", stats->totalThreads );
|
||||
printf( "Total Time spent Working in seconds: %f\n",
|
||||
stats->totalWorkTime );
|
||||
printf( "Total Time spent Idle in seconds : %f\n",
|
||||
stats->totalIdleTime );}
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
printf("ThreadPoolStats at Time: %d\n", time(NULL));
|
||||
#else /* __FreeBSD__ */
|
||||
printf("ThreadPoolStats at Time: %ld\n", time(NULL));
|
||||
#endif /* __FreeBSD__ */
|
||||
printf("High Jobs pending: %d\n", stats->currentJobsHQ);
|
||||
printf("Med Jobs Pending: %d\n", stats->currentJobsMQ);
|
||||
printf("Low Jobs Pending: %d\n", stats->currentJobsLQ);
|
||||
printf("Average Wait in High Priority Q in milliseconds: %f\n", stats->avgWaitHQ);
|
||||
printf("Average Wait in Med Priority Q in milliseconds: %f\n", stats->avgWaitMQ);
|
||||
printf("Averate Wait in Low Priority Q in milliseconds: %f\n", stats->avgWaitLQ);
|
||||
printf("Max Threads Active: %d\n", stats->maxThreads);
|
||||
printf("Current Worker Threads: %d\n", stats->workerThreads);
|
||||
printf("Current Persistent Threads: %d\n", stats->persistentThreads);
|
||||
printf("Current Idle Threads: %d\n", stats->idleThreads);
|
||||
printf("Total Threads : %d\n", stats->totalThreads);
|
||||
printf("Total Time spent Working in seconds: %f\n", stats->totalWorkTime);
|
||||
printf("Total Time spent Idle in seconds : %f\n", stats->totalIdleTime);
|
||||
}
|
||||
#endif /* STATS */
|
||||
|
||||
/****************************************************************************
|
||||
* Function: TPAttrSetMaxJobsTotal
|
||||
@@ -1552,17 +1550,19 @@ static void SetSeed() {
|
||||
* Returns:
|
||||
* Always returns 0.
|
||||
*****************************************************************************/
|
||||
int TPAttrSetMaxJobsTotal( ThreadPoolAttr * attr,
|
||||
int maxJobsTotal ) {
|
||||
assert( attr != NULL );
|
||||
int TPAttrSetMaxJobsTotal(
|
||||
ThreadPoolAttr * attr,
|
||||
int maxJobsTotal )
|
||||
{
|
||||
assert( attr != NULL );
|
||||
|
||||
if( attr == NULL ) {
|
||||
return EINVAL;
|
||||
}
|
||||
if( attr == NULL ) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
attr->maxJobsTotal = maxJobsTotal;
|
||||
return 0;
|
||||
}
|
||||
attr->maxJobsTotal = maxJobsTotal;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ThreadPoolGetStats
|
||||
@@ -1579,40 +1579,54 @@ static void SetSeed() {
|
||||
*****************************************************************************/
|
||||
#ifdef STATS
|
||||
int
|
||||
ThreadPoolGetStats( ThreadPool * tp,
|
||||
ThreadPoolStats * stats ) {
|
||||
ThreadPoolGetStats(
|
||||
ThreadPool *tp,
|
||||
ThreadPoolStats *stats)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(stats != NULL);
|
||||
|
||||
assert( tp != NULL );
|
||||
assert( stats != NULL );
|
||||
if( ( tp == NULL ) || ( stats == NULL ) ) {
|
||||
return EINVAL;}
|
||||
if (tp == NULL || stats == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
//if not shutdown then acquire mutex
|
||||
if( !tp->shutdown ) {
|
||||
ithread_mutex_lock( &tp->mutex );}
|
||||
//if not shutdown then acquire mutex
|
||||
if (!tp->shutdown) {
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
}
|
||||
|
||||
( *stats ) = tp->stats; if( stats->totalJobsHQ > 0 )
|
||||
stats->avgWaitHQ =
|
||||
stats->totalTimeHQ / stats->totalJobsHQ;
|
||||
else
|
||||
stats->avgWaitHQ = 0; if( stats->totalJobsMQ > 0 )
|
||||
stats->avgWaitMQ =
|
||||
stats->totalTimeMQ / stats->totalJobsMQ;
|
||||
else
|
||||
stats->avgWaitMQ = 0; if( stats->totalJobsLQ > 0 )
|
||||
stats->avgWaitLQ =
|
||||
stats->totalTimeLQ / stats->totalJobsLQ;
|
||||
else
|
||||
stats->avgWaitLQ = 0;
|
||||
stats->totalThreads = tp->totalThreads;
|
||||
stats->persistentThreads = tp->persistentThreads;
|
||||
stats->currentJobsHQ = ListSize( &tp->highJobQ );
|
||||
stats->currentJobsLQ = ListSize( &tp->lowJobQ );
|
||||
stats->currentJobsMQ = ListSize( &tp->medJobQ );
|
||||
//if not shutdown then release mutex
|
||||
if( !tp->shutdown ) {
|
||||
ithread_mutex_unlock( &tp->mutex );}
|
||||
*stats = tp->stats;
|
||||
if (stats->totalJobsHQ > 0) {
|
||||
stats->avgWaitHQ = stats->totalTimeHQ / stats->totalJobsHQ;
|
||||
} else {
|
||||
stats->avgWaitHQ = 0;
|
||||
}
|
||||
|
||||
if( stats->totalJobsMQ > 0 ) {
|
||||
stats->avgWaitMQ = stats->totalTimeMQ / stats->totalJobsMQ;
|
||||
} else {
|
||||
stats->avgWaitMQ = 0;
|
||||
}
|
||||
|
||||
if( stats->totalJobsLQ > 0 ) {
|
||||
stats->avgWaitLQ = stats->totalTimeLQ / stats->totalJobsLQ;
|
||||
} else {
|
||||
stats->avgWaitLQ = 0;
|
||||
}
|
||||
|
||||
return 0;}
|
||||
stats->totalThreads = tp->totalThreads;
|
||||
stats->persistentThreads = tp->persistentThreads;
|
||||
stats->currentJobsHQ = ListSize( &tp->highJobQ );
|
||||
stats->currentJobsLQ = ListSize( &tp->lowJobQ );
|
||||
stats->currentJobsMQ = ListSize( &tp->medJobQ );
|
||||
|
||||
//if not shutdown then release mutex
|
||||
if( !tp->shutdown ) {
|
||||
ithread_mutex_unlock( &tp->mutex );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* STATS */
|
||||
|
||||
#endif
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <sys/param.h>
|
||||
#if (defined(BSD) && BSD >= 199306)
|
||||
#if (defined(BSD) && BSD >= 199306) || defined(__OSX__)
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
|
Reference in New Issue
Block a user