34 #ifndef SCHEDULER_LOCKS_H
35 #define SCHEDULER_LOCKS_H
43 #define LOCKED_SIGNAL_ENGINE_INIT 1
44 #define LOCKED_SIGNAL_ENGINE_RUN 2
45 #define LOCKED_SIGNAL_ENGINE_CAPTURE 3
46 #define LOCKED_SIGNAL_ENGINE_SLEEP 4
47 #define LOCKED_SCHEDULE_ENGINE_DELZONE 5
48 #define LOCKED_SCHEDULE_ENGINE_ADDZONE 6
49 #define LOCKED_SCHEDULE_ENGINE_RESCHEDULE 7
50 #define LOCKED_SCHEDULE_ENGINE_RECOVER 8
51 #define LOCKED_SIGNAL_SIGHUP 9
52 #define LOCKED_SIGNAL_SIGTERM 10
53 #define LOCKED_SIGNAL_CMD_RELOAD 11
54 #define LOCKED_SIGNAL_CMD_STOP 12
55 #define LOCKED_ZL_CMD_ZONES 13
56 #define LOCKED_ZL_CMD_UPDATE 14
57 #define LOCKED_ZL_CMD_UPDATE_ALL 15
58 #define LOCKED_ZL_CMD_SIGN 16
59 #define LOCKED_ZL_CMD_CLEAR 17
60 #define LOCKED_SCHEDULE_CMD_UPDATE 18
61 #define LOCKED_SCHEDULE_CMD_SIGN 19
62 #define LOCKED_SCHEDULE_CMD_SIGN_ALL 20
63 #define LOCKED_SCHEDULE_CMD_QUEUE 21
64 #define LOCKED_SCHEDULE_CMD_FLUSH 22
65 #define LOCKED_STATS_RRSET_SIGN 23
66 #define LOCKED_STATS_TOOLS_INPUT_START 24
67 #define LOCKED_STATS_TOOLS_INPUT_STOP 25
68 #define LOCKED_STATS_TOOLS_NSECIFY_START 26
69 #define LOCKED_STATS_TOOLS_NSECIFY_STOP 27
70 #define LOCKED_STATS_TOOLS_AUDIT_START 28
71 #define LOCKED_STATS_TOOLS_AUDIT_STOP 29
72 #define LOCKED_STATS_TOOLS_OUTPUT_START 30
73 #define LOCKED_STATS_TOOLS_OUTPUT_STOP 31
74 #define LOCKED_STATS_TOOLS_LOG 32
75 #define LOCKED_STATS_ZONE_RECOVER 33
76 #define LOCKED_ZONE_CMD_UPDATE 34
77 #define LOCKED_ZONE_CMD_SIGN 35
78 #define LOCKED_ZONE_CMD_CLEAR 36
79 #define LOCKED_ZONE_ENGINE_DELZONE 37
80 #define LOCKED_ZONE_ENGINE_ADDZONE 38
81 #define LOCKED_ZONE_ENGINE_UPDZONE 39
83 #define LOCKED_WORKER_INIT 50
84 #define LOCKED_WORKER_SIGN 51
85 #define LOCKED_WORKER_SLEEP 52
86 #define LOCKED_WORKER_SLEEP_UNLESS 53
87 #define LOCKED_WORKER_WAKEUP 54
89 #define LOCKED_ZL_ENGINE_UPDATEZONES 60
90 #define LOCKED_ZL_ENGINE_RECOVER 61
92 #define LOCKED_Q_WORKER(x) (300+x)
93 #define LOCKED_Q_DRUDGER(x) (400+x)
94 #define LOCKED_SCHEDULE_WORKER(x) (500+x)
95 #define LOCKED_WORKER_RRSET(x) (600+x)
96 #define LOCKED_WORKER_DRUDGER(x) (700+x)
97 #define LOCKED_ZONE_WORKER(x) (800+x)
98 #define LOCKED_STATS_WORKER(x) (900+x)
99 #define LOCKED_SLEEP_WORKER(x) (1000+x)
100 #define LOCKED_SLEEP_DRUDGER(x) (1100+x)
104 #define LOCKRET(func) do { \
106 if ( (err=(func)) != 0) \
107 ods_log_error("%s at %d could not " #func ": %s", \
108 __FILE__, __LINE__, strerror(err)); \
111 #if defined(HAVE_PTHREAD)
118 typedef pthread_cond_t cond_basic_type;
121 #define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL))
122 #define lock_basic_destroy(lock) LOCKRET(pthread_mutex_destroy(lock))
123 #define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
124 #define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
127 #define lock_basic_set(cond) LOCKRET(pthread_cond_init(cond, NULL))
128 #define lock_basic_sleep(cond, lock, sleep) LOCKRET(ods_thread_wait(cond, lock, sleep))
129 #define lock_basic_alarm(cond) LOCKRET(pthread_cond_signal(cond))
130 #define lock_basic_broadcast(cond) LOCKRET(pthread_cond_broadcast(cond))
131 #define lock_basic_off(cond) LOCKRET(pthread_cond_destroy(cond))
133 int ods_thread_wait(cond_basic_type* cond,
lock_basic_type* lock, time_t wait);
138 #define ods_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg))
139 #define ods_thread_detach(thr) LOCKRET(pthread_detach(thr))
140 #define ods_thread_self() pthread_self()
141 #define ods_thread_join(thr) LOCKRET(pthread_join(thr, NULL))
143 int ods_thread_wait(cond_basic_type* cond,
lock_basic_type* lock, time_t wait);
149 #define PTHREADS_DISABLED 1
152 #define lock_basic_init(lock)
153 #define lock_basic_destroy(lock)
154 #define lock_basic_lock(lock)
155 #define lock_basic_unlock(lock)
157 #define lock_basic_set(cond)
158 #define lock_basic_sleep(cond, lock, sleep)
159 #define lock_basic_alarm(cond)
160 #define lock_basic_broadcast(cond)
161 #define lock_basic_off(cond)
164 #define ods_thread_create(thr, func, arg) ods_thr_fork_create(thr, func, arg)
165 #define ods_thread_detach(thr)
166 #define ods_thread_self() getpid()
167 #define ods_thread_join(thr) ods_thr_fork_wait(thr)
void ods_thread_blocksigs(void)
void ods_thr_fork_create(ods_thread_type *thr, void *(*func)(void *), void *arg)
void ods_thr_fork_wait(ods_thread_type thread)