This is Unofficial EPICS BASE Doxygen Site
poolPriv.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2014 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * EPICS BASE is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 
8 #ifndef POOLPRIV_H
9 #define POOLPRIV_H
10 
11 #include "epicsThreadPool.h"
12 #include "ellLib.h"
13 #include "epicsThread.h"
14 #include "epicsEvent.h"
15 #include "epicsMutex.h"
16 
19  size_t sharedCount;
20 
21  ELLLIST jobs; /* run queue */
22  ELLLIST owned; /* unqueued jobs. */
23 
24  /* Worker state counters.
25  * The life cycle of a worker is
26  * Wakeup -> Awake -> Sleeping
27  * Newly created workers go into the wakeup state
28  */
29 
30  /* # of running workers which are not waiting for a wakeup event */
31  unsigned int threadsAreAwake;
32  /* # of sleeping workers which need to be awakened */
33  unsigned int threadsWaking;
34  /* # of workers waiting on the workerWakeup event */
35  unsigned int threadsSleeping;
36  /* # of threads started and not stopped */
37  unsigned int threadsRunning;
38 
39  /* # of observers waiting on pool events */
40  unsigned int observerCount;
41 
44 
46 
47  /* Disallow epicsJobQueue */
48  unsigned int pauseadd:1;
49  /* Prevent workers from running new jobs */
50  unsigned int pauserun:1;
51  /* Prevent further changes to pool options */
52  unsigned int freezeopt:1;
53  /* tell workers to exit */
54  unsigned int shutdown:1;
55 
57 
58  /* copy of config passed when created */
60 };
61 
62 /* Called after manipulating counters to check that invariants are preserved */
63 #define CHECKCOUNT(pPool) do { \
64  if (!(pPool)->shutdown) { \
65  assert((pPool)->threadsAreAwake + (pPool)->threadsSleeping == (pPool)->threadsRunning); \
66  assert((pPool)->threadsWaking <= (pPool)->threadsSleeping); \
67  } \
68 } while(0)
69 
70 /* When created a job is idle. queued and running are false
71  * and jobnode is in the thread pool's owned list.
72  *
73  * When the job is added, the queued flag is set and jobnode
74  * is in the jobs list.
75  *
76  * When the job starts running the queued flag is cleared and
77  * the running flag is set. jobnode is not in any list
78  * (held locally by worker).
79  *
80  * When the job has finished running, the running flag is cleared.
81  * The queued flag may be set if the job re-added itself.
82  * Based on the queued flag jobnode is added to the appropriate
83  * list.
84  */
85 struct epicsJob {
88  void *arg;
90 
91  unsigned int queued:1;
92  unsigned int running:1;
93  unsigned int freewhendone:1; /* lazy delete of running job */
94  unsigned int dead:1; /* flag to catch use of freed objects */
95 };
96 
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
100 
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif // POOLPRIV_H
epicsEventId workerWakeup
Definition: poolPriv.h:42
ELLLIST owned
Definition: poolPriv.h:22
epicsMutexId guard
Definition: poolPriv.h:56
epicsThreadPool * pool
Definition: poolPriv.h:89
void * arg
Definition: poolPriv.h:88
ELLNODE jobnode
Definition: poolPriv.h:86
ELLLIST jobs
Definition: poolPriv.h:21
ELLNODE sharedNode
Definition: poolPriv.h:18
epicsJobFunction func
Definition: poolPriv.h:87
unsigned int threadsWaking
Definition: poolPriv.h:33
A doubly-linked list library.
unsigned int threadsAreAwake
Definition: poolPriv.h:31
APIs for the epicsMutex mutual exclusion semaphore.
epicsEventId shutdownEvent
Definition: poolPriv.h:43
epicsThreadPoolConfig conf
Definition: poolPriv.h:59
unsigned int observerCount
Definition: poolPriv.h:40
int createPoolThread(epicsThreadPool *pool)
Definition: poolJob.c:117
List node type.
Definition: ellLib.h:45
APIs for the epicsEvent binary semaphore.
unsigned int pauseadd
Definition: poolPriv.h:48
unsigned int threadsRunning
Definition: poolPriv.h:37
unsigned int freezeopt
Definition: poolPriv.h:52
unsigned int threadsSleeping
Definition: poolPriv.h:35
void(* epicsJobFunction)(void *arg, epicsJobMode mode)
List header type.
Definition: ellLib.h:56
unsigned int pauserun
Definition: poolPriv.h:50
C++ and C descriptions for a thread.
unsigned int shutdown
Definition: poolPriv.h:54
epicsEventId observerWakeup
Definition: poolPriv.h:45
size_t sharedCount
Definition: poolPriv.h:19