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"
30 enum CtdlThreadState {
34 CTDL_THREAD_CANCELLED,
37 CTDL_THREAD_STOP_REQ, /* Do NOT put any running states before this state */
41 CTDL_THREAD_LAST_STATE
43 typedef struct CtdlThreadNode CtdlThreadNode;
45 struct CtdlThreadNode{
46 citthread_t tid; /* id as returned by citthread_create() */
47 pid_t pid; /* pid, as best the OS will let us determine */
48 time_t when; /* When to start a scheduled thread */
49 struct CitContext *Context; /* The session context that this thread mught be working on or NULL if none */
50 long number; /* A unigue number for this thread (not implimented yet) */
51 int wakefd_recv; /* An fd that this thread can sleep on (not implimented yet) */
52 int wakefd_send; /* An fd that this thread can send out on (Not implimented yet) */
53 int signal; /* A field to store a signal we caught. */
54 const char *name; /* A name for this thread */
55 void *(*thread_func) (void *arg); /* The actual function that does this threads work */
56 void *user_args; /* Arguments passed to this threads work function */
57 long flags; /* Flags that describe this thread */
58 enum CtdlThreadState state; /* Flag to show state of this thread */
59 int stop_ticker; /* A counter to determine how long it has taken for this thread to exit */
60 citthread_mutex_t ThreadMutex; /* A mutex to sync this thread to others if this thread allows (also used for sleeping) */
61 citthread_cond_t ThreadCond; /* A condition variable to sync this thread with others */
62 citthread_mutex_t SleepMutex; /* A mutex for sleeping */
63 citthread_cond_t SleepCond; /* A condition variable for sleeping */
64 citthread_attr_t attr; /* Attributes of this thread */
65 struct timeval start_time; /* Time this thread was started */
66 struct timeval last_state_change; /* Time when this thread last changed state */
67 double avg_sleeping; /* Average sleeping time */
68 double avg_running; /* Average running time */
69 double avg_blocked; /* Average blocked time */
70 double load_avg; /* Load average for this thread */
71 CtdlThreadNode *prev; /* Previous thread in the thread table */
72 CtdlThreadNode *next; /* Next thread in the thread table */
75 extern CtdlThreadNode *CtdlThreadList;
77 typedef struct ThreadTSD ThreadTSD;
80 DB_TXN *tid; /* Transaction handle */
81 DBC *cursors[MAXCDB]; /* Cursors, for traversals... */
82 CtdlThreadNode *self; /* Pointer to this threads control structure */
85 extern double CtdlThreadLoadAvg;
86 extern double CtdlThreadWorkerAvg;
87 extern citthread_key_t ThreadKey;
89 void ctdl_thread_internal_init_tsd(void);
90 void ctdl_internal_thread_gc (void);
91 void ctdl_thread_internal_init(void);
92 void ctdl_thread_internal_cleanup(void);
93 void ctdl_thread_internal_calc_loadavg(void);
94 void ctdl_thread_internal_free_tsd(void);
95 CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thread_func) (void *arg), void *args);
96 void ctdl_thread_internal_check_scheduled(void);
98 void InitialiseSemaphores(void);
99 int try_critical_section (int which_one);
100 void begin_critical_section (int which_one);
101 void end_critical_section (int which_one);
102 void go_threading(void);