34 #ifndef SCHEDULER_LOCKS_H
35 #define SCHEDULER_LOCKS_H
43 #define LOCKRET(func) do { \
45 if ( (err=(func)) != 0) \
46 ods_log_error("%s at %d could not " #func ": %s", \
47 __FILE__, __LINE__, strerror(err)); \
50 #if defined(HAVE_PTHREAD)
57 typedef pthread_cond_t cond_basic_type;
60 #define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL))
61 #define lock_basic_destroy(lock) LOCKRET(pthread_mutex_destroy(lock))
62 #define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
63 #define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
66 #define lock_basic_set(cond) LOCKRET(pthread_cond_init(cond, NULL))
67 #define lock_basic_sleep(cond, lock, sleep) LOCKRET(ods_thread_wait(cond, lock, sleep))
68 #define lock_basic_alarm(cond) LOCKRET(pthread_cond_signal(cond))
69 #define lock_basic_broadcast(cond) LOCKRET(pthread_cond_broadcast(cond))
70 #define lock_basic_off(cond) LOCKRET(pthread_cond_destroy(cond))
72 int ods_thread_wait(cond_basic_type* cond,
lock_basic_type* lock, time_t wait);
77 #define ods_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg))
78 #define ods_thread_detach(thr) LOCKRET(pthread_detach(thr))
79 #define ods_thread_self() pthread_self()
80 #define ods_thread_join(thr) LOCKRET(pthread_join(thr, NULL))
81 #define ods_thread_kill(thr, sig) LOCKRET(pthread_kill(thr, sig))
82 int ods_thread_wait(cond_basic_type* cond,
lock_basic_type* lock, time_t wait);
88 #define PTHREADS_DISABLED 1
91 #define lock_basic_init(lock)
92 #define lock_basic_destroy(lock)
93 #define lock_basic_lock(lock)
94 #define lock_basic_unlock(lock)
96 #define lock_basic_set(cond)
97 #define lock_basic_sleep(cond, lock, sleep)
98 #define lock_basic_alarm(cond)
99 #define lock_basic_broadcast(cond)
100 #define lock_basic_off(cond)
103 #define ods_thread_create(thr, func, arg) ods_thr_fork_create(thr, func, arg)
104 #define ods_thread_detach(thr)
105 #define ods_thread_self() getpid()
106 #define ods_thread_join(thr) ods_thr_fork_wait(thr)