1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rclock.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** C++ access to NSPR locks (PRLock) 1.11 +*/ 1.12 + 1.13 +#if defined(_RCLOCK_H) 1.14 +#else 1.15 +#define _RCLOCK_H 1.16 + 1.17 +#include "rcbase.h" 1.18 + 1.19 +#include <prlock.h> 1.20 + 1.21 +class PR_IMPLEMENT(RCLock): public RCBase 1.22 +{ 1.23 +public: 1.24 + RCLock(); 1.25 + virtual ~RCLock(); 1.26 + 1.27 + void Acquire(); /* non-reentrant */ 1.28 + void Release(); /* should be by owning thread */ 1.29 + 1.30 + friend class RCCondition; 1.31 + 1.32 +private: 1.33 + RCLock(const RCLock&); /* can't do that */ 1.34 + void operator=(const RCLock&); /* nor that */ 1.35 + 1.36 + PRLock *lock; 1.37 +}; /* RCLock */ 1.38 + 1.39 +/* 1.40 +** Class: RCEnter 1.41 +** 1.42 +** In scope locks. You can only allocate them on the stack. The language 1.43 +** will insure that they get released (by calling the destructor) when 1.44 +** the thread leaves scope, even if via an exception. 1.45 +*/ 1.46 +class PR_IMPLEMENT(RCEnter) 1.47 +{ 1.48 +public: 1.49 + ~RCEnter(); /* releases the lock */ 1.50 + RCEnter(RCLock*); /* acquires the lock */ 1.51 + 1.52 +private: 1.53 + RCLock *lock; 1.54 + 1.55 + RCEnter(); 1.56 + RCEnter(const RCEnter&); 1.57 + void operator=(const RCEnter&); 1.58 + 1.59 + void *operator new(PRSize) { return NULL; } 1.60 + void operator delete(void*) { } 1.61 +}; /* RCEnter */ 1.62 + 1.63 + 1.64 +inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); } 1.65 +inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; } 1.66 + 1.67 +#endif /* defined(_RCLOCK_H) */ 1.68 + 1.69 +/* RCLock.h */