17 #elif defined(HAVE_DB4_DB_H)
20 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
24 #include "sysdep_decls.h"
27 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
31 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
35 #define timercmp(tvp, uvp, cmp) \
36 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
37 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
38 ((tvp)->tv_sec cmp (uvp)->tv_sec))
42 #define timeradd(tvp, uvp, vvp) \
44 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
45 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
46 if ((vvp)->tv_usec >= 1000000) { \
48 (vvp)->tv_usec -= 1000000; \
54 #define timersub(tvp, uvp, vvp) \
56 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
57 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
58 if ((vvp)->tv_usec < 0) { \
60 (vvp)->tv_usec += 1000000; \
66 // #define THREADS_USESIGNALS
72 enum CtdlThreadState {
76 CTDL_THREAD_CANCELLED,
79 CTDL_THREAD_STOP_REQ, /* Do NOT put any running states before this state */
83 CTDL_THREAD_LAST_STATE
85 typedef struct CtdlThreadNode CtdlThreadNode;
87 struct CtdlThreadNode{
88 citthread_t tid; /* id as returned by citthread_create() */
89 pid_t pid; /* pid, as best the OS will let us determine */
90 time_t when; /* When to start a scheduled thread */
91 struct CitContext *Context; /* The session context that this thread mught be working on or NULL if none */
92 long number; /* A unigue number for this thread (not implimented yet) */
93 int wakefd_recv; /* An fd that this thread can sleep on (not implimented yet) */
94 int wakefd_send; /* An fd that this thread can send out on (Not implimented yet) */
95 int signal; /* A field to store a signal we caught. */
96 const char *name; /* A name for this thread */
97 void *(*thread_func) (void *arg); /* The actual function that does this threads work */
98 void *user_args; /* Arguments passed to this threads work function */
99 long flags; /* Flags that describe this thread */
100 enum CtdlThreadState state; /* Flag to show state of this thread */
101 time_t stop_ticker; /* A counter to determine how long it has taken for this thread to exit */
102 citthread_mutex_t ThreadMutex; /* A mutex to sync this thread to others if this thread allows (also used for sleeping) */
103 citthread_cond_t ThreadCond; /* A condition variable to sync this thread with others */
104 citthread_mutex_t SleepMutex; /* A mutex for sleeping */
105 citthread_cond_t SleepCond; /* A condition variable for sleeping */
106 citthread_attr_t attr; /* Attributes of this thread */
107 struct timeval start_time; /* Time this thread was started */
108 struct timeval last_state_change; /* Time when this thread last changed state */
109 double avg_sleeping; /* Average sleeping time */
110 double avg_running; /* Average running time */
111 double avg_blocked; /* Average blocked time */
112 double load_avg; /* Load average for this thread */
113 CtdlThreadNode *prev; /* Previous thread in the thread table */
114 CtdlThreadNode *next; /* Next thread in the thread table */
117 extern CtdlThreadNode *CtdlThreadList;
119 typedef struct ThreadTSD ThreadTSD;
122 DB_TXN *tid; /* Transaction handle */
123 DBC *cursors[MAXCDB]; /* Cursors, for traversals... */
124 CtdlThreadNode *self; /* Pointer to this threads control structure */
127 extern double CtdlThreadLoadAvg;
128 extern double CtdlThreadWorkerAvg;
129 extern long statcount; /* are we doing a stats check? */
130 extern citthread_key_t ThreadKey;
132 void ctdl_thread_internal_init_tsd(void);
133 void ctdl_internal_thread_gc (void);
134 void ctdl_thread_internal_init(void);
135 void ctdl_thread_internal_cleanup(void);
136 void ctdl_thread_internal_calc_loadavg(void);
137 void ctdl_thread_internal_free_tsd(void);
138 CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thread_func) (void *arg), void *args);
139 void ctdl_thread_internal_check_scheduled(void);
140 void ctdl_thread_internal_change_state (CtdlThreadNode *this_thread, enum CtdlThreadState new_state);
142 void InitialiseSemaphores(void);
143 int try_critical_section (int which_one);
144 void begin_critical_section (int which_one);
145 void end_critical_section (int which_one);
146 void go_threading(void);