Rizin
unix-like reverse engineering framework and cli tools
thread_types.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021-2022 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_th.h>
5 #include <rz_util.h>
6 
13  bool value;
15 };
16 
26  if (!tbool) {
27  return NULL;
28  }
29  tbool->lock = rz_th_lock_new(false);
30  tbool->value = true;
31  return tbool;
32 }
33 
40  if (!tbool) {
41  return;
42  }
43  rz_th_lock_free(tbool->lock);
44  free(tbool);
45 }
46 
55  rz_return_val_if_fail(tbool, false);
56  rz_th_lock_enter(tbool->lock);
57  bool value = tbool->value;
58  rz_th_lock_leave(tbool->lock);
59  return value;
60 }
61 
69  rz_return_if_fail(tbool);
70  rz_th_lock_enter(tbool->lock);
71  tbool->value = value;
72  rz_th_lock_leave(tbool->lock);
73 }
static int value
Definition: cmd_api.c:93
#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_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#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
bool value
The value to get/set safely.
Definition: thread_types.c:13
RzThreadLock * lock
The lock related to the single value.
Definition: thread_types.c:14
RZ_API void rz_th_lock_leave(RZ_NONNULL RzThreadLock *thl)
Releases a RzThreadLock structure.
Definition: thread_lock.c:75
RZ_API void rz_th_lock_free(RZ_NULLABLE RzThreadLock *thl)
Frees a RzThreadLock structure.
Definition: thread_lock.c:89
RZ_API RZ_OWN RzThreadLock * rz_th_lock_new(bool recursive)
Allocates and initialize a RzThreadLock structure.
Definition: thread_lock.c:14
RZ_API void rz_th_lock_enter(RZ_NONNULL RzThreadLock *thl)
Acquires a RzThreadLock structure.
Definition: thread_lock.c:45
RZ_API RZ_OWN RzAtomicBool * rz_atomic_bool_new(bool value)
Initialize a thread safe bool type container.
Definition: thread_types.c:24
RZ_API bool rz_atomic_bool_get(RZ_NONNULL RzAtomicBool *tbool)
Gets the current value hold by the RzAtomicBool structure.
Definition: thread_types.c:54
RZ_API void rz_atomic_bool_free(RZ_NULLABLE RzAtomicBool *tbool)
Frees a RzAtomicBool structure.
Definition: thread_types.c:39
RZ_API void rz_atomic_bool_set(RZ_NONNULL RzAtomicBool *tbool, bool value)
Sets the value int the RzAtomicBool structure.
Definition: thread_types.c:68