Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00086
00087
00088 #define PTHREADS_DISABLED 1
00089
00090 typedef int lock_basic_type;
00091 #define lock_basic_init(lock)
00092 #define lock_basic_destroy(lock)
00093 #define lock_basic_lock(lock)
00094 #define lock_basic_unlock(lock)
00095
00096 #define lock_basic_set(cond)
00097 #define lock_basic_sleep(cond, lock, sleep)
00098 #define lock_basic_alarm(cond)
00099 #define lock_basic_broadcast(cond)
00100 #define lock_basic_off(cond)
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)
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
00112
00113 void ods_thread_blocksigs(void);
00114
00115 #endif