ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
platform/thread.h
Go to the documentation of this file.
1#pragma once
2
26#include <stdbool.h>
27#include <stdint.h>
28
29// Type definitions MUST come before including common.h to avoid circular dependencies.
30// common.h → abstraction.h → debug/lock.h → thread.h, and lock.h needs asciichat_thread_t.
31#ifdef _WIN32
32#include "windows_compat.h"
34typedef HANDLE asciichat_thread_t;
36typedef DWORD thread_id_t;
38typedef DWORD tls_key_t;
39#else
40#include <pthread.h>
42typedef pthread_t asciichat_thread_t;
44typedef pthread_t thread_id_t;
46typedef pthread_key_t tls_key_t;
47#endif
48
49#include "../common.h" // For asciichat_error_t (must come AFTER type definitions)
50
51// ============================================================================
52// Thread Functions
53// ============================================================================
54
67int asciichat_thread_create(asciichat_thread_t *thread, void *(*func)(void *), void *arg);
68
79int asciichat_thread_join(asciichat_thread_t *thread, void **retval);
80
93int asciichat_thread_join_timeout(asciichat_thread_t *thread, void **retval, uint32_t timeout_ms);
94
104void asciichat_thread_exit(void *retval);
105
115
125
136
145
156
176
197asciichat_error_t thread_create_or_fail(asciichat_thread_t *thread, void *(*func)(void *), void *arg,
198 const char *thread_name, uint32_t client_id);
199
200// ============================================================================
201// Thread-Local Storage (TLS) Functions
202// ============================================================================
203
216int ascii_tls_key_create(tls_key_t *key, void (*destructor)(void *));
217
229
241
252int ascii_tls_set(tls_key_t key, void *value);
253
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:46
int ascii_tls_key_create(tls_key_t *key, void(*destructor)(void *))
Create a thread-local storage key.
int ascii_tls_set(tls_key_t key, void *value)
Set thread-local value for a key.
thread_id_t asciichat_thread_self(void)
Get the current thread's ID.
int asciichat_thread_equal(thread_id_t t1, thread_id_t t2)
Compare two thread IDs for equality.
void asciichat_thread_exit(void *retval)
Exit the current thread.
asciichat_error_t asciichat_thread_set_realtime_priority(void)
Set the current thread to real-time priority.
asciichat_error_t thread_create_or_fail(asciichat_thread_t *thread, void *(*func)(void *), void *arg, const char *thread_name, uint32_t client_id)
Create a thread with standardized error handling and logging.
Definition thread.c:14
pthread_key_t tls_key_t
Thread-local storage key type (POSIX: pthread_key_t)
void asciichat_thread_init(asciichat_thread_t *thread)
Initialize a thread handle to an uninitialized state.
bool asciichat_thread_is_initialized(asciichat_thread_t *thread)
Check if a thread handle has been initialized.
int asciichat_thread_join(asciichat_thread_t *thread, void **retval)
Wait for a thread to complete (blocking)
void * ascii_tls_get(tls_key_t key)
Get thread-local value for a key.
int ascii_tls_key_delete(tls_key_t key)
Delete a thread-local storage key.
int asciichat_thread_join_timeout(asciichat_thread_t *thread, void **retval, uint32_t timeout_ms)
Wait for a thread to complete with timeout.
pthread_t thread_id_t
Thread ID type (POSIX: pthread_t)
pthread_t asciichat_thread_t
Thread handle type (POSIX: pthread_t)
int asciichat_thread_create(asciichat_thread_t *thread, void *(*func)(void *), void *arg)
Create a new thread.
uint64_t asciichat_thread_current_id(void)
Get the current thread's unique numeric ID.
Wrapper for windows.h with C23 alignment compatibility.