IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28138


Ignore:
Timestamp:
May 27, 2010, 10:51:54 AM (16 years ago)
Author:
Paul Price
Message:

Reworking the locks because something still seems to be sneaking through every now and then.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psThread.c

    r21348 r28138  
    121121    }
    122122
     123    psThreadLock();
    123124    psThreadJob *job = psListGetAndRemove(pending, PS_LIST_HEAD);
     125    psThreadUnlock();
    124126    return job;
    125127}
     
    132134    }
    133135
     136    psThreadLock();
    134137    psThreadJob *job = psListGetAndRemove(done, PS_LIST_HEAD);
     138    psThreadUnlock();
    135139    return job;
    136140}
     
    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
    195         psThreadLock();
    196199        psThreadJob *job = NULL;        // Job to process
    197200        while ((job = psThreadJobGetPending()) == NULL) {
    198             psThreadUnlock();
    199201            usleep(THREAD_WAIT);
    200             psThreadLock(); // XXX ???
    201202        }
    202203        self->busy = true;
    203204
    204205        psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
    205         psThreadUnlock();
    206 
    207206        psAssert(task, "Couldn't find thread task %s", job->type);
    208207        psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s (%ld supplied, expected %d)", task->type, job->args->n, task->nArgs);
     
    216215        psListAdd(done, PS_LIST_TAIL, job);
    217216        psFree(job);
     217        psThreadUnlock();
    218218
    219219        if (!status) {
     
    221221        }
    222222        self->busy = false;
    223         psThreadUnlock();
    224223    }
    225224}
     
    257256static void psThreadJobHarvest(void)
    258257{
    259     psThreadLock();
    260258    psThreadJob *job;           // Job from done queue
    261259    while ((job = psThreadJobGetDone())) {
    262260        psFree(job);
    263261    }
    264     psThreadUnlock();
    265262    return;
    266263}
     
    287284        }
    288285
    289         // Harvest jobs, if requested
     286        // Harvest jobs in the background, if requested
    290287        if (harvest) {
    291288            psThreadJobHarvest();
    292289        }
    293290
     291#if 0 // Thread state doesn't matter, only the pending job queue
    294292        // are all threads idle?
    295         psThreadLock();
    296293        for (int i = 0; i < pool->n; i++) {
    297294            psThread *thread = pool->data[i];
     
    301298            }
    302299        }
    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) {
    305307            // Nothing in the queue
    306             psThreadUnlock();
    307308            // Ensure everything is harvested, if requested
    308309            if (harvest) {
     
    312313        }
    313314
    314     SLEEP:
    315         psThreadUnlock();
    316315        usleep(THREAD_WAIT);
    317316    }
Note: See TracChangeset for help on using the changeset viewer.