michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** C++ access to NSPR locks (PRLock) michael@0: */ michael@0: michael@0: #if defined(_RCLOCK_H) michael@0: #else michael@0: #define _RCLOCK_H michael@0: michael@0: #include "rcbase.h" michael@0: michael@0: #include michael@0: michael@0: class PR_IMPLEMENT(RCLock): public RCBase michael@0: { michael@0: public: michael@0: RCLock(); michael@0: virtual ~RCLock(); michael@0: michael@0: void Acquire(); /* non-reentrant */ michael@0: void Release(); /* should be by owning thread */ michael@0: michael@0: friend class RCCondition; michael@0: michael@0: private: michael@0: RCLock(const RCLock&); /* can't do that */ michael@0: void operator=(const RCLock&); /* nor that */ michael@0: michael@0: PRLock *lock; michael@0: }; /* RCLock */ michael@0: michael@0: /* michael@0: ** Class: RCEnter michael@0: ** michael@0: ** In scope locks. You can only allocate them on the stack. The language michael@0: ** will insure that they get released (by calling the destructor) when michael@0: ** the thread leaves scope, even if via an exception. michael@0: */ michael@0: class PR_IMPLEMENT(RCEnter) michael@0: { michael@0: public: michael@0: ~RCEnter(); /* releases the lock */ michael@0: RCEnter(RCLock*); /* acquires the lock */ michael@0: michael@0: private: michael@0: RCLock *lock; michael@0: michael@0: RCEnter(); michael@0: RCEnter(const RCEnter&); michael@0: void operator=(const RCEnter&); michael@0: michael@0: void *operator new(PRSize) { return NULL; } michael@0: void operator delete(void*) { } michael@0: }; /* RCEnter */ michael@0: michael@0: michael@0: inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); } michael@0: inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; } michael@0: michael@0: #endif /* defined(_RCLOCK_H) */ michael@0: michael@0: /* RCLock.h */