Changeset 28304 for branches/czw_branch/20100519/psLib/src/sys/psThread.c
- Timestamp:
- Jun 10, 2010, 6:28:51 PM (16 years ago)
- Location:
- branches/czw_branch/20100519
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/sys/psThread.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20100519
- Property svn:mergeinfo changed
-
branches/czw_branch/20100519/psLib/src/sys/psThread.c
r21348 r28304 21 21 #define TASK_BUCKETS 8 // Number of hash buckets for task list 22 22 23 // Mutex covers: 24 // * pending queue 25 // * done queue 26 // * thread->busy states 23 27 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Mutex for locking threads 28 24 29 static psList *pending = NULL; // queue of pending jobs 25 30 static psList *done = NULL; // queue of done jobs … … 28 33 static psArray *tsd = NULL; // Thread-specific data 29 34 30 31 35 /***** basic thread functions *****/ 32 36 … … 193 197 // request a new job, if there are none available, sleep a bit 194 198 // we have to lock here so the job queue cannot be empty yet no threads busy 199 psThreadJob *job = NULL; // Job to process 195 200 psThreadLock(); 196 psThreadJob *job = NULL; // Job to process197 201 while ((job = psThreadJobGetPending()) == NULL) { 202 // Unlock while sleeping, then lock to read the pending queue again 198 203 psThreadUnlock(); 199 204 usleep(THREAD_WAIT); 200 psThreadLock(); // XXX ???205 psThreadLock(); 201 206 } 202 207 self->busy = true; 208 psThreadUnlock(); 203 209 204 210 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 205 psThreadUnlock();206 207 211 psAssert(task, "Couldn't find thread task %s", job->type); 208 212 psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs); … … 254 258 } 255 259 256 // Harvest jobs from the 260 // Harvest jobs from the done list 257 261 static void psThreadJobHarvest(void) 258 262 { 259 psThreadLock();260 263 psThreadJob *job; // Job from done queue 261 264 while ((job = psThreadJobGetDone())) { 262 265 psFree(job); 263 266 } 264 psThreadUnlock();265 267 return; 266 268 } … … 273 275 // Ensure everything is harvested, if requested 274 276 if (harvest) { 277 // No threads, no no need to lock 275 278 psThreadJobHarvest(); 276 279 } … … 287 290 } 288 291 289 // Harvest jobs, if requested 292 psThreadLock(); 293 294 // Harvest jobs in the background, if requested 290 295 if (harvest) { 291 296 psThreadJobHarvest(); … … 293 298 294 299 // are all threads idle? 295 psThreadLock();296 300 for (int i = 0; i < pool->n; i++) { 297 301 psThread *thread = pool->data[i]; … … 303 307 304 308 if (!pending || !pending->head) { 305 // Nothing in the queue 306 psThreadUnlock(); 309 // Nothing in the queue and nothing more to add 307 310 // Ensure everything is harvested, if requested 308 311 if (harvest) { 309 312 psThreadJobHarvest(); 310 313 } 314 psThreadUnlock(); 311 315 return true; 312 316 }
Note:
See TracChangeset
for help on using the changeset viewer.
