Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** C++ access to NSPR locks (PRLock) |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | #if defined(_RCLOCK_H) |
michael@0 | 11 | #else |
michael@0 | 12 | #define _RCLOCK_H |
michael@0 | 13 | |
michael@0 | 14 | #include "rcbase.h" |
michael@0 | 15 | |
michael@0 | 16 | #include <prlock.h> |
michael@0 | 17 | |
michael@0 | 18 | class PR_IMPLEMENT(RCLock): public RCBase |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | RCLock(); |
michael@0 | 22 | virtual ~RCLock(); |
michael@0 | 23 | |
michael@0 | 24 | void Acquire(); /* non-reentrant */ |
michael@0 | 25 | void Release(); /* should be by owning thread */ |
michael@0 | 26 | |
michael@0 | 27 | friend class RCCondition; |
michael@0 | 28 | |
michael@0 | 29 | private: |
michael@0 | 30 | RCLock(const RCLock&); /* can't do that */ |
michael@0 | 31 | void operator=(const RCLock&); /* nor that */ |
michael@0 | 32 | |
michael@0 | 33 | PRLock *lock; |
michael@0 | 34 | }; /* RCLock */ |
michael@0 | 35 | |
michael@0 | 36 | /* |
michael@0 | 37 | ** Class: RCEnter |
michael@0 | 38 | ** |
michael@0 | 39 | ** In scope locks. You can only allocate them on the stack. The language |
michael@0 | 40 | ** will insure that they get released (by calling the destructor) when |
michael@0 | 41 | ** the thread leaves scope, even if via an exception. |
michael@0 | 42 | */ |
michael@0 | 43 | class PR_IMPLEMENT(RCEnter) |
michael@0 | 44 | { |
michael@0 | 45 | public: |
michael@0 | 46 | ~RCEnter(); /* releases the lock */ |
michael@0 | 47 | RCEnter(RCLock*); /* acquires the lock */ |
michael@0 | 48 | |
michael@0 | 49 | private: |
michael@0 | 50 | RCLock *lock; |
michael@0 | 51 | |
michael@0 | 52 | RCEnter(); |
michael@0 | 53 | RCEnter(const RCEnter&); |
michael@0 | 54 | void operator=(const RCEnter&); |
michael@0 | 55 | |
michael@0 | 56 | void *operator new(PRSize) { return NULL; } |
michael@0 | 57 | void operator delete(void*) { } |
michael@0 | 58 | }; /* RCEnter */ |
michael@0 | 59 | |
michael@0 | 60 | |
michael@0 | 61 | inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); } |
michael@0 | 62 | inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; } |
michael@0 | 63 | |
michael@0 | 64 | #endif /* defined(_RCLOCK_H) */ |
michael@0 | 65 | |
michael@0 | 66 | /* RCLock.h */ |