Tor
0.4.7.0-alpha-dev
|
Cross-platform threading and inter-thread communication logic. (Platform-specific parts are written in the other compat_*threads modules.) More...
#include "orconfig.h"
#include <stdlib.h>
#include "lib/thread/threads.h"
#include "lib/thread/thread_sys.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/subsys/subsys.h"
#include <string.h>
Go to the source code of this file.
Functions | |
tor_cond_t * | tor_cond_new (void) |
void | tor_cond_free_ (tor_cond_t *c) |
void | set_main_thread (void) |
int | in_main_thread (void) |
void | atomic_counter_init (atomic_counter_t *counter) |
void | atomic_counter_destroy (atomic_counter_t *counter) |
void | atomic_counter_add (atomic_counter_t *counter, size_t add) |
void | atomic_counter_sub (atomic_counter_t *counter, size_t sub) |
size_t | atomic_counter_get (atomic_counter_t *counter) |
size_t | atomic_counter_exchange (atomic_counter_t *counter, size_t newval) |
static int | subsys_threads_initialize (void) |
Variables | |
static unsigned long | main_thread_id = -1 |
const subsys_fns_t | sys_threads |
Cross-platform threading and inter-thread communication logic. (Platform-specific parts are written in the other compat_*threads modules.)
Definition in file compat_threads.c.
void atomic_counter_add | ( | atomic_counter_t * | counter, |
size_t | add | ||
) |
Add a value to an atomic counter.
Definition at line 87 of file compat_threads.c.
Referenced by atomic_counter_sub().
void atomic_counter_destroy | ( | atomic_counter_t * | counter | ) |
Clean up all resources held by an atomic counter.
Destroying a locked mutex is undefined behaviour. Global mutexes may be locked when they are passed to this function, because multiple threads can still access them. So we can either:
Definition at line 80 of file compat_threads.c.
Referenced by cleanup_protocol_warning_severity_level().
size_t atomic_counter_exchange | ( | atomic_counter_t * | counter, |
size_t | newval | ||
) |
Replace the value of an atomic counter; return the old one.
Definition at line 112 of file compat_threads.c.
Referenced by set_protocol_warning_severity_level().
size_t atomic_counter_get | ( | atomic_counter_t * | counter | ) |
Return the current value of an atomic counter
Definition at line 102 of file compat_threads.c.
Referenced by get_protocol_warning_severity_level(), tor_compress_get_total_allocation(), tor_lzma_get_total_allocation(), tor_zlib_get_total_allocation(), and tor_zstd_get_total_allocation().
void atomic_counter_init | ( | atomic_counter_t * | counter | ) |
Initialize a new atomic counter with the value 0
Definition at line 65 of file compat_threads.c.
Referenced by init_protocol_warning_severity_level(), tor_compress_init(), tor_lzma_init(), and tor_zstd_init().
void atomic_counter_sub | ( | atomic_counter_t * | counter, |
size_t | sub | ||
) |
Subtract a value from an atomic counter.
Definition at line 95 of file compat_threads.c.
Referenced by tor_lzma_compress_free_(), tor_zlib_compress_free_(), and tor_zstd_compress_free_().
int in_main_thread | ( | void | ) |
Return true iff called from the main thread.
Definition at line 57 of file compat_threads.c.
Referenced by consensus_diff_queue_diff_work(), consensus_diff_worker_replyfn(), control_event_logmsg(), and control_event_logmsg_pending().
void set_main_thread | ( | void | ) |
Start considering the current thread to be the 'main thread'. This has no effect on anything besides in_main_thread().
Definition at line 51 of file compat_threads.c.
void tor_cond_free_ | ( | tor_cond_t * | c | ) |
Free all storage held in c.
Definition at line 37 of file compat_threads.c.
tor_cond_t* tor_cond_new | ( | void | ) |
Allocate and return a new condition variable.
Definition at line 27 of file compat_threads.c.
|
static |
Identity of the "main" thread
Definition at line 46 of file compat_threads.c.
Referenced by in_main_thread(), and set_main_thread().
const subsys_fns_t sys_threads |
Definition at line 130 of file compat_threads.c.