|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🧵 Thread lifecycle management helpers More...
Go to the source code of this file.
Macros | |
| #define | THREAD_IS_CREATED(created_flag) ((created_flag) == true) |
| #define | THREAD_CREATE_SAFE(thread_var, func, arg) asciichat_thread_create(&(thread_var), (func), (arg)) |
| #define | THREAD_CREATE_OR_RETURN_VOID(thread_var, func, arg, error_msg) |
| #define | THREAD_JOIN_SAFE(thread_var, exit_code) asciichat_thread_join(&(thread_var), (exit_code)) |
| #define | THREAD_JOIN(thread_var) asciichat_thread_join(&(thread_var), NULL) |
| #define | THREAD_CLEAR_HANDLE(thread_var) memset(&(thread_var), 0, sizeof(thread_var)) |
🧵 Thread lifecycle management helpers
Provides macros and utilities for managing thread creation, initialization, and cleanup patterns. Reduces code duplication in modules that manage dedicated worker threads.
Common Pattern: Many modules in ascii-chat create dedicated threads with a similar lifecycle:
Usage:
Definition in file util/thread.h.
| #define THREAD_CLEAR_HANDLE | ( | thread_var | ) | memset(&(thread_var), 0, sizeof(thread_var)) |
Initialize a thread handle to an invalid/uninitialized state. Call this before creating the thread to ensure clean state.
| thread_var | Thread handle (asciichat_thread_t) |
Usage:
Definition at line 145 of file util/thread.h.
| #define THREAD_CREATE_OR_RETURN_VOID | ( | thread_var, | |
| func, | |||
| arg, | |||
| error_msg | |||
| ) |
Create a thread with automatic error handling and logging (void return version).
| thread_var | Thread handle (asciichat_thread_t) |
| func | Thread function pointer |
| arg | Thread argument |
| error_msg | Message to log on failure |
On failure, logs an error and the macro exits the enclosing function with return. Useful for mandatory thread creation where failure is fatal.
Note: Use THREAD_CREATE_OR_RETURN from common.h for int-returning functions. This version is for void-returning functions with custom error messages.
Usage:
Definition at line 97 of file util/thread.h.
| #define THREAD_CREATE_SAFE | ( | thread_var, | |
| func, | |||
| arg | |||
| ) | asciichat_thread_create(&(thread_var), (func), (arg)) |
Safely create a thread with error handling and logging. Does NOT set the created flag - caller must do that.
| thread_var | Thread handle (asciichat_thread_t) |
| func | Thread function pointer (void *(*)(void *)) |
| arg | Thread argument (void *) |
This is a direct call to asciichat_thread_create with no error handling. Caller should check return value and log if needed.
Definition at line 76 of file util/thread.h.
| #define THREAD_IS_CREATED | ( | created_flag | ) | ((created_flag) == true) |
Check if a thread has been created.
| created_flag | Boolean flag indicating thread creation status |
Definition at line 62 of file util/thread.h.
| #define THREAD_JOIN | ( | thread_var | ) | asciichat_thread_join(&(thread_var), NULL) |
Join a thread without capturing its exit code. Simpler version when exit code is not needed.
| thread_var | Thread handle (asciichat_thread_t) |
Usage:
Definition at line 132 of file util/thread.h.
| #define THREAD_JOIN_SAFE | ( | thread_var, | |
| exit_code | |||
| ) | asciichat_thread_join(&(thread_var), (exit_code)) |
Join a thread and wait for it to complete. Returns the thread's exit code in the output parameter.
| thread_var | Thread handle (asciichat_thread_t) |
| exit_code | Pointer to store thread exit code (void **), or NULL to ignore |
Usage:
Definition at line 119 of file util/thread.h.