OpenDNSSEC-signer  1.3.16
locks.h
Go to the documentation of this file.
1 /*
2  * $Id: locks.h 7298 2013-09-11 11:26:35Z matthijs $
3  *
4  * Copyright (c) 2009 NLNet Labs. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
34 #ifndef SCHEDULER_LOCKS_H
35 #define SCHEDULER_LOCKS_H
36 
37 #include "config.h"
38 #include "shared/log.h"
39 
40 #include <errno.h>
41 #include <stdlib.h>
42 
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
82 
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
88 
89 #define LOCKED_ZL_ENGINE_UPDATEZONES 60
90 #define LOCKED_ZL_ENGINE_RECOVER 61
91 
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)
101 
102 
103 
104 #define LOCKRET(func) do { \
105  int err; \
106  if ( (err=(func)) != 0) \
107  ods_log_error("%s at %d could not " #func ": %s", \
108  __FILE__, __LINE__, strerror(err)); \
109  } while(0)
110 
111 #if defined(HAVE_PTHREAD)
112 
113 #include <pthread.h>
114 
116 typedef pthread_mutex_t lock_basic_type;
118 typedef pthread_cond_t cond_basic_type;
119 
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))
125 
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))
132 
133 int ods_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait);
134 
136 typedef pthread_t ods_thread_type;
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))
142 
143 int ods_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait);
144 void ods_thread_blocksigs(void);
145 
146 #else /* !HAVE_PTHREAD */
147 
148 /* we do not have PTHREADS */
149 #define PTHREADS_DISABLED 1
150 
151 typedef int lock_basic_type;
152 #define lock_basic_init(lock) /* nop */
153 #define lock_basic_destroy(lock) /* nop */
154 #define lock_basic_lock(lock) /* nop */
155 #define lock_basic_unlock(lock) /* nop */
156 
157 #define lock_basic_set(cond) /* nop */
158 #define lock_basic_sleep(cond, lock, sleep) /* nop */
159 #define lock_basic_alarm(cond) /* nop */
160 #define lock_basic_broadcast(cond) /* nop */
161 #define lock_basic_off(cond) /* nop */
162 
163 typedef pid_t ods_thread_type;
164 #define ods_thread_create(thr, func, arg) ods_thr_fork_create(thr, func, arg)
165 #define ods_thread_detach(thr) /* nop */
166 #define ods_thread_self() getpid()
167 #define ods_thread_join(thr) ods_thr_fork_wait(thr)
168 
169 void ods_thr_fork_create(ods_thread_type* thr, void* (*func)(void*), void* arg);
171 
172 #endif /* HAVE_PTHREAD */
173 
174 void ods_thread_blocksigs(void);
175 
176 #endif /* SHARED_LOCKS_H */
void ods_thread_blocksigs(void)
Definition: locks.c:150
void ods_thr_fork_create(ods_thread_type *thr, void *(*func)(void *), void *arg)
Definition: locks.c:65
pid_t ods_thread_type
Definition: locks.h:163
int lock_basic_type
Definition: locks.h:151
void ods_thr_fork_wait(ods_thread_type thread)
Definition: locks.c:90