Rizin
unix-like reverse engineering framework and cli tools
thread_types.c File Reference
#include <rz_th.h>
#include <rz_util.h>

Go to the source code of this file.

Classes

struct  rz_atomic_bool_t
 

Functions

RZ_API RZ_OWN RzAtomicBoolrz_atomic_bool_new (bool value)
 Initialize a thread safe bool type container. More...
 
RZ_API void rz_atomic_bool_free (RZ_NULLABLE RzAtomicBool *tbool)
 Frees a RzAtomicBool structure. More...
 
RZ_API bool rz_atomic_bool_get (RZ_NONNULL RzAtomicBool *tbool)
 Gets the current value hold by the RzAtomicBool structure. More...
 
RZ_API void rz_atomic_bool_set (RZ_NONNULL RzAtomicBool *tbool, bool value)
 Sets the value int the RzAtomicBool structure. More...
 

Detailed Description

The native types should actually be real atomic types but these should be falling back in similar structs in case of insupported atomic types.

Definition in file thread_types.c.

Function Documentation

◆ rz_atomic_bool_free()

RZ_API void rz_atomic_bool_free ( RZ_NULLABLE RzAtomicBool tbool)

Frees a RzAtomicBool structure.

Parameters
tboolThe RzAtomicBool structure to free

Definition at line 39 of file thread_types.c.

39  {
40  if (!tbool) {
41  return;
42  }
43  rz_th_lock_free(tbool->lock);
44  free(tbool);
45 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_th_lock_free(RZ_NULLABLE RzThreadLock *thl)
Frees a RzThreadLock structure.
Definition: thread_lock.c:89

References free(), and rz_th_lock_free().

Referenced by bin_file_string_search_free(), and rz_basefind().

◆ rz_atomic_bool_get()

RZ_API bool rz_atomic_bool_get ( RZ_NONNULL RzAtomicBool tbool)

Gets the current value hold by the RzAtomicBool structure.

Parameters
[in]tboolThe RzAtomicBool to safely access
Returns
Returns a copy of the stored value

Definition at line 54 of file thread_types.c.

54  {
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 }
static int value
Definition: cmd_api.c:93
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
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_enter(RZ_NONNULL RzThreadLock *thl)
Acquires a RzThreadLock structure.
Definition: thread_lock.c:45

References rz_return_val_if_fail, rz_th_lock_enter(), rz_th_lock_leave(), and value.

Referenced by basefind_thread_runner(), basefind_thread_ui(), rz_core_rtr_rap_thread(), and search_string_thread_runner().

◆ rz_atomic_bool_new()

RZ_API RZ_OWN RzAtomicBool* rz_atomic_bool_new ( bool  value)

Initialize a thread safe bool type container.

Parameters
[in]valueThe initial value status
Returns
On success returns a valid pointer, otherwise NULL

Definition at line 24 of file thread_types.c.

24  {
26  if (!tbool) {
27  return NULL;
28  }
29  tbool->lock = rz_th_lock_new(false);
30  tbool->value = true;
31  return tbool;
32 }
#define NULL
Definition: cris-opc.c:27
#define RZ_NEW0(x)
Definition: rz_types.h:284
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 RZ_OWN RzThreadLock * rz_th_lock_new(bool recursive)
Allocates and initialize a RzThreadLock structure.
Definition: thread_lock.c:14

References rz_atomic_bool_t::lock, NULL, RZ_NEW0, rz_th_lock_new(), and rz_atomic_bool_t::value.

Referenced by create_string_search_thread(), rz_basefind(), and rz_core_rtr_cmd().

◆ rz_atomic_bool_set()

RZ_API void rz_atomic_bool_set ( RZ_NONNULL RzAtomicBool tbool,
bool  value 
)

Sets the value int the RzAtomicBool structure.

Parameters
tboolThe RzAtomicBool to safely modify
[in]valueThe new value to set

Definition at line 68 of file thread_types.c.

68  {
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 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References rz_return_if_fail, rz_th_lock_enter(), rz_th_lock_leave(), and value.

Referenced by basefind_stop_all_search_threads(), interrupt_thread(), rz_basefind(), and rz_core_wait().