tor-browser

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

rccv.cpp (1560B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 ** RCCondition - C++ wrapper around NSPR's PRCondVar
      8 */
      9 
     10 #include "rccv.h"
     11 
     12 #include <prlog.h>
     13 #include <prerror.h>
     14 #include <prcvar.h>
     15 
     16 RCCondition::RCCondition(class RCLock *lock): RCBase()
     17 {
     18    cv = PR_NewCondVar(lock->lock);
     19    PR_ASSERT(NULL != cv);
     20    timeout = PR_INTERVAL_NO_TIMEOUT;
     21 }  /* RCCondition::RCCondition */
     22 
     23 RCCondition::~RCCondition()
     24 {
     25    if (NULL != cv) {
     26        PR_DestroyCondVar(cv);
     27    }
     28 }  /* RCCondition::~RCCondition */
     29 
     30 PRStatus RCCondition::Wait()
     31 {
     32    PRStatus rv;
     33    PR_ASSERT(NULL != cv);
     34    if (NULL == cv)
     35    {
     36        SetError(PR_INVALID_ARGUMENT_ERROR, 0);
     37        rv = PR_FAILURE;
     38    }
     39    else {
     40        rv = PR_WaitCondVar(cv, timeout.interval);
     41    }
     42    return rv;
     43 }  /* RCCondition::Wait */
     44 
     45 PRStatus RCCondition::Notify()
     46 {
     47    return PR_NotifyCondVar(cv);
     48 }  /* RCCondition::Notify */
     49 
     50 PRStatus RCCondition::Broadcast()
     51 {
     52    return PR_NotifyAllCondVar(cv);
     53 }  /* RCCondition::Broadcast */
     54 
     55 PRStatus RCCondition::SetTimeout(const RCInterval& tmo)
     56 {
     57    if (NULL == cv)
     58    {
     59        SetError(PR_INVALID_ARGUMENT_ERROR, 0);
     60        return PR_FAILURE;
     61    }
     62    timeout = tmo;
     63    return PR_SUCCESS;
     64 }  /* RCCondition::SetTimeout */
     65 
     66 RCInterval RCCondition::GetTimeout() const {
     67    return timeout;
     68 }
     69 
     70 /* rccv.cpp */