fix: split main command queue into per-source SPSC queues

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-09 23:32:21 +00:00
parent de0389e144
commit 7edd95d06e
3 changed files with 57 additions and 16 deletions

View File

@@ -16,7 +16,8 @@
struct channel_t channels[MAX_CHANNELS];
atomic_int channel_count = 0;
int next_channel_id = 1;
spsc_queue_t cmd_queue_main;
spsc_queue_t cmd_queue_main_midi;
spsc_queue_t cmd_queue_main_fifo;
atomic_int global_rt_cycles = 0;
jack_port_t *midi_control_port = NULL;
jack_port_t *midi_clock_port = NULL;
@@ -218,7 +219,8 @@ void jack_shutdown_cb(void *arg) {
* ---------------------------------------------------------------- */
int looper_init(jack_client_t *client) {
queue_init(&cmd_queue);
queue_init(&cmd_queue_main);
queue_init(&cmd_queue_main_midi);
queue_init(&cmd_queue_main_fifo);
/* channel 0 */
channels[0].active = 1;
atomic_store(&channels[0].state, STATE_IDLE);
@@ -253,9 +255,36 @@ int looper_init(jack_client_t *client) {
* mainloop command processing
* ---------------------------------------------------------------- */
void looper_process_commands(jack_client_t *client) {
/* Drain mainloop command queue (add/remove) */
/* Drain mainloop command queues (add/remove) */
command_t cmd;
while (queue_pop(&cmd_queue_main, &cmd)) {
while (queue_pop(&cmd_queue_main_midi, &cmd)) {
switch (cmd.type) {
case CMD_ADD_CHANNEL: {
int idx;
for (idx = 0; idx < MAX_CHANNELS; idx++)
if (!channels[idx].active)
break;
if (idx < MAX_CHANNELS)
channel_add(client, idx);
break;
}
case CMD_REMOVE_CHANNEL: {
int remove_idx = -1;
for (int idx = 1; idx < MAX_CHANNELS; idx++)
if (channels[idx].active)
remove_idx = idx;
if (remove_idx != -1) {
channel_remove(client, remove_idx);
pending_unregister_idx = remove_idx;
pending_unregister_cycle = atomic_load(&global_rt_cycles);
}
break;
}
default:
break;
}
}
while (queue_pop(&cmd_queue_main_fifo, &cmd)) {
switch (cmd.type) {
case CMD_ADD_CHANNEL: {
int idx;