ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
debug/mutex.h
Go to the documentation of this file.
1#pragma once
2
12#include <stdint.h>
13#include <stdbool.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
22typedef enum {
23 MUTEX_STACK_STATE_PENDING, // Attempting to acquire lock
24 MUTEX_STACK_STATE_LOCKED, // Lock successfully acquired
26
30typedef struct {
31 uintptr_t mutex_key; // Pointer to mutex_t (used as unique ID)
32 const char *mutex_name; // Human-readable mutex name
33 mutex_stack_state_t state; // PENDING or LOCKED
34 uint64_t timestamp_ns; // When this lock was attempted/acquired
36
42void mutex_stack_push_pending(uintptr_t mutex_key, const char *mutex_name);
43
49void mutex_stack_mark_locked(uintptr_t mutex_key);
50
55void mutex_stack_pop(uintptr_t mutex_key);
56
63int mutex_stack_get_current(mutex_stack_entry_t *out_entries, int max_entries);
64
75int mutex_stack_get_all_threads(mutex_stack_entry_t ***out_stacks, int **out_stack_counts, int *out_thread_count);
76
80void mutex_stack_free_all_threads(mutex_stack_entry_t **stacks, int *stack_counts, int thread_count);
81
93
98int mutex_stack_init(void);
99
103void mutex_stack_cleanup(void);
104
111
112#ifdef __cplusplus
113}
114#endif
115
mutex_stack_state_t
Definition debug/mutex.h:22
@ MUTEX_STACK_STATE_LOCKED
Definition debug/mutex.h:24
@ MUTEX_STACK_STATE_PENDING
Definition debug/mutex.h:23
void mutex_stack_cleanup_current_thread(void)
Cleanup TLS stack for current thread Explicitly frees the thread-local mutex stack....
int mutex_stack_get_all_threads(mutex_stack_entry_t ***out_stacks, int **out_stack_counts, int *out_thread_count)
Get all threads' lock stacks for deadlock analysis.
void mutex_stack_free_all_threads(mutex_stack_entry_t **stacks, int *stack_counts, int thread_count)
Free memory allocated by mutex_stack_get_all_threads()
void mutex_stack_cleanup(void)
Cleanup mutex stack system.
int mutex_stack_get_current(mutex_stack_entry_t *out_entries, int max_entries)
Get the current thread's lock stack.
void mutex_stack_pop(uintptr_t mutex_key)
Pop the top mutex from the current thread's lock stack (unlock)
void mutex_stack_push_pending(uintptr_t mutex_key, const char *mutex_name)
Push a mutex onto the current thread's lock stack (PENDING state)
void mutex_stack_mark_locked(uintptr_t mutex_key)
Mark the top of the current thread's lock stack as LOCKED (transitions PENDING -> LOCKED)
int mutex_stack_init(void)
Initialize mutex stack system.
void mutex_stack_detect_deadlocks(void)
Detect and log circular wait deadlocks.
unsigned long long uint64_t
Definition common.h:59
ClangTool/LibTooling compatibility shim for stdbool.h.
Definition debug/mutex.h:30
const char * mutex_name
Definition debug/mutex.h:32
mutex_stack_state_t state
Definition debug/mutex.h:33
uint64_t timestamp_ns
Definition debug/mutex.h:34
uintptr_t mutex_key
Definition debug/mutex.h:31