Rizin
unix-like reverse engineering framework and cli tools
thread_cond.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2020 thestr4ng3r <info@florianmaerkl.de>
2 // SPDX-FileCopyrightText: 2022 deroad <wargio@libero.it>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include "thread.h"
6 
15  if (!cond) {
16  return NULL;
17  }
18 #if HAVE_PTHREAD
19  if (pthread_cond_init(&cond->cond, NULL) != 0) {
20  free(cond);
21  return NULL;
22  }
23 #elif __WINDOWS__
24  InitializeConditionVariable(&cond->cond);
25 #endif
26  return cond;
27 }
28 
36 #if HAVE_PTHREAD
37  pthread_cond_signal(&cond->cond);
38 #elif __WINDOWS__
39  WakeConditionVariable(&cond->cond);
40 #endif
41 }
42 
50 #if HAVE_PTHREAD
51  pthread_cond_broadcast(&cond->cond);
52 #elif __WINDOWS__
53  WakeAllConditionVariable(&cond->cond);
54 #endif
55 }
56 
65 #if HAVE_PTHREAD
66  pthread_cond_wait(&cond->cond, &lock->lock);
67 #elif __WINDOWS__
68  SleepConditionVariableCS(&cond->cond, &lock->lock, INFINITE);
69 #endif
70 }
71 
78  if (!cond) {
79  return;
80  }
81 #if HAVE_PTHREAD
82  pthread_cond_destroy(&cond->cond);
83 #endif
84  free(cond);
85 }
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NONNULL
Definition: rz_types.h:64
#define cond(bop, top, mask, flags)
RZ_API void rz_th_cond_signal_all(RZ_NONNULL RzThreadCond *cond)
This function shall unblock all threads currently blocked on the specified condition.
Definition: thread_cond.c:48
RZ_API void rz_th_cond_free(RZ_NULLABLE RzThreadCond *cond)
Frees a RzThreadCond struct.
Definition: thread_cond.c:77
RZ_API void rz_th_cond_signal(RZ_NONNULL RzThreadCond *cond)
This function shall unblock at least one of the threads that are blocked on the specified condition.
Definition: thread_cond.c:34
RZ_API void rz_th_cond_wait(RZ_NONNULL RzThreadCond *cond, RZ_NONNULL RzThreadLock *lock)
The function shall block on a condition variable and shall be called with RzThreadLock locked by the ...
Definition: thread_cond.c:63
RZ_API RZ_OWN RzThreadCond * rz_th_cond_new(void)
Condition variables are intended to be used to communicate changes in the state of data shared betwee...
Definition: thread_cond.c:13
static void lock(volatile int *lk)
Definition: malloc.c:61