11 #ifndef TOR_COMPAT_THREADS_H
12 #define TOR_COMPAT_THREADS_H
19 #if defined(HAVE_STDATOMIC_H) && defined(STDATOMIC_WORKS)
20 #define HAVE_WORKING_STDATOMIC
23 #ifdef HAVE_WORKING_STDATOMIC
24 #include <stdatomic.h>
29 int spawn_func(
void (*func)(
void *),
void *data);
36 #define tor_mutex_init_for_cond(m) tor_mutex_init_nonrecursive(m)
44 #elif defined(USE_WIN32_THREADS)
45 CONDITION_VARIABLE cond;
47 #error no known condition implementation.
53 #define tor_cond_free(c) FREE_AND_NULL(tor_cond_t, tor_cond_free_, (c))
100 #ifdef HAVE_WORKING_STDATOMIC
105 #define ATOMIC_LINKAGE static
112 #define ATOMIC_LINKAGE
122 #undef ATOMIC_LINKAGE
124 #ifdef HAVE_WORKING_STDATOMIC
129 atomic_init(&counter->val, 0);
151 (void) atomic_fetch_add(&counter->val, add);
157 (void) atomic_fetch_sub(&counter->val, sub);
163 return atomic_load(&counter->val);
169 return atomic_exchange(&counter->val, newval);
Header for compat_mutex.c.
Macros to implement mocking and selective exposure for the test code.
ATOMIC_LINKAGE void atomic_counter_add(atomic_counter_t *counter, size_t add)
void tor_cond_free_(tor_cond_t *cond)
ATOMIC_LINKAGE size_t atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
ATOMIC_LINKAGE void atomic_counter_init(atomic_counter_t *counter)
void tor_cond_signal_all(tor_cond_t *cond)
void * tor_threadlocal_get(tor_threadlocal_t *threadlocal)
void spawn_exit(void) ATTR_NORETURN
int tor_cond_init(tor_cond_t *cond)
int spawn_func(void(*func)(void *), void *data)
ATOMIC_LINKAGE void atomic_counter_sub(atomic_counter_t *counter, size_t sub)
ATOMIC_LINKAGE size_t atomic_counter_get(atomic_counter_t *counter)
void tor_threadlocal_destroy(tor_threadlocal_t *threadlocal)
void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value)
tor_cond_t * tor_cond_new(void)
void tor_threads_init(void)
void set_main_thread(void)
void tor_cond_uninit(tor_cond_t *cond)
void tor_cond_signal_one(tor_cond_t *cond)
int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex, const struct timeval *tv)
int tor_threadlocal_init(tor_threadlocal_t *threadlocal)
unsigned long tor_get_thread_id(void)
ATOMIC_LINKAGE void atomic_counter_destroy(atomic_counter_t *counter)
Integer definitions used throughout Tor.