6 int cond_init_pshared(pthread_cond_t *cond)
8 pthread_condattr_t cattr;
11 ret = pthread_condattr_init(&cattr);
13 log_err("pthread_condattr_init: %s\n", strerror(ret));
18 ret = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
20 log_err("pthread_condattr_setpshared: %s\n", strerror(ret));
25 #ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
26 ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
28 log_err("pthread_condattr_setclock: %s\n", strerror(ret));
33 ret = pthread_cond_init(cond, &cattr);
35 log_err("pthread_cond_init: %s\n", strerror(ret));
43 * 'type' must be a mutex type, e.g. PTHREAD_MUTEX_NORMAL,
44 * PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_DEFAULT.
46 int mutex_init_pshared_with_type(pthread_mutex_t *mutex, int type)
48 pthread_mutexattr_t mattr;
51 ret = pthread_mutexattr_init(&mattr);
53 log_err("pthread_mutexattr_init: %s\n", strerror(ret));
58 * Not all platforms support process shared mutexes (NetBSD/OpenBSD)
61 ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
63 log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
67 ret = pthread_mutexattr_settype(&mattr, type);
69 log_err("pthread_mutexattr_settype: %s\n", strerror(ret));
72 ret = pthread_mutex_init(mutex, &mattr);
74 log_err("pthread_mutex_init: %s\n", strerror(ret));
77 pthread_mutexattr_destroy(&mattr);
82 int mutex_init_pshared(pthread_mutex_t *mutex)
84 return mutex_init_pshared_with_type(mutex, PTHREAD_MUTEX_DEFAULT);
87 int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond)
91 ret = mutex_init_pshared(mutex);
95 ret = cond_init_pshared(cond);