Changeset 18953 for trunk/psLib/src/sys/psThread.h
- Timestamp:
- Aug 8, 2008, 8:05:09 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psThread.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psThread.h
r18827 r18953 4 4 * 5 5 * @author EAM, IFA 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2008-0 7-31 23:56:29 $6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2008-08-08 18:05:09 $ 8 8 * 9 9 * Copyright 2004-2005 Insitute for Astronomy, University of Hawaii … … 16 16 /// @{ 17 17 18 /// Job to be executed on a thread 19 /// 20 /// This job is passed to the function that executes it 18 21 typedef struct { 19 psString type; 20 psArray *args; 22 psString type; // Type of thread 23 psArray *args; // Arguments to job 21 24 } psThreadJob; 22 25 26 #define PS_ASSERT_THREAD_JOB_NON_NULL(JOB, RVAL) \ 27 if (!(JOB) || !(JOB)->type || !(JOB)->args) { \ 28 psError(PS_ERR_UNEXPECTED_NULL, true, "Thread job %s or one of its components is NULL.", #JOB); \ 29 return RVAL; \ 30 } 31 32 /// A thread, which executes a job 33 /// 34 /// Wraps pthread with a few extra conveniences 23 35 typedef struct { 24 bool busy; 25 bool fault; 26 pthread_t pt; 36 bool busy; // Is the thread busy? 37 bool fault; // Has the thread faulted? 38 pthread_t pt; // The thread itself 27 39 } psThread; 28 40 29 typedef bool (*psThreadTaskFunction)(psThreadJob *job); 41 /// Function to execute a thread job 42 typedef bool (*psThreadTaskFunction)(const psThreadJob *job); 30 43 44 /// Task that is executed on a thread 31 45 typedef struct { 32 psString type; 33 int nArgs; 34 psThreadTaskFunction function; 46 psString type; // Type of task 47 int nArgs; // Number of arguments that function takes 48 psThreadTaskFunction function; // Function to execute 35 49 } psThreadTask; 36 50 37 // typedef void *(*psThreadLaunchJobsFunction)(void *data); 51 #define PS_ASSERT_THREAD_TASK_NON_NULL(TASK, RVAL) \ 52 if (!(TASK) || !(TASK)->type || (TASK)->nArgs < 0 || !(TASK)->function) { \ 53 psError(PS_ERR_UNEXPECTED_NULL, true, "Thread task %s or one of its components is NULL.", #TASK); \ 54 return RVAL; \ 55 } 38 56 39 void psThreadLock ();40 void psThreadUnlock ();41 57 42 psThread *psThreadAlloc (); 58 /// Lock the thread mutex 59 void psThreadLock(void); 43 60 44 psThreadJob *psThreadJobAlloc (char *type); 45 bool psThreadJobAddPending (psThreadJob *job); 46 psThreadJob *psThreadJobGetPending (); 47 psThreadJob *psThreadJobGetDone (); 61 /// Unlock the thread mutex 62 void psThreadUnlock(void); 48 63 49 psThreadTask *psThreadTaskAlloc (char *type, int nArgs); 50 bool psThreadTaskAdd (psThreadTask *task); 51 void *psThreadLauncher (void *data); 64 /// Allocate a thread 65 psThread *psThreadAlloc(void); 52 66 53 bool psThreadPoolInit (int nThreads); 54 bool psThreadPoolWait (); 55 bool psThreadPoolFinalize (); 67 /// Allocate a thread job 68 psThreadJob *psThreadJobAlloc(const char *type); 69 70 /// Add a pending job to the queue 71 bool psThreadJobAddPending(psThreadJob *job); 72 73 /// Get a job off the queue of pending jobs 74 psThreadJob *psThreadJobGetPending(void); 75 76 /// Get a job off the queue of done jobs 77 psThreadJob *psThreadJobGetDone(void); 78 79 /// Allocate a thread task 80 psThreadTask *psThreadTaskAlloc(const char *type, // Type of task 81 int nArgs // Number of arguments 82 ); 83 84 /// Add a task to the list 85 bool psThreadTaskAdd(psThreadTask *task // Task to add 86 ); 87 88 /// Launch jobs on a thread 89 void *psThreadLauncher(void *thread // Thread (of type psThread) 90 ); 91 92 /// Initialise a pool of threads 93 bool psThreadPoolInit(int nThreads // Number of threads 94 ); 95 96 /// Return size of thread pool 97 int psThreadPoolSize(void); 98 99 /// Wait for the thread pool to finish 100 /// 101 /// This function blocks (waits in usleep) until either an error is detected on one of the threads or until ll 102 /// threads are idle and no jobs are left on the queue 103 bool psThreadPoolWait(bool harvest // Harvest the jobs from the queue? 104 ); 105 106 /// Clean up the thread pool 107 bool psThreadPoolFinalize(void); 56 108 57 109 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
