ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
worker.c File Reference

Go to the source code of this file.

Data Structures

struct  quic_worker
 For acip quic worker, this is the live record that ties endpoint, lane, failure, context together. The owning code creates it, updates it while work is active, and releases its handles and pointed-to storage before freeing the record. More...

Functions

asciichat_error_t quic_worker_start (quic_udp_endpoint_t *endpoint, mutex_t *lane, quic_worker_failure_fn failure, void *context, quic_worker_t **out)
asciichat_error_t quic_worker_start_locked_failure (quic_udp_endpoint_t *endpoint, mutex_t *lane, quic_worker_failure_fn failure, void *context, quic_worker_t **out)
void quic_worker_wake (void *arg)
asciichat_error_t quic_worker_stop (quic_worker_t **worker)

Function Documentation

◆ quic_worker_start()

asciichat_error_t quic_worker_start ( quic_udp_endpoint_t * endpoint,
mutex_t * lane,
quic_worker_failure_fn failure,
void * context,
quic_worker_t ** out )

Definition at line 101 of file worker.c.

101 {
102 return worker_start(endpoint, lane, failure, context, false, out);
103}
static bool size_t gotel_query_t * out
Definition queries.h:10

References out.

◆ quic_worker_start_locked_failure()

asciichat_error_t quic_worker_start_locked_failure ( quic_udp_endpoint_t * endpoint,
mutex_t * lane,
quic_worker_failure_fn failure,
void * context,
quic_worker_t ** out )

Definition at line 105 of file worker.c.

105 {
106 return worker_start(endpoint, lane, failure, context, true, out);
107}

References out.

Referenced by quic_endpoint_migrate(), and quic_endpoint_open().

◆ quic_worker_stop()

asciichat_error_t quic_worker_stop ( quic_worker_t ** worker)

Definition at line 115 of file worker.c.

115 {
116 if (!worker || !*worker)
117 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid QUIC worker stop");
118 atomic_store_u64(&(*worker)->stopping, 1);
119 quic_worker_wake(*worker);
120 if (thread_join(&(*worker)->thread, NULL) != 0)
121 return SET_ERRNO(ERROR_THREAD, "Cannot join QUIC worker");
122 asciichat_error_t result = (*worker)->result;
123 SAFE_FREE(*worker);
124 *worker = NULL;
125 return result;
126}
#define SET_ERRNO(code,...)
void atomic_store_u64(atomic_t *a, uint64_t value)
Atomically store a uint64_t value.
#define SAFE_FREE(ptr)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_INVALID_PARAM
@ ERROR_THREAD
void quic_worker_wake(void *arg)
Definition worker.c:109

References atomic_store_u64(), ERROR_INVALID_PARAM, ERROR_THREAD, quic_worker_wake(), SAFE_FREE, and SET_ERRNO.

Referenced by quic_endpoint_migrate(), and quic_endpoint_stop().

◆ quic_worker_wake()

void quic_worker_wake ( void * arg)

Definition at line 109 of file worker.c.

109 {
110 quic_worker_t *worker = arg;
111 if (worker && atomic_exchange_u64(&worker->wake_pending, 1) == 0 && quic_udp_wake(worker->endpoint) != ASCIICHAT_OK)
112 atomic_store_u64(&worker->wake_pending, 0);
113}
uint64_t atomic_exchange_u64(atomic_t *a, uint64_t new_value)
Atomically exchange a uint64_t and return the old value.
@ ASCIICHAT_OK
Definition error_codes.h:50
asciichat_error_t quic_udp_wake(quic_udp_endpoint_t *endpoint)
Definition udp.c:301
struct quic_worker quic_worker_t
Definition worker.h:11

References ASCIICHAT_OK, atomic_exchange_u64(), atomic_store_u64(), and quic_udp_wake().

Referenced by quic_worker_stop().