Changeset 28405 for trunk/psLib/src/sys
- Timestamp:
- Jun 18, 2010, 2:25:38 PM (16 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
-
psThread.c (modified) (4 diffs)
-
psThread.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psThread.c
r28402 r28405 99 99 bool psThreadJobAddPending(psThreadJob *job) 100 100 { 101 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 101 if (!job) { 102 // Asking for a no-op 103 return true; 104 } 102 105 103 106 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job … … 114 117 } 115 118 psListAdd(done, PS_LIST_TAIL, job); 116 119 psFree(job); 117 120 return task->function(job); 118 121 } … … 123 126 } 124 127 psListAdd(pending, PS_LIST_TAIL, job); 128 psFree(job); 125 129 psThreadUnlock(); 126 130 … … 279 283 for (int i = 0; i < nThreads; i++) { 280 284 psThread *thread = pool->data[i] = psThreadAlloc(); // Thread for pool 281 if ( !pthread_create(&threads[i], NULL, psThreadLauncher, thread)) {285 if (pthread_create(&threads[i], NULL, psThreadLauncher, thread)) { 282 286 psAbort("Unable to create thread"); 283 287 } -
trunk/psLib/src/sys/psThread.h
r28402 r28405 73 73 74 74 /// Add a pending job to the queue 75 /// 76 /// This function swallows the provided job, so that the user no longer owns it. This is because freeing the 77 /// job is not thread-safe (its reference count is being changed within the threads) so we handle it ourselves 78 /// and absolve the user from all responsibility. If the user stores the job, he should only access it while 79 /// threads are processing in code protected by psThreadLock/psThreadUnlock. 75 80 bool psThreadJobAddPending(psThreadJob *job); 76 81 77 82 /// Get a job off the queue of pending jobs 83 /// 84 /// This function is not thread-safe. Protect with psThreadLock/psThreadUnlock if threads are running. 78 85 psThreadJob *psThreadJobGetPending(void); 79 86 80 87 /// Get a job off the queue of done jobs 88 /// 89 /// This function is not thread-safe. Protect with psThreadLock/psThreadUnlock if threads are running. 81 90 psThreadJob *psThreadJobGetDone(void); 82 91 … … 115 124 bool psThreadPoolFinalize(void); 116 125 117 126 #if 0 118 127 /// Add thread-specific data 119 128 /// … … 134 143 bool psThreadDataRemove(const char *name // Name of data 135 144 ); 136 145 #endif 137 146 138 147 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
