// On MacOS, clock_gettime is available from version 10.12, and on // iOS, from version 10.0. So we can't use it yet. #ifdefined(WEBRTC_MAC) || defined(WEBRTC_IOS) #define USE_CLOCK_GETTIME 0 #define USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP 0 // On Android, pthread_condattr_setclock is available from version 21. By // default, we target a new enough version for 64-bit platforms but not for // 32-bit platforms. For older versions, use // pthread_cond_timedwait_monotonic_np. #elifdefined(WEBRTC_ANDROID) && (__ANDROID_API__ < 21) #define USE_CLOCK_GETTIME 1 #define USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP 1 #else #define USE_CLOCK_GETTIME 1 #define USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP 0 #endif
// Get the current time. #if USE_CLOCK_GETTIME
clock_gettime(CLOCK_MONOTONIC, &ts); #else
timeval tv;
gettimeofday(&tv, nullptr);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = TimeDelta::Micros(tv.tv_usec).ns(); #endif
// Add the specified number of nanoseconds to it. // Use integer division to transfer full seconds to `tv_sec`. // `ns` has type either std::ldiv_t or std::lldiv_t. auto ns = std::div(ts.tv_nsec + from_now.ns(), TimeDelta::Seconds(1).ns());
ts.tv_sec += ns.quot;
ts.tv_nsec = ns.rem;
return ts;
}
} // namespace
bool Event::Wait(TimeDelta give_up_after, TimeDelta warn_after) { // Instant when we'll log a warning message (because we've been waiting so // long it might be a bug), but not yet give up waiting. nullopt if we // shouldn't log a warning. const std::optional<timespec> warn_ts =
warn_after >= give_up_after ? std::nullopt
: std::make_optional(GetTimespec(warn_after));
// Instant when we'll stop waiting and return an error. nullopt if we should // never give up. const std::optional<timespec> give_up_ts =
give_up_after.IsPlusInfinity()
? std::nullopt
: std::make_optional(GetTimespec(give_up_after));
// Wait for `event_cond_` to trigger and `event_status_` to be set, with the // given timeout (or without a timeout if none is given). constauto wait = [&](const std::optional<timespec> timeout_ts) {
int error = 0; while (!event_status_ && error == 0) {
if (timeout_ts == std::nullopt) {
error = pthread_cond_wait(&event_cond_, &event_mutex_);
} else { #if USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
error = pthread_cond_timedwait_monotonic_np(&event_cond_, &event_mutex_,
&*timeout_ts); #else
error =
pthread_cond_timedwait(&event_cond_, &event_mutex_, &*timeout_ts); #endif
}
} return error;
};
int error;
if (warn_ts == std::nullopt) {
error = wait(give_up_ts);
} else {
error = wait(warn_ts);
if (error == ETIMEDOUT) {
WarnThatTheCurrentThreadIsProbablyDeadlocked();
error = wait(give_up_ts);
}
}
// NOTE(liulk): Exactly one thread will auto-reset this event. All // the other threads will think it's unsignaled. This seems to be // consistent with auto-reset events in WEBRTC_WIN
if (error == 0 && !is_manual_reset_)
event_status_ = false;
pthread_mutex_unlock(&event_mutex_);
return (error == 0);
}
#endif
} // namespace webrtc
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.