1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/AutoRwLock.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef RWLOCK_AUTO_ENTER_H 1.9 +#define RWLOCK_AUTO_ENTER_H 1.10 + 1.11 +#include "prrwlock.h" 1.12 +#include "mozilla/Assertions.h" 1.13 + 1.14 +class RwLockAutoEnterRead 1.15 +{ 1.16 +public: 1.17 + RwLockAutoEnterRead(PRRWLock* aRwLock) 1.18 + : mRwLock(aRwLock) 1.19 + { 1.20 + MOZ_ASSERT(mRwLock); 1.21 + PR_RWLock_Rlock(mRwLock); 1.22 + } 1.23 + 1.24 + ~RwLockAutoEnterRead() 1.25 + { 1.26 + PR_RWLock_Unlock(mRwLock); 1.27 + } 1.28 + 1.29 +protected: 1.30 + PRRWLock* mRwLock; 1.31 +}; 1.32 + 1.33 +class RwLockAutoEnterWrite 1.34 +{ 1.35 +public: 1.36 + RwLockAutoEnterWrite(PRRWLock* aRwLock) 1.37 + : mRwLock(aRwLock) 1.38 + { 1.39 + MOZ_ASSERT(mRwLock); 1.40 + PR_RWLock_Wlock(mRwLock); 1.41 + } 1.42 + 1.43 + ~RwLockAutoEnterWrite() 1.44 + { 1.45 + PR_RWLock_Unlock(mRwLock); 1.46 + } 1.47 + 1.48 +protected: 1.49 + PRRWLock* mRwLock; 1.50 +}; 1.51 + 1.52 +#endif // RWLOCK_AUTO_ENTER_H