Changeset 33089 for trunk/psLib
- Timestamp:
- Jan 11, 2012, 10:16:48 AM (15 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
imageops/psImageConvolve.c (modified) (5 diffs)
-
imageops/psImageCovariance.c (modified) (2 diffs)
-
sys/psThread.c (modified) (8 diffs)
-
sys/psThread.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r32745 r33089 1039 1039 } 1040 1040 } 1041 if (!psThreadPoolWait(true )) {1041 if (!psThreadPoolWait(true, true)) { 1042 1042 psError(PS_ERR_UNKNOWN, false, "Error waiting for threads."); 1043 1043 psFree(gaussNorm); … … 1390 1390 } 1391 1391 // wait here for the threaded jobs to finish (NOP if threading is not active) 1392 if (!psThreadPoolWait(true )) {1392 if (!psThreadPoolWait(true, true)) { 1393 1393 psError(PS_ERR_UNKNOWN, false, "Unable to smooth image"); 1394 1394 psFree(calculation); … … 1437 1437 1438 1438 // wait here for the threaded jobs to finish (NOP if threading is not active) 1439 if (!psThreadPoolWait(true )) {1439 if (!psThreadPoolWait(true, true)) { 1440 1440 psError(PS_ERR_UNKNOWN, false, "Unable to smooth image"); 1441 1441 psFree(calculation); … … 1752 1752 } 1753 1753 } 1754 if (!psThreadPoolWait(true )) {1754 if (!psThreadPoolWait(true, true)) { 1755 1755 psError(PS_ERR_UNKNOWN, false, "Error waiting for threads."); 1756 1756 psFree(conv); … … 1787 1787 } 1788 1788 } 1789 if (!psThreadPoolWait(true )) {1789 if (!psThreadPoolWait(true, true)) { 1790 1790 psError(PS_ERR_UNKNOWN, false, "Error waiting for threads."); 1791 1791 psFree(conv); -
trunk/psLib/src/imageops/psImageCovariance.c
r32714 r33089 193 193 } 194 194 195 if (threaded && !psThreadPoolWait(true )) {195 if (threaded && !psThreadPoolWait(true, true)) { 196 196 psError(PS_ERR_UNKNOWN, false, "Error waiting for threads."); 197 197 return false; … … 360 360 } 361 361 } 362 if (threaded && !psThreadPoolWait(true )) {362 if (threaded && !psThreadPoolWait(true, true)) { 363 363 psError(PS_ERR_UNKNOWN, false, "Error waiting for threads."); 364 364 return false; -
trunk/psLib/src/sys/psThread.c
r32715 r33089 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 … … 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 -
trunk/psLib/src/sys/psThread.h
r28405 r33089 116 116 /// Wait for the thread pool to finish 117 117 /// 118 /// This function blocks (waits in usleep) until either an error is detected on one of the threads or until ll 119 /// threads are idle and no jobs are left on the queue 120 bool psThreadPoolWait(bool harvest // Harvest the jobs from the queue? 118 /// This function blocks (waits in usleep) until all threads are idle and no jobs 119 /// are left on the queue 120 /// returns success if all jobs return success, otherwise returns false 121 bool psThreadPoolWait(bool harvest, // Harvest the jobs from the queue? 122 bool harvestOnFailure // If harvest is false, harvest the jobs if a failure is encountered 121 123 ); 122 124
Note:
See TracChangeset
for help on using the changeset viewer.
