mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-09 09:39:17 +00:00
Replace delay by deadline in timedwait()
The function sc_cond_timedwait() accepted a parameter representing the max duration to wait, because it internally uses SDL_CondWaitTimeout(). Instead, accept a deadline, to be consistent with pthread_cond_timedwait().
This commit is contained in:
parent
1dcd3f295d
commit
0faadc7590
4 changed files with 9 additions and 9 deletions
|
@ -84,11 +84,9 @@ run_fps_counter(void *data) {
|
||||||
sc_tick now = sc_tick_now();
|
sc_tick now = sc_tick_now();
|
||||||
check_interval_expired(counter, now);
|
check_interval_expired(counter, now);
|
||||||
|
|
||||||
assert(counter->next_timestamp > now);
|
|
||||||
sc_tick remaining = counter->next_timestamp - now;
|
|
||||||
|
|
||||||
// ignore the reason (timeout or signaled), we just loop anyway
|
// ignore the reason (timeout or signaled), we just loop anyway
|
||||||
sc_cond_timedwait(&counter->state_cond, &counter->mutex, remaining);
|
sc_cond_timedwait(&counter->state_cond, &counter->mutex,
|
||||||
|
counter->next_timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sc_mutex_unlock(&counter->mutex);
|
sc_mutex_unlock(&counter->mutex);
|
||||||
|
|
|
@ -557,7 +557,7 @@ server_stop(struct server *server) {
|
||||||
#define WATCHDOG_DELAY_MS 1000
|
#define WATCHDOG_DELAY_MS 1000
|
||||||
signaled = sc_cond_timedwait(&server->process_terminated_cond,
|
signaled = sc_cond_timedwait(&server->process_terminated_cond,
|
||||||
&server->mutex,
|
&server->mutex,
|
||||||
WATCHDOG_DELAY_MS);
|
sc_tick_now() + WATCHDOG_DELAY_MS);
|
||||||
}
|
}
|
||||||
sc_mutex_unlock(&server->mutex);
|
sc_mutex_unlock(&server->mutex);
|
||||||
|
|
||||||
|
|
|
@ -124,12 +124,14 @@ sc_cond_wait(sc_cond *cond, sc_mutex *mutex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick ms) {
|
sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick deadline) {
|
||||||
if (ms < 0) {
|
sc_tick now = sc_tick_now();
|
||||||
|
if (deadline <= now) {
|
||||||
return false; // timeout
|
return false; // timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = SDL_CondWaitTimeout(cond->cond, mutex->mutex, (uint32_t) ms);
|
sc_tick delay = deadline - now;
|
||||||
|
int r = SDL_CondWaitTimeout(cond->cond, mutex->mutex, delay);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
LOGC("Could not wait on condition with timeout: %s", SDL_GetError());
|
LOGC("Could not wait on condition with timeout: %s", SDL_GetError());
|
||||||
|
|
|
@ -74,7 +74,7 @@ sc_cond_wait(sc_cond *cond, sc_mutex *mutex);
|
||||||
|
|
||||||
// return true on signaled, false on timeout
|
// return true on signaled, false on timeout
|
||||||
bool
|
bool
|
||||||
sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick ms);
|
sc_cond_timedwait(sc_cond *cond, sc_mutex *mutex, sc_tick deadline);
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_cond_signal(sc_cond *cond);
|
sc_cond_signal(sc_cond *cond);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue