tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

condition_variable_win.cc (1437B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style license that can be
      5 // found in the LICENSE file.
      6 
      7 #include "base/condition_variable.h"
      8 
      9 #include "base/lock.h"
     10 #include "base/logging.h"
     11 #include "base/time.h"
     12 
     13 ConditionVariable::ConditionVariable(Lock* user_lock)
     14    : srwlock_(user_lock->lock_.native_handle()) {
     15  DCHECK(user_lock);
     16  InitializeConditionVariable(&cv_);
     17 }
     18 
     19 ConditionVariable::~ConditionVariable() = default;
     20 
     21 void ConditionVariable::Wait() {
     22  TimedWait(base::TimeDelta::FromMilliseconds(INFINITE));
     23 }
     24 
     25 void ConditionVariable::TimedWait(const base::TimeDelta& max_time) {
     26  DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds());
     27 
     28  if (!SleepConditionVariableSRW(&cv_, srwlock_, timeout, 0)) {
     29    // On failure, we only expect the CV to timeout. Any other error value means
     30    // that we've unexpectedly woken up.
     31    // Note that WAIT_TIMEOUT != ERROR_TIMEOUT. WAIT_TIMEOUT is used with the
     32    // WaitFor* family of functions as a direct return value. ERROR_TIMEOUT is
     33    // used with GetLastError().
     34    DCHECK_EQ(static_cast<DWORD>(ERROR_TIMEOUT), GetLastError());
     35  }
     36 }
     37 
     38 void ConditionVariable::Broadcast() { WakeAllConditionVariable(&cv_); }
     39 
     40 void ConditionVariable::Signal() { WakeConditionVariable(&cv_); }