support: sync timers with data loop

Start and stop the timers in the data_loop. Otherwise we might be trying
to stop a timer while the data loop is starting it and we end up with
"ready non-active node" messages.
This commit is contained in:
Wim Taymans 2023-03-24 17:24:56 +01:00
parent 157a97cc98
commit 5ea3c10dca
2 changed files with 10 additions and 10 deletions

View file

@ -149,7 +149,7 @@ static int set_timers(struct impl *this)
spa_log_debug(this->log, "%p now:%"PRIu64, this, this->next_time); spa_log_debug(this->log, "%p now:%"PRIu64, this, this->next_time);
if (this->following) { if (this->following || !this->started) {
set_timeout(this, 0); set_timeout(this, 0);
} else { } else {
set_timeout(this, this->next_time); set_timeout(this, this->next_time);
@ -162,7 +162,7 @@ static inline bool is_following(struct impl *this)
return this->position && this->clock && this->position->clock.id != this->clock->id; return this->position && this->clock && this->position->clock.id != this->clock->id;
} }
static int do_reassign_follower(struct spa_loop *loop, static int do_set_timers(struct spa_loop *loop,
bool async, bool async,
uint32_t seq, uint32_t seq,
const void *data, const void *data,
@ -189,7 +189,7 @@ static int reassign_follower(struct impl *this)
if (following != this->following) { if (following != this->following) {
spa_log_debug(this->log, NAME" %p: reassign follower %d->%d", this, this->following, following); spa_log_debug(this->log, NAME" %p: reassign follower %d->%d", this, this->following, following);
this->following = following; this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this); spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
} }
return 0; return 0;
} }
@ -323,9 +323,9 @@ static int do_start(struct impl *this)
return 0; return 0;
this->following = is_following(this); this->following = is_following(this);
set_timers(this);
this->started = true; this->started = true;
this->last_time = 0; this->last_time = 0;
spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
return 0; return 0;
} }
@ -334,7 +334,7 @@ static int do_stop(struct impl *this)
if (!this->started) if (!this->started)
return 0; return 0;
this->started = false; this->started = false;
set_timeout(this, 0); spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
return 0; return 0;
} }

View file

@ -191,7 +191,7 @@ static int set_timers(struct impl *this)
return res; return res;
this->next_time = SPA_TIMESPEC_TO_NSEC(&now); this->next_time = SPA_TIMESPEC_TO_NSEC(&now);
if (this->following) { if (this->following || !this->started) {
set_timeout(this, 0); set_timeout(this, 0);
} else { } else {
set_timeout(this, this->next_time); set_timeout(this, this->next_time);
@ -204,7 +204,7 @@ static inline bool is_following(struct impl *this)
return this->position && this->clock && this->position->clock.id != this->clock->id; return this->position && this->clock && this->position->clock.id != this->clock->id;
} }
static int do_reassign_follower(struct spa_loop *loop, static int do_set_timers(struct spa_loop *loop,
bool async, bool async,
uint32_t seq, uint32_t seq,
const void *data, const void *data,
@ -227,7 +227,7 @@ static int reassign_follower(struct impl *this)
if (following != this->following) { if (following != this->following) {
spa_log_debug(this->log, NAME" %p: reassign follower %d->%d", this, this->following, following); spa_log_debug(this->log, NAME" %p: reassign follower %d->%d", this, this->following, following);
this->following = following; this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this); spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
} }
return 0; return 0;
} }
@ -310,8 +310,8 @@ static int do_start(struct impl *this)
return 0; return 0;
this->following = is_following(this); this->following = is_following(this);
set_timers(this);
this->started = true; this->started = true;
spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
return 0; return 0;
} }
@ -320,7 +320,7 @@ static int do_stop(struct impl *this)
if (!this->started) if (!this->started)
return 0; return 0;
this->started = false; this->started = false;
set_timeout(this, 0); spa_loop_invoke(this->data_loop, do_set_timers, 0, NULL, 0, true, this);
return 0; return 0;
} }