ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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 102 of file worker.c.

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

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 107 of file worker.c.

108 {
109 return worker_start(endpoint, lane, failure, context, true, out);
110}

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 118 of file worker.c.

118 {
119 if (!worker || !*worker)
120 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid QUIC worker stop");
121 atomic_store_u64(&(*worker)->stopping, 1);
122 quic_worker_wake(*worker);
123 if (thread_join(&(*worker)->thread, NULL) != 0)
124 return SET_ERRNO(ERROR_THREAD, "Cannot join QUIC worker");
125 asciichat_error_t result = (*worker)->result;
126 SAFE_FREE(*worker);
127 *worker = NULL;
128 return result;
129}
#define SET_ERRNO(code,...)
#define SAFE_FREE(ptr)
Definition common.h:377
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ERROR_INVALID_PARAM
@ ERROR_THREAD
void quic_worker_wake(void *arg)
Definition worker.c:112

References 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 112 of file worker.c.

112 {
113 quic_worker_t *worker = arg;
114 if (worker && atomic_exchange_u64(&worker->wake_pending, 1) == 0 && quic_udp_wake(worker->endpoint) != ASCIICHAT_OK)
115 atomic_store_u64(&worker->wake_pending, 0);
116}
@ ASCIICHAT_OK
Definition error_codes.h:46
asciichat_error_t quic_udp_wake(quic_udp_endpoint_t *endpoint)
Definition udp.c:319
struct quic_worker quic_worker_t
Definition worker.h:11

References ASCIICHAT_OK, and quic_udp_wake().

Referenced by quic_worker_stop().