Changeset 28138
- Timestamp:
- May 27, 2010, 10:51:54 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psThread.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psThread.c
r21348 r28138 121 121 } 122 122 123 psThreadLock(); 123 124 psThreadJob *job = psListGetAndRemove(pending, PS_LIST_HEAD); 125 psThreadUnlock(); 124 126 return job; 125 127 } … … 132 134 } 133 135 136 psThreadLock(); 134 137 psThreadJob *job = psListGetAndRemove(done, PS_LIST_HEAD); 138 psThreadUnlock(); 135 139 return job; 136 140 } … … 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 195 psThreadLock();196 199 psThreadJob *job = NULL; // Job to process 197 200 while ((job = psThreadJobGetPending()) == NULL) { 198 psThreadUnlock();199 201 usleep(THREAD_WAIT); 200 psThreadLock(); // XXX ???201 202 } 202 203 self->busy = true; 203 204 204 205 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 205 psThreadUnlock();206 207 206 psAssert(task, "Couldn't find thread task %s", job->type); 208 207 psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs); … … 216 215 psListAdd(done, PS_LIST_TAIL, job); 217 216 psFree(job); 217 psThreadUnlock(); 218 218 219 219 if (!status) { … … 221 221 } 222 222 self->busy = false; 223 psThreadUnlock();224 223 } 225 224 } … … 257 256 static void psThreadJobHarvest(void) 258 257 { 259 psThreadLock();260 258 psThreadJob *job; // Job from done queue 261 259 while ((job = psThreadJobGetDone())) { 262 260 psFree(job); 263 261 } 264 psThreadUnlock();265 262 return; 266 263 } … … 287 284 } 288 285 289 // Harvest jobs , if requested286 // Harvest jobs in the background, if requested 290 287 if (harvest) { 291 288 psThreadJobHarvest(); 292 289 } 293 290 291 #if 0 // Thread state doesn't matter, only the pending job queue 294 292 // are all threads idle? 295 psThreadLock();296 293 for (int i = 0; i < pool->n; i++) { 297 294 psThread *thread = pool->data[i]; … … 301 298 } 302 299 } 303 304 if (!pending || !pending->head) { 300 #endif 301 302 psThreadLock(); 303 bool more = (pending && pending->head) ? true : false; // More to process? 304 psThreadUnlock(); 305 306 if (!more) { 305 307 // Nothing in the queue 306 psThreadUnlock();307 308 // Ensure everything is harvested, if requested 308 309 if (harvest) { … … 312 313 } 313 314 314 SLEEP:315 psThreadUnlock();316 315 usleep(THREAD_WAIT); 317 316 }
Note:
See TracChangeset
for help on using the changeset viewer.
