ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
atomic.h
Go to the documentation of this file.
1
33#pragma once
34
35// C11 stdatomic.h conflicts with MSVC's C++ <atomic> header on Windows.
36// When compiling C++ with MSVC runtime headers (even with Clang), we must not
37// include stdatomic.h as the MSVC <atomic> header already provides the same
38// functionality and the declarations conflict.
39#if defined(__cplusplus) && defined(_WIN32)
40#include <atomic>
41#else
42#include <stdatomic.h>
43#endif
44#include <stdbool.h>
45#include <stdint.h>
46
64#define SHOULD_EXIT() (atomic_load(&g_server_should_exit))
65
81#define CLIENT_SHOULD_EXIT() (atomic_load(&g_should_exit))
82
94#define ATOMIC_LOAD_BOOL(ptr) atomic_load((atomic_bool *)(ptr))
95
107#define ATOMIC_LOAD_UINT32(ptr) atomic_load((atomic_uint32_t *)(ptr))
108
120#define ATOMIC_LOAD_UINT64(ptr) atomic_load((atomic_uint64_t *)(ptr))
121
133#define ATOMIC_STORE_BOOL(ptr, value) atomic_store((atomic_bool *)(ptr), (value))
134
146#define ATOMIC_STORE_UINT32(ptr, value) atomic_store((atomic_uint32_t *)(ptr), (value))
147
159#define ATOMIC_STORE_UINT64(ptr, value) atomic_store((atomic_uint64_t *)(ptr), (value))
160
181#define ATOMIC_CAS_BOOL(ptr, expected, new_value) \
182 atomic_compare_exchange_strong((atomic_bool *)(ptr), &(expected), (new_value))
183
200#define ATOMIC_CAS_UINT32(ptr, expected, new_value) \
201 atomic_compare_exchange_strong((atomic_uint32_t *)(ptr), (expected), (new_value))
202
216#define ATOMIC_ADD_UINT32(ptr, delta) atomic_fetch_add((atomic_uint32_t *)(ptr), (delta))
217
231#define ATOMIC_SUB_UINT32(ptr, delta) atomic_fetch_sub((atomic_uint32_t *)(ptr), (delta))
232
233#endif