SF Tracker [ 1628562 ] Maximum total jobs patch
Submitted By: Fredrik Svensson - svefredrik Incremented the libray versions and included some comments in the file configure.ac so that we do not bump the library version excessively, only the necessary numbers on the next release. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@115 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
@@ -62,6 +62,7 @@ typedef enum priority {LOW_PRIORITY,
|
||||
#define DEFAULT_STARVATION_TIME 500 //default starvation time used by TPAttrInit
|
||||
#define DEFAULT_IDLE_TIME 10 * 1000 //default idle time used by TPAttrInit
|
||||
#define DEFAULT_FREE_ROUTINE NULL //default free routine used TPJobInit
|
||||
#define DEFAULT_MAX_JOBS_TOTAL 100 //default max jobs used TPAttrInit
|
||||
|
||||
#define STATS 1 //always include stats because code change is minimal
|
||||
|
||||
@@ -119,23 +120,25 @@ typedef void (*free_routine)(void *arg);
|
||||
*****************************************************************************/
|
||||
typedef struct THREADPOOLATTR
|
||||
{
|
||||
int minThreads; //minThreads, ThreadPool will always maintain at least
|
||||
//this many threads
|
||||
int minThreads; // minThreads, ThreadPool will always maintain at least
|
||||
// this many threads
|
||||
|
||||
int maxThreads; //maxThreads, ThreadPool will never have more than this
|
||||
//number of threads
|
||||
int maxThreads; // maxThreads, ThreadPool will never have more than this
|
||||
// number of threads
|
||||
|
||||
int maxIdleTime; //maxIdleTime (in milliseconds)
|
||||
// this is the maximum time a thread will remain idle
|
||||
// before dying
|
||||
int maxIdleTime; // maxIdleTime (in milliseconds)
|
||||
// this is the maximum time a thread will remain idle
|
||||
// before dying
|
||||
|
||||
int jobsPerThread; //jobs per thread to maintain
|
||||
int jobsPerThread; // jobs per thread to maintain
|
||||
|
||||
int starvationTime; //the time a low priority or med priority
|
||||
//job waits before getting bumped
|
||||
//up a priority (in milliseconds)
|
||||
int maxJobsTotal; // maximum number of jobs that can be queued totally.
|
||||
|
||||
PolicyType schedPolicy; //scheduling policy to use
|
||||
int starvationTime; // the time a low priority or med priority
|
||||
// job waits before getting bumped
|
||||
// up a priority (in milliseconds)
|
||||
|
||||
PolicyType schedPolicy; // scheduling policy to use
|
||||
|
||||
} ThreadPoolAttr;
|
||||
|
||||
@@ -521,6 +524,19 @@ int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime);
|
||||
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: TPAttrSetMaxJobsTotal
|
||||
*
|
||||
* Description:
|
||||
* Sets the maximum number jobs that can be qeued totally.
|
||||
* Parameters:
|
||||
* attr - must be valid thread pool attributes.
|
||||
* maxJobsTotal - maximum number of jobs
|
||||
* Returns:
|
||||
* Always returns 0.
|
||||
*****************************************************************************/
|
||||
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ThreadPoolGetStats
|
||||
*
|
||||
|
@@ -906,6 +906,7 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default:
|
||||
int rc = EOUTOFMEM;
|
||||
|
||||
int tempId = -1;
|
||||
int totalJobs;
|
||||
|
||||
ThreadPoolJob *temp = NULL;
|
||||
|
||||
@@ -922,6 +923,13 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default:
|
||||
|| ( job->priority == MED_PRIORITY )
|
||||
|| ( job->priority == HIGH_PRIORITY ) );
|
||||
|
||||
totalJobs = tp->highJobQ.size + tp->lowJobQ.size + tp->medJobQ.size;
|
||||
if (totalJobs >= tp->attr.maxJobsTotal) {
|
||||
fprintf(stderr, "total jobs = %d, too many jobs", totalJobs);
|
||||
ithread_mutex_unlock( &tp->mutex );
|
||||
return rc;
|
||||
}
|
||||
|
||||
if( jobId == NULL )
|
||||
jobId = &tempId;
|
||||
|
||||
@@ -1267,6 +1275,7 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default:
|
||||
attr->minThreads = DEFAULT_MIN_THREADS;
|
||||
attr->schedPolicy = DEFAULT_POLICY;
|
||||
attr->starvationTime = DEFAULT_STARVATION_TIME;
|
||||
attr->maxJobsTotal = DEFAULT_MAX_JOBS_TOTAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1518,6 +1527,29 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default:
|
||||
stats->totalIdleTime );}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: TPAttrSetMaxJobsTotal
|
||||
*
|
||||
* Description:
|
||||
* Sets the maximum number jobs that can be qeued totally.
|
||||
* Parameters:
|
||||
* attr - must be valid thread pool attributes.
|
||||
* maxJobsTotal - maximum number of jobs
|
||||
* Returns:
|
||||
* Always returns 0.
|
||||
*****************************************************************************/
|
||||
int TPAttrSetMaxJobsTotal( ThreadPoolAttr * attr,
|
||||
int maxJobsTotal ) {
|
||||
assert( attr != NULL );
|
||||
|
||||
if( attr == NULL ) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
attr->maxJobsTotal = maxJobsTotal;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: ThreadPoolGetStats
|
||||
*
|
||||
|
Reference in New Issue
Block a user