OpenDNSSEC-signer 1.2.1
|
00001 /* 00002 * $Id: locks.h 4294 2011-01-13 19:58:29Z jakob $ 00003 * 00004 * Copyright (c) 2009 NLNet Labs. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00034 #ifndef SCHEDULER_LOCKS_H 00035 #define SCHEDULER_LOCKS_H 00036 00037 #include "config.h" 00038 #include "util/log.h" 00039 00040 #include <errno.h> 00041 #include <stdlib.h> 00042 00043 #define LOCKRET(func) do { \ 00044 int err; \ 00045 if ( (err=(func)) != 0) \ 00046 se_log_error("%s at %d could not " #func ": %s", \ 00047 __FILE__, __LINE__, strerror(err)); \ 00048 } while(0) 00049 00050 #if defined(HAVE_PTHREAD) 00051 00052 #include <pthread.h> 00053 00055 typedef pthread_mutex_t lock_basic_type; 00057 typedef pthread_cond_t cond_basic_type; 00058 00060 #define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL)) 00061 #define lock_basic_destroy(lock) LOCKRET(pthread_mutex_destroy(lock)) 00062 #define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock)) 00063 #define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock)) 00064 00066 #define lock_basic_set(cond) LOCKRET(pthread_cond_init(cond, NULL)) 00067 #define lock_basic_sleep(cond, lock, sleep) LOCKRET(se_thread_wait(cond, lock, sleep)) 00068 #define lock_basic_alarm(cond) LOCKRET(pthread_cond_signal(cond)) 00069 #define lock_basic_off(cond) LOCKRET(pthread_cond_destroy(cond)) 00070 00071 int se_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait); 00072 00074 typedef pthread_t se_thread_type; 00076 #define se_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg)) 00077 #define se_thread_detach(thr) LOCKRET(pthread_detach(thr)) 00078 #define se_thread_self() pthread_self() 00079 #define se_thread_join(thr) LOCKRET(pthread_join(thr, NULL)) 00080 00081 int se_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait); 00082 void se_thread_blocksigs(void); 00083 00084 #else /* !HAVE_PTHREAD */ 00085 00086 /* we do not have PTHREADS */ 00087 #define PTHREADS_DISABLED 1 00088 00089 typedef int lock_basic_type; 00090 #define lock_basic_init(lock) /* nop */ 00091 #define lock_basic_destroy(lock) /* nop */ 00092 #define lock_basic_lock(lock) /* nop */ 00093 #define lock_basic_unlock(lock) /* nop */ 00094 00095 #define lock_basic_set(cond) /* nop */ 00096 #define lock_basic_sleep(cond, lock, sleep) /* nop */ 00097 #define lock_basic_alarm(cond) /* nop */ 00098 #define lock_basic_off(cond) /* nop */ 00099 00100 typedef pid_t se_thread_type; 00101 #define se_thread_create(thr, func, arg) se_thr_fork_create(thr, func, arg) 00102 #define se_thread_detach(thr) /* nop */ 00103 #define se_thread_self() getpid() 00104 #define se_thread_join(thr) se_thr_fork_wait(thr) 00105 00106 void se_thr_fork_create(se_thread_type* thr, void* (*func)(void*), void* arg); 00107 void se_thr_fork_wait(se_thread_type thread); 00108 00109 #endif /* HAVE_PTHREAD */ 00110 00111 void se_thread_blocksigs(void); 00112 00113 #endif /* SCHEDULER_LOCKS_H */