tor  0.4.2.0-alpha-dev
Functions | Variables
compat_threads.c File Reference
#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_ttor_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
 

Detailed Description

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.

Function Documentation

◆ atomic_counter_add()

void atomic_counter_add ( atomic_counter_t counter,
size_t  add 
)

Add a value to an atomic counter.

Definition at line 79 of file compat_threads.c.

References tor_mutex_acquire(), and tor_mutex_release().

Referenced by atomic_counter_sub().

◆ atomic_counter_destroy()

void atomic_counter_destroy ( atomic_counter_t counter)

Clean up all resources held by an atomic counter.

Definition at line 72 of file compat_threads.c.

References tor_mutex_uninit().

Referenced by cleanup_protocol_warning_severity_level().

◆ atomic_counter_exchange()

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 104 of file compat_threads.c.

References tor_mutex_acquire(), and tor_mutex_release().

Referenced by set_protocol_warning_severity_level().

◆ atomic_counter_get()

size_t atomic_counter_get ( atomic_counter_t counter)

◆ atomic_counter_init()

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.

References tor_mutex_init_nonrecursive().

Referenced by init_protocol_warning_severity_level(), tor_compress_init(), tor_lzma_init(), tor_zlib_init(), and tor_zstd_init().

◆ atomic_counter_sub()

void atomic_counter_sub ( atomic_counter_t counter,
size_t  sub 
)

Subtract a value from an atomic counter.

Definition at line 87 of file compat_threads.c.

References atomic_counter_add().

Referenced by tor_lzma_compress_free_(), tor_zlib_compress_free_(), and tor_zstd_compress_free_().

◆ in_main_thread()

int in_main_thread ( void  )

Return true iff called from the main thread.

Definition at line 57 of file compat_threads.c.

References main_thread_id, and tor_get_thread_id().

Referenced by control_event_logmsg(), and control_event_logmsg_pending().

◆ set_main_thread()

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.

References main_thread_id, and tor_get_thread_id().

◆ tor_cond_free_()

void tor_cond_free_ ( tor_cond_t c)

Free all storage held in c.

Definition at line 37 of file compat_threads.c.

References tor_cond_uninit(), and tor_free.

◆ tor_cond_new()

tor_cond_t* tor_cond_new ( void  )

Allocate and return a new condition variable.

Definition at line 27 of file compat_threads.c.

Variable Documentation

◆ main_thread_id

unsigned long main_thread_id = -1
static

Identity of the "main" thread

Definition at line 46 of file compat_threads.c.

Referenced by in_main_thread(), and set_main_thread().

◆ sys_threads

const subsys_fns_t sys_threads
Initial value:
= {
.name = "threads",
.supported = true,
.level = -95,
.initialize = subsys_threads_initialize,
}

Definition at line 122 of file compat_threads.c.