OpenDNSSEC-signer
1.3.8
|
00001 /* 00002 * $Id: locks.h 4501 2011-02-21 09:02:16Z matthijs $ 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 "shared/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 ods_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(ods_thread_wait(cond, lock, sleep)) 00068 #define lock_basic_alarm(cond) LOCKRET(pthread_cond_signal(cond)) 00069 #define lock_basic_broadcast(cond) LOCKRET(pthread_cond_broadcast(cond)) 00070 #define lock_basic_off(cond) LOCKRET(pthread_cond_destroy(cond)) 00071 00072 int ods_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait); 00073 00075 typedef pthread_t ods_thread_type; 00077 #define ods_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg)) 00078 #define ods_thread_detach(thr) LOCKRET(pthread_detach(thr)) 00079 #define ods_thread_self() pthread_self() 00080 #define ods_thread_join(thr) LOCKRET(pthread_join(thr, NULL)) 00081 00082 int ods_thread_wait(cond_basic_type* cond, lock_basic_type* lock, time_t wait); 00083 void ods_thread_blocksigs(void); 00084 00085 #else /* !HAVE_PTHREAD */ 00086 00087 /* we do not have PTHREADS */ 00088 #define PTHREADS_DISABLED 1 00089 00090 typedef int lock_basic_type; 00091 #define lock_basic_init(lock) /* nop */ 00092 #define lock_basic_destroy(lock) /* nop */ 00093 #define lock_basic_lock(lock) /* nop */ 00094 #define lock_basic_unlock(lock) /* nop */ 00095 00096 #define lock_basic_set(cond) /* nop */ 00097 #define lock_basic_sleep(cond, lock, sleep) /* nop */ 00098 #define lock_basic_alarm(cond) /* nop */ 00099 #define lock_basic_broadcast(cond) /* nop */ 00100 #define lock_basic_off(cond) /* nop */ 00101 00102 typedef pid_t ods_thread_type; 00103 #define ods_thread_create(thr, func, arg) ods_thr_fork_create(thr, func, arg) 00104 #define ods_thread_detach(thr) /* nop */ 00105 #define ods_thread_self() getpid() 00106 #define ods_thread_join(thr) ods_thr_fork_wait(thr) 00107 00108 void ods_thr_fork_create(ods_thread_type* thr, void* (*func)(void*), void* arg); 00109 void ods_thr_fork_wait(ods_thread_type thread); 00110 00111 #endif /* HAVE_PTHREAD */ 00112 00113 void ods_thread_blocksigs(void); 00114 00115 #endif /* SHARED_LOCKS_H */