diff --git a/jack/internal.h b/jack/internal.h index 2a0863e..05800a3 100644 --- a/jack/internal.h +++ b/jack/internal.h @@ -61,7 +61,7 @@ #endif #ifndef TRUE -#define TRUE (!FALSE) +#define TRUE (1) #endif typedef struct _jack_engine jack_engine_t; @@ -96,8 +96,8 @@ typedef struct { int8_t new_pos; /* new position this cycle */ int8_t pending_pos; /* new position request pending */ jack_nframes_t pending_frame; /* pending frame number */ - uint32_t sync_clients; /* number of active slowsync clients */ - uint32_t sync_remain; /* number of them with sync_poll */ + int32_t sync_clients; /* number of active_slowsync clients */ + int32_t sync_remain; /* number of them with sync_poll */ jack_time_t sync_timeout; jack_time_t sync_time_left; jack_frame_timer_t frame_timer; @@ -166,14 +166,15 @@ typedef volatile struct { volatile jack_client_state_t state; /* w: engine and client r: engine */ volatile int8_t name[JACK_CLIENT_NAME_SIZE+1]; volatile ClientType type; /* w: engine r: engine and client */ - volatile int8_t active : 1; /* w: engine r: engine and client */ - volatile int8_t dead : 1; /* r/w: engine */ - volatile int8_t timed_out : 1; /* r/w: engine */ - volatile int8_t is_timebase : 1; /* w: engine, r: engine and client */ - volatile int8_t timebase_new : 1; /* w: engine and client, r: engine */ - volatile int8_t is_slowsync : 1; /* w: engine, r: engine and client */ - volatile int8_t sync_poll : 1; /* w: engine and client, r: engine */ - volatile int8_t sync_new : 1; /* w: engine and client, r: engine */ + volatile int8_t active; /* w: engine r: engine and client */ + volatile int8_t dead; /* r/w: engine */ + volatile int8_t timed_out; /* r/w: engine */ + volatile int8_t is_timebase; /* w: engine, r: engine and client */ + volatile int8_t timebase_new; /* w: engine and client, r: engine */ + volatile int8_t is_slowsync; /* w: engine, r: engine and client */ + volatile int8_t active_slowsync; /* w: engine, r: engine and client */ + volatile int8_t sync_poll; /* w: engine and client, r: engine */ + volatile int8_t sync_new; /* w: engine and client, r: engine */ volatile pid_t pid; /* w: client r: engine; client pid */ volatile pid_t pgrp; /* w: client r: engine; client pgrp */ volatile uint64_t signalled_at; diff --git a/jackd/engine.c b/jackd/engine.c index 3e80e08..44cbe9d 100644 --- a/jackd/engine.c +++ b/jackd/engine.c @@ -2590,7 +2590,6 @@ jack_zombify_client (jack_engine_t *engine, jack_client_internal_t *client) client->control->dead = TRUE; - jack_transport_client_exit (engine, client); jack_client_disconnect (engine, client); jack_client_do_deactivate (engine, client, FALSE); } diff --git a/jackd/transengine.c b/jackd/transengine.c index a355b1a..78a7de1 100644 --- a/jackd/transengine.c +++ b/jackd/transengine.c @@ -59,7 +59,8 @@ jack_sync_poll_new (jack_engine_t *engine, jack_client_internal_t *client) * * precondition: caller holds the graph lock. */ static inline void -jack_sync_poll_exit (jack_engine_t *engine, jack_client_internal_t *client) +jack_sync_poll_deactivate (jack_engine_t *engine, + jack_client_internal_t *client) { if (client->control->sync_poll) { client->control->sync_poll = 0; @@ -68,6 +69,9 @@ jack_sync_poll_exit (jack_engine_t *engine, jack_client_internal_t *client) VERBOSE (engine, "sync poll interrupted for client %" PRIu32 "\n", client->control->id); } + client->control->active_slowsync = 0; + engine->control->sync_clients--; + assert(engine->control->sync_clients >= 0); } /* stop polling all the slow-sync clients @@ -82,8 +86,7 @@ jack_sync_poll_stop (jack_engine_t *engine) for (node = engine->clients; node; node = jack_slist_next (node)) { jack_client_internal_t *client = (jack_client_internal_t *) node->data; - if (client->control->is_slowsync && - client->control->active && + if (client->control->active_slowsync && client->control->sync_poll) { client->control->sync_poll = 0; poll_count++; @@ -113,8 +116,7 @@ jack_sync_poll_start (jack_engine_t *engine) for (node = engine->clients; node; node = jack_slist_next (node)) { jack_client_internal_t *client = (jack_client_internal_t *) node->data; - if (client->control->is_slowsync && - client->control->active) { + if (client->control->active_slowsync) { client->control->sync_poll = 1; sync_count++; } @@ -248,6 +250,8 @@ void jack_transport_activate (jack_engine_t *engine, jack_client_internal_t *client) { if (client->control->is_slowsync) { + assert(!client->control->active_slowsync); + client->control->active_slowsync = 1; engine->control->sync_clients++; jack_sync_poll_new (engine, client); } @@ -300,8 +304,8 @@ jack_transport_client_exit (jack_engine_t *engine, } if (client->control->is_slowsync) { - jack_sync_poll_exit(engine, client); - engine->control->sync_clients--; + if (client->control->active_slowsync) + jack_sync_poll_deactivate (engine, client); if (client->control->dead) client->control->is_slowsync = 0; } @@ -314,6 +318,7 @@ jack_transport_client_new (jack_client_internal_t *client) client->control->is_timebase = 0; client->control->timebase_new = 0; client->control->is_slowsync = 0; + client->control->active_slowsync = 0; client->control->sync_poll = 0; client->control->sync_new = 0; client->control->sync_cb = NULL; @@ -335,10 +340,9 @@ jack_transport_client_reset_sync (jack_engine_t *engine, client = jack_client_internal_by_id (engine, client_id); if (client && (client->control->is_slowsync)) { - jack_sync_poll_exit(engine, client); + if (client->control->active_slowsync) + jack_sync_poll_deactivate (engine, client); client->control->is_slowsync = 0; - if (client->control->active) - engine->control->sync_clients--; ret = 0; } else ret = EINVAL; @@ -364,12 +368,14 @@ jack_transport_client_set_sync (jack_engine_t *engine, if (client) { if (!client->control->is_slowsync) { client->control->is_slowsync = 1; - if (client->control->active) + if (client->control->active) { + client->control->active_slowsync = 1; engine->control->sync_clients++; + } } /* force poll of the new slow-sync client, if active */ - if (client->control->active) + if (client->control->active_slowsync) jack_sync_poll_new (engine, client); ret = 0; } else diff --git a/libjack/transclient.c b/libjack/transclient.c index 6a6f0d1..aa8bb26 100644 --- a/libjack/transclient.c +++ b/libjack/transclient.c @@ -145,10 +145,10 @@ jack_call_sync_client (jack_client_t *client) jack_client_control_t *control = client->control; jack_control_t *ectl = client->engine; - /* Make sure we are still slow-sync; is_slowsync is set in a - * critical section; sync_cb is not. */ + /* Make sure still active and slow-sync; active_slowsync is + * set in a critical section; sync_cb is not. */ if ((ectl->new_pos || control->sync_poll || control->sync_new) && - control->is_slowsync) { + control->active_slowsync) { if (control->sync_cb (ectl->transport_state, &ectl->current_time,