Skip to content

CefWaitableEvent

Header: cef_waitable_event.h
Category: System Utilities

Overview

Tasks, threads, parsers, streams, cookies, URL requests, scheme registration, and constant tables.

CefWaitableEvent

Source File: include/cef_waitable_event.h

Process / Thread Context: Any process. Reset, Signal, IsSignaled, and construction are safe from any thread. Wait and TimedWait may NOT be called on the browser process UI or IO threads.

Purpose: Thread synchronization primitive — equivalent to a Lock + ConditionVariable guarding a boolean. For more complex state changes, prefer a real ConditionVariable.

Methods

static CefRefPtr<CefWaitableEvent> CreateWaitableEvent(bool automatic_reset, bool initially_signaled)

Parameters:

  • automatic_reset: true → event auto-resets to unsignaled after one waiting thread is released; false → remains signaled until Reset().
  • initially_signaled: true → starts signaled.

Return Value: New event.

Threading Constraint: Any thread.

virtual void Reset()

Return Value: set state to unsignaled. Any thread.

Threading Constraint: Threading constraint not specified in source.

virtual void Signal()

Return Value: set state to signaled; wakes one (auto-reset) or all (manual) waiters. Any thread.

Threading Constraint: Threading constraint not specified in source.

virtual bool IsSignaled()

Return Value: true if signaled. Auto-reset events reset themselves when polled here. Any thread.

Threading Constraint: Threading constraint not specified in source.

virtual void Wait()

Return Value: block indefinitely until signaled. Not allowed on browser UI or IO threads.

Threading Constraint: Threading constraint not specified in source.

virtual bool TimedWait(int64_t max_ms)

Parameters:

  • max_ms: maximum wait in milliseconds.

Return Value: true if signaled before timeout; false does not necessarily mean the timeout elapsed (per header comment). Not allowed on browser UI or IO threads.

Threading Constraint: Threading constraint not specified in source.

Usage Example

cpp
// Block a background worker until the UI thread signals readiness.
CefRefPtr<CefWaitableEvent> ready = CefWaitableEvent::CreateWaitableEvent(
    /*automatic_reset=*/false, /*initially_signaled=*/false);

class SignalReadyTask : public CefTask {
 public:
  explicit SignalReadyTask(CefRefPtr<CefWaitableEvent> ev) : ev_(ev) {}
  void Execute() override { ev_->Signal(); }
 private:
  CefRefPtr<CefWaitableEvent> ev_;
  IMPLEMENT_REFCOUNTING(SignalReadyTask);
};

// UI thread sets the event:
CefPostTask(TID_UI, new SignalReadyTask(ready));

// Background worker (NOT UI/IO) waits:
if (ready->TimedWait(5000)) {
  // ready
} else {
  // timed out (or failed)
}

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.