static inline int
cnd_broadcast(cnd_t *cond)
{
- if (!cond) return thrd_error;
- pthread_cond_broadcast(cond);
- return thrd_success;
+ assert(cond != NULL);
+ return (pthread_cond_broadcast(cond) == 0) ? thrd_success : thrd_error;
}
// 7.25.3.2
static inline int
cnd_init(cnd_t *cond)
{
- if (!cond) return thrd_error;
- pthread_cond_init(cond, NULL);
- return thrd_success;
+ assert(cond != NULL);
+ return (pthread_cond_init(cond, NULL) == 0) ? thrd_success : thrd_error;
}
// 7.25.3.4
static inline int
cnd_signal(cnd_t *cond)
{
- if (!cond) return thrd_error;
- pthread_cond_signal(cond);
- return thrd_success;
+ assert(cond != NULL);
+ return (pthread_cond_signal(cond) == 0) ? thrd_success : thrd_error;
}
// 7.25.3.5
{
struct timespec abs_time;
int rt;
- if (!cond || !mtx || !xt) return thrd_error;
+ assert(mtx != NULL);
+ assert(cond != NULL);
rt = pthread_cond_timedwait(cond, mtx, &abs_time);
if (rt == ETIMEDOUT)
return thrd_busy;
static inline int
cnd_wait(cnd_t *cond, mtx_t *mtx)
{
- if (!cond || !mtx) return thrd_error;
- pthread_cond_wait(cond, mtx);
- return thrd_success;
+ assert(mtx != NULL);
+ assert(cond != NULL);
+ return (pthread_cond_wait(cond, mtx) == 0) ? thrd_success : thrd_error;
}
static inline void
mtx_destroy(mtx_t *mtx)
{
- assert(mtx);
+ assert(mtx != NULL);
pthread_mutex_destroy(mtx);
}
mtx_init(mtx_t *mtx, int type)
{
pthread_mutexattr_t attr;
- if (!mtx) return thrd_error;
+ assert(mtx != NULL);
if (type != mtx_plain && type != mtx_timed && type != mtx_try
&& type != (mtx_plain|mtx_recursive)
&& type != (mtx_timed|mtx_recursive)
static inline int
mtx_lock(mtx_t *mtx)
{
- if (!mtx) return thrd_error;
- pthread_mutex_lock(mtx);
- return thrd_success;
+ assert(mtx != NULL);
+ return (pthread_mutex_lock(mtx) == 0) ? thrd_success : thrd_error;
}
static inline int
static inline int
mtx_timedlock(mtx_t *mtx, const xtime *xt)
{
- if (!mtx || !xt) return thrd_error;
+ assert(mtx != NULL);
+ assert(xt != NULL);
+
{
#ifdef EMULATED_THREADS_USE_NATIVE_TIMEDLOCK
struct timespec ts;
static inline int
mtx_trylock(mtx_t *mtx)
{
- if (!mtx) return thrd_error;
+ assert(mtx != NULL);
return (pthread_mutex_trylock(mtx) == 0) ? thrd_success : thrd_busy;
}
static inline int
mtx_unlock(mtx_t *mtx)
{
- if (!mtx) return thrd_error;
- pthread_mutex_unlock(mtx);
- return thrd_success;
+ assert(mtx != NULL);
+ return (pthread_mutex_unlock(mtx) == 0) ? thrd_success : thrd_error;
}
thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
{
struct impl_thrd_param *pack;
- if (!thr) return thrd_error;
+ assert(thr != NULL);
pack = (struct impl_thrd_param *)malloc(sizeof(struct impl_thrd_param));
if (!pack) return thrd_nomem;
pack->func = func;
static inline int
tss_create(tss_t *key, tss_dtor_t dtor)
{
- if (!key) return thrd_error;
+ assert(key != NULL);
return (pthread_key_create(key, dtor) == 0) ? thrd_success : thrd_error;
}