2016-11-15 22:18:41 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/common/waitable_event_impl.h"
|
|
|
|
|
|
|
|
#include "include/cef_task.h"
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
#include "base/notreached.h"
|
2016-11-15 22:18:41 +01:00
|
|
|
#include "base/time/time.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool AllowWait() {
|
|
|
|
if (CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO)) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false) << "waiting is not allowed on the current thread";
|
2016-11-15 22:18:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefWaitableEvent> CefWaitableEvent::CreateWaitableEvent(
|
|
|
|
bool automatic_reset,
|
|
|
|
bool initially_signaled) {
|
|
|
|
return new CefWaitableEventImpl(automatic_reset, initially_signaled);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefWaitableEventImpl::CefWaitableEventImpl(bool automatic_reset,
|
|
|
|
bool initially_signaled)
|
2017-05-17 11:29:28 +02:00
|
|
|
: event_(automatic_reset ? base::WaitableEvent::ResetPolicy::AUTOMATIC
|
|
|
|
: base::WaitableEvent::ResetPolicy::MANUAL,
|
|
|
|
initially_signaled
|
|
|
|
? base::WaitableEvent::InitialState::SIGNALED
|
|
|
|
: base::WaitableEvent::InitialState::NOT_SIGNALED) {}
|
2016-11-15 22:18:41 +01:00
|
|
|
|
|
|
|
void CefWaitableEventImpl::Reset() {
|
|
|
|
event_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWaitableEventImpl::Signal() {
|
|
|
|
event_.Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWaitableEventImpl::IsSignaled() {
|
|
|
|
return event_.IsSignaled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWaitableEventImpl::Wait() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWait()) {
|
2016-11-15 22:18:41 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-15 22:18:41 +01:00
|
|
|
event_.Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWaitableEventImpl::TimedWait(int64 max_ms) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWait()) {
|
2016-11-15 22:18:41 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-10-19 00:17:16 +02:00
|
|
|
return event_.TimedWait(base::Milliseconds(max_ms));
|
2016-11-15 22:18:41 +01:00
|
|
|
}
|