- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/sys/psThread.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/psLib/src/sys/psThread.c
r28405 r33415 36 36 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Mutex for locking threads 37 37 38 static psList *pending = NULL;// queue of pending jobs39 static psList *done = NULL;// queue of done jobs38 static volatile psList *pending = NULL; // queue of pending jobs 39 static volatile psList *done = NULL; // queue of done jobs 40 40 static pthread_t *threads = NULL; // array of the POSIX thread handles 41 41 static psArray *pool = NULL; // array of defined threads … … 91 91 92 92 job->type = psStringCopy(type); 93 job->args = psArrayAlloc (0);93 job->args = psArrayAllocEmpty(16); 94 94 job->results = NULL; 95 95 return job; … … 116 116 done = psListAlloc(NULL); 117 117 } 118 psListAdd( done, PS_LIST_TAIL, job);118 psListAdd((psList *)done, PS_LIST_TAIL, job); 119 119 psFree(job); 120 120 return task->function(job); … … 125 125 pending = psListAlloc(NULL); 126 126 } 127 psListAdd( pending, PS_LIST_TAIL, job);127 psListAdd((psList *)pending, PS_LIST_TAIL, job); 128 128 psFree(job); 129 129 psThreadUnlock(); … … 139 139 } 140 140 141 psThreadJob *job = psListGetAndRemove( pending, PS_LIST_HEAD);141 psThreadJob *job = psListGetAndRemove((psList *)pending, PS_LIST_HEAD); 142 142 return job; 143 143 } … … 150 150 } 151 151 152 psThreadJob *job = psListGetAndRemove( done, PS_LIST_HEAD);152 psThreadJob *job = psListGetAndRemove((psList *) done, PS_LIST_HEAD); 153 153 return job; 154 154 } … … 179 179 PS_ASSERT_THREAD_TASK_NON_NULL(task, false); 180 180 181 // fprintf(stderr, "adding task %s\n", task->type); 182 181 183 if (!tasks) { 182 184 tasks = psHashAlloc(TASK_BUCKETS); … … 189 191 { 190 192 PS_ASSERT_STRING_NON_EMPTY(type, false); 193 // fprintf(stderr, "removing task %s\n", type); 191 194 192 195 return psHashRemove(tasks, type); … … 223 226 224 227 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 228 // fprintf(stderr, "launching job %s\n", job->type); 225 229 #ifdef HAVE_BACKTRACE 226 230 if (!task && bt_buffer) { … … 246 250 "invalid number of arguments to %s (%ld supplied, expected %d)", 247 251 task->type, job->args->n, task->nArgs); 252 // fprintf(stderr, " thread for %s %p launching on %p\n", job->type, task->function, self); 253 254 // Run the job's function 248 255 bool status = task->function(job); // Status of executing task 256 257 // fprintf(stderr, " thread for %s %p finished on %p with status %d\n", job->type, task->function, self, status); 249 258 250 259 // Put the completed job on the 'done' queue … … 253 262 done = psListAlloc(NULL); 254 263 } 255 psListAdd( done, PS_LIST_TAIL, job);264 psListAdd((psList *)done, PS_LIST_TAIL, job); 256 265 psFree(job); 257 266 … … 306 315 307 316 // call this function after you have added jobs to the queue and 308 bool psThreadPoolWait(bool harvest) 309 { 317 bool psThreadPoolWait(bool harvest, bool harvestOnFailure) 318 { 319 // fprintf(stderr, "psThreadPoolWait called with harvest: %d\n", harvest); 310 320 if (!pool || pool->n == 0) { 311 321 // No threads initialised, so everything's done … … 326 336 #endif 327 337 338 // accumulate the number of faulted jobs that we encounter 339 int numFaults = 0; 328 340 while (1) { 329 341 // check for an error … … 331 343 psThread *thread = pool->data[i]; 332 344 if (thread->fault) { 333 return false;345 numFaults++; 334 346 } 335 347 } … … 354 366 // Nothing in the queue and nothing more to add 355 367 // Ensure everything is harvested, if requested 356 if (harvest ) {368 if (harvest || (numFaults && harvestOnFailure)) { 357 369 psThreadJobHarvest(); 358 370 } 359 371 psThreadUnlock(); 360 return true;372 return numFaults == 0; 361 373 } 362 374
Note:
See TracChangeset
for help on using the changeset viewer.
