ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
rwlock.h
Go to the documentation of this file.
1#pragma once
2
31#include <stdbool.h>
32
33#ifdef _WIN32
34#include "windows_compat.h"
36typedef SRWLOCK rwlock_t;
37#else
38#include <pthread.h>
40typedef pthread_rwlock_t rwlock_t;
41#endif
42
43// Forward declarations for lock debugging
44// Note: Full lock_debug.h cannot be included here due to circular dependencies
45// Files that use both rwlock and lock_debug must include lock_debug.h separately
46#ifndef NDEBUG
47#ifdef __cplusplus
48extern "C" {
49#endif
50
52int debug_rwlock_rdlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name);
53int debug_rwlock_wrlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name);
54int debug_rwlock_rdunlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name);
55int debug_rwlock_wrunlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name);
56
57#ifdef __cplusplus
58}
59#endif
60#endif
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66// ============================================================================
67// Read-Write Lock Functions
68// ============================================================================
69
81
93
104
115
130
145
159
173
191#ifdef NDEBUG
192#define rwlock_rdlock(lock) rwlock_rdlock_impl(lock)
193#else
194#define rwlock_rdlock(lock) \
195 (lock_debug_is_initialized() ? debug_rwlock_rdlock(lock, __FILE__, __LINE__, __func__) : rwlock_rdlock_impl(lock))
196#endif
197
210#ifdef NDEBUG
211#define rwlock_wrlock(lock) rwlock_wrlock_impl(lock)
212#else
213#define rwlock_wrlock(lock) \
214 (lock_debug_is_initialized() ? debug_rwlock_wrlock(lock, __FILE__, __LINE__, __func__) : rwlock_wrlock_impl(lock))
215#endif
216
228#ifdef NDEBUG
229#define rwlock_rdunlock(lock) rwlock_rdunlock_impl(lock)
230#else
231#define rwlock_rdunlock(lock) \
232 (lock_debug_is_initialized() ? debug_rwlock_rdunlock(lock, __FILE__, __LINE__, __func__) : rwlock_rdunlock_impl(lock))
233#endif
234
246#ifdef NDEBUG
247#define rwlock_wrunlock(lock) rwlock_wrunlock_impl(lock)
248#else
249#define rwlock_wrunlock(lock) \
250 (lock_debug_is_initialized() ? debug_rwlock_wrunlock(lock, __FILE__, __LINE__, __func__) : rwlock_wrunlock_impl(lock))
251#endif
252
253#ifdef __cplusplus
254}
255#endif
256
int debug_rwlock_rdlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name)
int debug_rwlock_wrlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name)
int rwlock_rdunlock_impl(rwlock_t *lock)
Release a read lock (implementation function)
int rwlock_destroy(rwlock_t *lock)
Destroy a read-write lock.
int rwlock_rdlock_impl(rwlock_t *lock)
Acquire a read lock (implementation function)
int debug_rwlock_wrunlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name)
int rwlock_wrunlock_impl(rwlock_t *lock)
Release a write lock (implementation function)
int rwlock_wrlock_impl(rwlock_t *lock)
Acquire a write lock (implementation function)
int rwlock_destroy_impl(rwlock_t *lock)
Destroy a read-write lock (implementation function)
pthread_rwlock_t rwlock_t
Read-write lock type (POSIX: pthread_rwlock_t)
Definition rwlock.h:40
bool lock_debug_is_initialized(void)
int debug_rwlock_rdunlock(rwlock_t *rwlock, const char *file_name, int line_number, const char *function_name)
int rwlock_init_impl(rwlock_t *lock)
Initialize a read-write lock (implementation function)
int rwlock_init(rwlock_t *lock)
Initialize a read-write lock.
rwlock_t rwlock
Read-write lock for thread-safe access (uthash requires external locking)
Definition time.c:28
Wrapper for windows.h with C23 alignment compatibility.