tor-browser

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

rclock.h (1623B)


      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 ** C++ access to NSPR locks (PRLock)
      8 */
      9 
     10 #if defined(_RCLOCK_H)
     11 #else
     12 #define _RCLOCK_H
     13 
     14 #include "rcbase.h"
     15 
     16 #include <prlock.h>
     17 
     18 class PR_IMPLEMENT(RCLock): public RCBase
     19 {
     20 public:
     21    RCLock();
     22    virtual ~RCLock();
     23 
     24    void Acquire();                 /* non-reentrant */
     25    void Release();                 /* should be by owning thread */
     26 
     27    friend class RCCondition;
     28 
     29 private:
     30    RCLock(const RCLock&);          /* can't do that */
     31    void operator=(const RCLock&);  /* nor that */
     32 
     33    PRLock *lock;
     34 };  /* RCLock */
     35 
     36 /*
     37 ** Class: RCEnter
     38 **
     39 ** In scope locks. You can only allocate them on the stack. The language
     40 ** will insure that they get released (by calling the destructor) when
     41 ** the thread leaves scope, even if via an exception.
     42 */
     43 class PR_IMPLEMENT(RCEnter)
     44 {
     45 public:
     46    ~RCEnter();                     /* releases the lock */
     47    RCEnter(RCLock*);               /* acquires the lock */
     48 
     49 private:
     50    RCLock *lock;
     51 
     52    RCEnter();
     53    RCEnter(const RCEnter&);
     54    void operator=(const RCEnter&);
     55 
     56    void *operator new(PRSize) {
     57        return NULL;
     58    }
     59    void operator delete(void*) { }
     60 };  /* RCEnter */
     61 
     62 
     63 inline RCEnter::RCEnter(RCLock* ml) {
     64    lock = ml;
     65    lock->Acquire();
     66 }
     67 inline RCEnter::~RCEnter() {
     68    lock->Release();
     69    lock = NULL;
     70 }
     71 
     72 #endif /* defined(_RCLOCK_H) */
     73 
     74 /* RCLock.h */