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
"
34
typedef
HANDLE
asciichat_thread_t
;
36
typedef
DWORD
thread_id_t
;
38
typedef
DWORD
tls_key_t
;
39
#else
40
#include <pthread.h>
42
typedef
pthread_t
asciichat_thread_t
;
44
typedef
pthread_t
thread_id_t
;
46
typedef
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
67
int
asciichat_thread_create
(
asciichat_thread_t
*thread,
void
*(*func)(
void
*),
void
*arg);
68
79
int
asciichat_thread_join
(
asciichat_thread_t
*thread,
void
**retval);
80
93
int
asciichat_thread_join_timeout
(
asciichat_thread_t
*thread,
void
**retval,
uint32_t
timeout_ms);
94
104
void
asciichat_thread_exit
(
void
*retval);
105
114
thread_id_t
asciichat_thread_self
(
void
);
115
124
int
asciichat_thread_equal
(
thread_id_t
t1,
thread_id_t
t2);
125
135
uint64_t
asciichat_thread_current_id
(
void
);
136
144
bool
asciichat_thread_is_initialized
(
asciichat_thread_t
*thread);
145
155
void
asciichat_thread_init
(
asciichat_thread_t
*thread);
156
175
asciichat_error_t
asciichat_thread_set_realtime_priority
(
void
);
176
197
asciichat_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
216
int
ascii_tls_key_create
(
tls_key_t
*key,
void
(*destructor)(
void
*));
217
228
int
ascii_tls_key_delete
(
tls_key_t
key);
229
240
void
*
ascii_tls_get
(
tls_key_t
key);
241
252
int
ascii_tls_set
(
tls_key_t
key,
void
*value);
253
uint32_t
unsigned int uint32_t
Definition
common.h:58
uint64_t
unsigned long long uint64_t
Definition
common.h:59
asciichat_error_t
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition
error_codes.h:46
ascii_tls_key_create
int ascii_tls_key_create(tls_key_t *key, void(*destructor)(void *))
Create a thread-local storage key.
ascii_tls_set
int ascii_tls_set(tls_key_t key, void *value)
Set thread-local value for a key.
asciichat_thread_self
thread_id_t asciichat_thread_self(void)
Get the current thread's ID.
asciichat_thread_equal
int asciichat_thread_equal(thread_id_t t1, thread_id_t t2)
Compare two thread IDs for equality.
asciichat_thread_exit
void asciichat_thread_exit(void *retval)
Exit the current thread.
asciichat_thread_set_realtime_priority
asciichat_error_t asciichat_thread_set_realtime_priority(void)
Set the current thread to real-time priority.
thread_create_or_fail
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
tls_key_t
pthread_key_t tls_key_t
Thread-local storage key type (POSIX: pthread_key_t)
Definition
platform/thread.h:46
asciichat_thread_init
void asciichat_thread_init(asciichat_thread_t *thread)
Initialize a thread handle to an uninitialized state.
asciichat_thread_is_initialized
bool asciichat_thread_is_initialized(asciichat_thread_t *thread)
Check if a thread handle has been initialized.
asciichat_thread_join
int asciichat_thread_join(asciichat_thread_t *thread, void **retval)
Wait for a thread to complete (blocking)
ascii_tls_get
void * ascii_tls_get(tls_key_t key)
Get thread-local value for a key.
ascii_tls_key_delete
int ascii_tls_key_delete(tls_key_t key)
Delete a thread-local storage key.
asciichat_thread_join_timeout
int asciichat_thread_join_timeout(asciichat_thread_t *thread, void **retval, uint32_t timeout_ms)
Wait for a thread to complete with timeout.
thread_id_t
pthread_t thread_id_t
Thread ID type (POSIX: pthread_t)
Definition
platform/thread.h:44
asciichat_thread_t
pthread_t asciichat_thread_t
Thread handle type (POSIX: pthread_t)
Definition
platform/thread.h:42
asciichat_thread_create
int asciichat_thread_create(asciichat_thread_t *thread, void *(*func)(void *), void *arg)
Create a new thread.
asciichat_thread_current_id
uint64_t asciichat_thread_current_id(void)
Get the current thread's unique numeric ID.
stdbool.h
windows_compat.h
Wrapper for windows.h with C23 alignment compatibility.
lib
platform
thread.h
Generated by
1.9.8