Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion audioio/audioio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <limits.h>
#include <errno.h>
#include <signal.h>
Expand All @@ -32,7 +33,12 @@
#include "resampler.h"
#include "pcm24.h"

extern volatile bool shutdown_;
/* Must match the definition in common/mercury_engine.c: _Atomic, not
* volatile. This global is written from the termination signal handler and
* polled by every worker loop; volatile orders nothing between threads, and
* declaring the same object differently in different translation units is
* undefined behaviour on top of that. Plain assignment and test still work. */
extern _Atomic bool shutdown_;

/* ------------------------------------------------------------------ */
/* DirectSound GUID ↔ string helpers (Windows only) */
Expand Down
2 changes: 1 addition & 1 deletion common/mercury_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "virtual_clock.h"

/* ---- shared globals ---- */
volatile bool shutdown_ = false;
_Atomic bool shutdown_ = false;
static generic_modem_t g_modem;
static pthread_t g_radio_capture, g_radio_playback;
static int g_audio_system = -1;
Expand Down
8 changes: 7 additions & 1 deletion common/mercury_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
#define MERCURY_ENGINE_H

#include <stdbool.h>
#include <stdatomic.h>
#include <stdint.h>
#include <pthread.h>

#include "cfg_utils.h"
#include "ui_communication.h"
#include "modem.h"

extern volatile bool shutdown_;
/* Set by the termination signal handler, polled by main and by every worker
* loop. _Atomic rather than volatile: volatile provides no inter-thread
* ordering, and the handler-write/thread-read pair is a data race in the
* formal sense (ThreadSanitizer reports it at main.c's handler). Plain
* assignment and test still work -- C11 atomics overload them. */
extern _Atomic bool shutdown_;

/* ------------------------------------------------------------------ */
/* mercury_engine_init() */
Expand Down
7 changes: 6 additions & 1 deletion data_interfaces/tcp_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ extern cbuf_handle_t data_rx_buffer_arq;
extern cbuf_handle_t data_tx_buffer_broadcast;
extern cbuf_handle_t data_rx_buffer_broadcast;

extern volatile bool shutdown_;
/* Must match the definition in common/mercury_engine.c: _Atomic, not
* volatile. This global is written from the termination signal handler and
* polled by every worker loop; volatile orders nothing between threads, and
* declaring the same object differently in different translation units is
* undefined behaviour on top of that. Plain assignment and test still work. */
extern _Atomic bool shutdown_;

extern arq_info arq_conn;

Expand Down
10 changes: 8 additions & 2 deletions datalink_arq/arq.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ static pthread_t g_loop_tid;
static pthread_t g_cmd_tid;
static pthread_t g_payload_tid;

static volatile bool g_running;
static volatile bool g_initialized;
/* Read by the modem RX/TX and TCP threads while the main thread writes them
* at init/teardown. `volatile` orders nothing between threads and is not
* atomic in C -- formally a data race, and ThreadSanitizer flags exactly that
* (arq_init writing g_initialized against arq_get_runtime_snapshot reading it
* from the RX thread). C11 atomics keep the plain read/write syntax, so only
* the declaration changes. */
static _Atomic bool g_running;
static _Atomic bool g_initialized;

/* ======================================================================
* Event queue helpers
Expand Down
8 changes: 7 additions & 1 deletion datalink_broadcast/broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
Expand All @@ -36,7 +37,12 @@
#include "tcp_interfaces.h"
#include "hermes_log.h"

extern volatile bool shutdown_; // global shutdown flag
/* Must match the definition in common/mercury_engine.c: _Atomic, not
* volatile. This global is written from the termination signal handler and
* polled by every worker loop; volatile orders nothing between threads, and
* declaring the same object differently in different translation units is
* undefined behaviour on top of that. Plain assignment and test still work. */
extern _Atomic bool shutdown_;
extern arq_info arq_conn; // ARQ connection info

static const uint32_t hermes_broadcast_frame_size[] = { 510, 126, 14, 54, 14, 3, 30, 30, 14, 1180, 1213 };
Expand Down
8 changes: 7 additions & 1 deletion gui_interface/ui_communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <time.h>
#include <errno.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <math.h>

#include "../common/os_interop.h"
Expand All @@ -53,7 +54,12 @@ extern int audioio_restart(const char *capture_dev, const char *playback_dev,
int audio_subsys, int capture_channel_layout);

// global shutdown flag from main.c
extern volatile bool shutdown_;
/* Must match the definition in common/mercury_engine.c: _Atomic, not
* volatile. This global is written from the termination signal handler and
* polled by every worker loop; volatile orders nothing between threads, and
* declaring the same object differently in different translation units is
* undefined behaviour on top of that. Plain assignment and test still work. */
extern _Atomic bool shutdown_;

#define UI_LOG_TAG "ui-comm"

Expand Down
Loading
Loading