IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18751


Ignore:
Timestamp:
Jul 27, 2008, 7:59:42 AM (18 years ago)
Author:
eugene
Message:

added a done-job queue, minor mods to apis

Location:
branches/eam_branch_20080719/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/psLib/src/sys/psThread.c

    r18749 r18751  
    1717
    1818static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    19 static psList *queue = NULL;            // queue of pending jobs
     19static psList *pending = NULL;          // queue of pending jobs
     20static psList *done = NULL;             // queue of done jobs
     21
    2022static psArray *pool = NULL;            // array of defined threads
    2123
     
    5052}
    5153
    52 // add a job to the queue of active jobs
    53 bool psThreadJobAddToQueue (psThreadJob *job) {
     54// add a job to the queue of pending jobs
     55bool psThreadJobAddPending (psThreadJob *job) {
    5456
    5557    psThreadLock ();
    56     if (queue == NULL) {
    57         queue = psListAlloc(NULL);
     58    if (pending == NULL) {
     59        pending = psListAlloc(NULL);
    5860    }
    5961
    60     psListAdd (queue, PS_LIST_TAIL, job);
     62    psListAdd (pending, PS_LIST_TAIL, job);
    6163    psThreadUnlock ();
    6264    return true;
     
    6466
    6567// this function is not locked -- see thread launder for example
    66 psThreadJob *psThreadJobGet () {
     68psThreadJob *psThreadJobGetPending () {
    6769
    68     psThreadJob *job = psListGetAndRemove (queue, PS_LIST_HEAD);
     70    if (!pending) return NULL;
     71
     72    psThreadJob *job = psListGetAndRemove (pending, PS_LIST_HEAD);
     73
     74    // jobs we pull off the pending queue get placed on the done queue
     75    if (job) {
     76        if (done == NULL) {
     77            done = psListAlloc(NULL);
     78        }
     79        psListAdd (done, PS_LIST_TAIL, job);
     80    }
     81    return job;
     82}
     83
     84// this function is not locked -- see thread launder for example
     85psThreadJob *psThreadJobGetDone () {
     86
     87    if (!done) return NULL;
     88
     89    psThreadJob *job = psListGetAndRemove (done, PS_LIST_HEAD);
    6990    return job;
    7091}
     
    122143
    123144        // is the queue empty?
    124         if (queue->head == NULL) {
     145        if (pending->head == NULL) {
    125146            psThreadUnlock();
    126147            return true;
  • branches/eam_branch_20080719/psLib/src/sys/psThread.h

    r18749 r18751  
    44 *
    55 *  @author EAM, IFA
    6  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2008-07-26 03:48:39 $
     6 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2008-07-27 17:59:42 $
    88 *
    99 *  Copyright 2004-2005 Insitute for Astronomy, University of Hawaii
     
    3333
    3434psThreadJob *psThreadJobAlloc (char *type, int nArgs);
    35 bool psThreadJobAddToQueue (psThreadJob *job);
    36 psThreadJob *psThreadJobGet ();
     35bool psThreadJobAddPending (psThreadJob *job);
     36psThreadJob *psThreadJobGetPending ();
     37psThreadJob *psThreadJobGetDone ();
    3738
    3839psThread *psThreadAlloc ();
Note: See TracChangeset for help on using the changeset viewer.