ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
sync.c File Reference

🔒 Synchronization primitive debugging with dynamic state inspection More...

Go to the source code of this file.

Data Structures

struct  sync_buffer_t
 
struct  debug_state_request_t
 

Macros

#define SYNC_BUFFER_SIZE   65536
 

Enumerations

enum  debug_request_type_t { DEBUG_REQUEST_STATE , DEBUG_REQUEST_BACKTRACE , DEBUG_REQUEST_MEMORY_REPORT }
 

Functions

void debug_sync_print_state (void)
 Print all synchronization primitive states at once.
 
void debug_sync_final_cleanup (void)
 Final cleanup of all debug allocations at shutdown.
 
void debug_sync_print_state_delayed (uint64_t delay_ns)
 Schedule delayed debug state printing on debug thread.
 
void debug_sync_print_backtrace_delayed (uint64_t delay_ns)
 Schedule delayed backtrace printing on debug thread.
 
void debug_sync_set_memory_report_interval (uint64_t interval_ns)
 Set periodic memory report interval.
 
void debug_sync_set_main_thread_id (void)
 Initialize debug synchronization system.
 
int debug_sync_init (void)
 
uint64_t debug_sync_get_main_thread_id (void)
 Get the main thread ID for memory reporting.
 
bool debug_sync_is_cleanup_in_progress (void)
 
int debug_sync_start_thread (void)
 Start background debug thread for scheduled operations.
 
void debug_sync_destroy (void)
 Destroy debug synchronization system.
 
void debug_sync_cleanup_thread (void)
 Stop and clean up background debug thread.
 
void debug_sync_trigger_print (void)
 Trigger sync state print immediately (synchronous)
 
void debug_sync_get_stats (uint64_t *total_acquired, uint64_t *total_released, uint32_t *currently_held)
 Get synchronization statistics.
 
int debug_sync_mutex_lock (mutex_t *mutex, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_mutex_trylock (mutex_t *mutex, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_mutex_unlock (mutex_t *mutex, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_rwlock_rdlock (rwlock_t *lock, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_rwlock_rdunlock (rwlock_t *lock, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_rwlock_wrlock (rwlock_t *lock, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_rwlock_wrunlock (rwlock_t *lock, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_cond_wait (cond_t *cond, mutex_t *mutex, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_cond_timedwait (cond_t *cond, mutex_t *mutex, uint64_t timeout_ns, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_cond_signal (cond_t *cond, const char *file_name, int line_number, const char *function_name)
 
int debug_sync_cond_broadcast (cond_t *cond, const char *file_name, int line_number, const char *function_name)
 
bool debug_sync_is_initialized (void)
 

Detailed Description

🔒 Synchronization primitive debugging with dynamic state inspection

Date
February 2026

Clean architecture: queries named.c registry for current state. No internal collection overhead - inspects lock structs directly.

Definition in file sync.c.

Macro Definition Documentation

◆ SYNC_BUFFER_SIZE

#define SYNC_BUFFER_SIZE   65536

Enumeration Type Documentation

◆ debug_request_type_t

Enumerator
DEBUG_REQUEST_STATE 
DEBUG_REQUEST_BACKTRACE 
DEBUG_REQUEST_MEMORY_REPORT 

Definition at line 435 of file sync.c.

435 {
436 DEBUG_REQUEST_STATE, // Print sync state
437 DEBUG_REQUEST_BACKTRACE, // Print backtrace
438 DEBUG_REQUEST_MEMORY_REPORT, // Print memory report
debug_request_type_t
Definition sync.c:435
@ DEBUG_REQUEST_STATE
Definition sync.c:436
@ DEBUG_REQUEST_MEMORY_REPORT
Definition sync.c:438
@ DEBUG_REQUEST_BACKTRACE
Definition sync.c:437

Function Documentation

◆ debug_sync_cond_broadcast()

int debug_sync_cond_broadcast ( cond_t *  cond,
const char *  file_name,
int  line_number,
const char *  function_name 
)

Definition at line 813 of file sync.c.

813 {
814 (void)file_name;
815 (void)line_number;
816 (void)function_name;
817 return cond_broadcast(cond);
818}
int cond_broadcast(cond_t *cond)
Broadcast to a condition variable (wake all waiting threads)

References cond_broadcast().

◆ debug_sync_cond_signal()

int debug_sync_cond_signal ( cond_t *  cond,
const char *  file_name,
int  line_number,
const char *  function_name 
)

Definition at line 806 of file sync.c.

806 {
807 (void)file_name;
808 (void)line_number;
809 (void)function_name;
810 return cond_signal(cond);
811}
int cond_signal(cond_t *cond)
Signal a condition variable (wake one waiting thread)

References cond_signal().

◆ debug_sync_init()

int debug_sync_init ( void  )

Definition at line 644 of file sync.c.

644 {
645 // debug_sync_set_main_thread_id() should have already been called
646 return 0;
647}

Referenced by main().

◆ debug_sync_is_cleanup_in_progress()

bool debug_sync_is_cleanup_in_progress ( void  )

Definition at line 653 of file sync.c.

653 {
654 return atomic_load_bool(&g_cleanup_in_progress);
655}
bool atomic_load_bool(atomic_t *a)
Atomically load a boolean value.
Definition atomic.c:169

References atomic_load_bool().

Referenced by debug_sync_check_cond_deadlocks().