IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 10, 2010, 6:28:51 PM (16 years ago)
Author:
watersc1
Message:

Skycell Summary and stack Association stuff should be finished. I'll merge and do final tests on monday.

Location:
branches/czw_branch/20100519
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100519

  • branches/czw_branch/20100519/psLib/src/sys/psThread.c

    r21348 r28304  
    2121#define TASK_BUCKETS 8                  // Number of hash buckets for task list
    2222
     23// Mutex covers:
     24// * pending queue
     25// * done queue
     26// * thread->busy states
    2327static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // Mutex for locking threads
     28
    2429static psList *pending = NULL;          // queue of pending jobs
    2530static psList *done = NULL;             // queue of done jobs
     
    2833static psArray *tsd = NULL;             // Thread-specific data
    2934
    30 
    3135/***** basic thread functions *****/
    3236
     
    193197        // request a new job, if there are none available, sleep a bit
    194198        // we have to lock here so the job queue cannot be empty yet no threads busy
     199        psThreadJob *job = NULL;        // Job to process
    195200        psThreadLock();
    196         psThreadJob *job = NULL;        // Job to process
    197201        while ((job = psThreadJobGetPending()) == NULL) {
     202            // Unlock while sleeping, then lock to read the pending queue again
    198203            psThreadUnlock();
    199204            usleep(THREAD_WAIT);
    200             psThreadLock(); // XXX ???
     205            psThreadLock();
    201206        }
    202207        self->busy = true;
     208        psThreadUnlock();
    203209
    204210        psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
    205         psThreadUnlock();
    206 
    207211        psAssert(task, "Couldn't find thread task %s", job->type);
    208212        psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs);
     
    254258}
    255259
    256 // Harvest jobs from the
     260// Harvest jobs from the done list
    257261static void psThreadJobHarvest(void)
    258262{
    259     psThreadLock();
    260263    psThreadJob *job;           // Job from done queue
    261264    while ((job = psThreadJobGetDone())) {
    262265        psFree(job);
    263266    }
    264     psThreadUnlock();
    265267    return;
    266268}
     
    273275        // Ensure everything is harvested, if requested
    274276        if (harvest) {
     277            // No threads, no no need to lock
    275278            psThreadJobHarvest();
    276279        }
     
    287290        }
    288291
    289         // Harvest jobs, if requested
     292        psThreadLock();
     293
     294        // Harvest jobs in the background, if requested
    290295        if (harvest) {
    291296            psThreadJobHarvest();
     
    293298
    294299        // are all threads idle?
    295         psThreadLock();
    296300        for (int i = 0; i < pool->n; i++) {
    297301            psThread *thread = pool->data[i];
     
    303307
    304308        if (!pending || !pending->head) {
    305             // Nothing in the queue
    306             psThreadUnlock();
     309            // Nothing in the queue and nothing more to add
    307310            // Ensure everything is harvested, if requested
    308311            if (harvest) {
    309312                psThreadJobHarvest();
    310313            }
     314            psThreadUnlock();
    311315            return true;
    312316        }
Note: See TracChangeset for help on using the changeset viewer.