From 59ad541e57c3e72b3708ebc55fb8a3200659a6ad Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Tue, 18 Dec 2012 15:20:35 +0000 Subject: [PATCH] Reformatted rw_lock classes. BUG= TEST=Trybots. Review URL: https://webrtc-codereview.appspot.com/1007004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3305 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../interface/rw_lock_wrapper.h | 75 +++++++++---------- webrtc/system_wrappers/source/rw_lock.cc | 8 +- .../system_wrappers/source/rw_lock_generic.cc | 6 +- .../system_wrappers/source/rw_lock_generic.h | 32 ++++---- .../system_wrappers/source/rw_lock_posix.cc | 16 ++-- webrtc/system_wrappers/source/rw_lock_posix.h | 27 ++++--- webrtc/system_wrappers/source/rw_lock_win.cc | 28 +++---- webrtc/system_wrappers/source/rw_lock_win.h | 8 +- 8 files changed, 96 insertions(+), 104 deletions(-) diff --git a/webrtc/system_wrappers/interface/rw_lock_wrapper.h b/webrtc/system_wrappers/interface/rw_lock_wrapper.h index 572820273..91305c152 100644 --- a/webrtc/system_wrappers/interface/rw_lock_wrapper.h +++ b/webrtc/system_wrappers/interface/rw_lock_wrapper.h @@ -11,65 +11,58 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ -// Note, Windows pre-Vista version of RW locks are not supported nativly. For +// Note, Windows pre-Vista version of RW locks are not supported natively. For // these OSs regular critical sections have been used to approximate RW lock // functionality and will therefore have worse performance. namespace webrtc { -class RWLockWrapper -{ -public: - static RWLockWrapper* CreateRWLock(); - virtual ~RWLockWrapper() {} +class RWLockWrapper { + public: + static RWLockWrapper* CreateRWLock(); + virtual ~RWLockWrapper() {} - virtual void AcquireLockExclusive() = 0; - virtual void ReleaseLockExclusive() = 0; + virtual void AcquireLockExclusive() = 0; + virtual void ReleaseLockExclusive() = 0; - virtual void AcquireLockShared() = 0; - virtual void ReleaseLockShared() = 0; + virtual void AcquireLockShared() = 0; + virtual void ReleaseLockShared() = 0; }; // RAII extensions of the RW lock. Prevents Acquire/Release missmatches and // provides more compact locking syntax. -class ReadLockScoped -{ -public: - ReadLockScoped(RWLockWrapper& rwLock) - : - _rwLock(rwLock) - { - _rwLock.AcquireLockShared(); - } +class ReadLockScoped { + public: + ReadLockScoped(RWLockWrapper& rw_lock) + : + rw_lock_(rw_lock) { + rw_lock_.AcquireLockShared(); + } - ~ReadLockScoped() - { - _rwLock.ReleaseLockShared(); - } + ~ReadLockScoped() { + rw_lock_.ReleaseLockShared(); + } -private: - RWLockWrapper& _rwLock; + private: + RWLockWrapper& rw_lock_; }; -class WriteLockScoped -{ -public: - WriteLockScoped(RWLockWrapper& rwLock) - : - _rwLock(rwLock) - { - _rwLock.AcquireLockExclusive(); - } +class WriteLockScoped { + public: + WriteLockScoped(RWLockWrapper& rw_lock) + : + rw_lock_(rw_lock) { + rw_lock_.AcquireLockExclusive(); + } - ~WriteLockScoped() - { - _rwLock.ReleaseLockExclusive(); - } + ~WriteLockScoped() { + rw_lock_.ReleaseLockExclusive(); + } -private: - RWLockWrapper& _rwLock; + private: + RWLockWrapper& rw_lock_; }; } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ diff --git a/webrtc/system_wrappers/source/rw_lock.cc b/webrtc/system_wrappers/source/rw_lock.cc index d3134684f..8b76eb861 100644 --- a/webrtc/system_wrappers/source/rw_lock.cc +++ b/webrtc/system_wrappers/source/rw_lock.cc @@ -8,15 +8,15 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "rw_lock_wrapper.h" +#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" #include #if defined(_WIN32) -#include "rw_lock_generic.h" -#include "rw_lock_win.h" +#include "webrtc/system_wrappers/source/rw_lock_generic.h" +#include "webrtc/system_wrappers/source/rw_lock_win.h" #else -#include "rw_lock_posix.h" +#include "webrtc/system_wrappers/source/rw_lock_posix.h" #endif namespace webrtc { diff --git a/webrtc/system_wrappers/source/rw_lock_generic.cc b/webrtc/system_wrappers/source/rw_lock_generic.cc index 21e9a3759..0ca951874 100644 --- a/webrtc/system_wrappers/source/rw_lock_generic.cc +++ b/webrtc/system_wrappers/source/rw_lock_generic.cc @@ -8,10 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "system_wrappers/source/rw_lock_generic.h" +#include "webrtc/system_wrappers/source/rw_lock_generic.h" -#include "system_wrappers/interface/condition_variable_wrapper.h" -#include "system_wrappers/interface/critical_section_wrapper.h" +#include "webrtc/system_wrappers/interface/condition_variable_wrapper.h" +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { diff --git a/webrtc/system_wrappers/source/rw_lock_generic.h b/webrtc/system_wrappers/source/rw_lock_generic.h index d81b8f0f3..cd5848f43 100644 --- a/webrtc/system_wrappers/source/rw_lock_generic.h +++ b/webrtc/system_wrappers/source/rw_lock_generic.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_GENERIC_H_ #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_GENERIC_H_ -#include "system_wrappers/interface/rw_lock_wrapper.h" +#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" namespace webrtc { @@ -19,25 +19,25 @@ class CriticalSectionWrapper; class ConditionVariableWrapper; class RWLockGeneric : public RWLockWrapper { -public: - RWLockGeneric(); - virtual ~RWLockGeneric(); + public: + RWLockGeneric(); + virtual ~RWLockGeneric(); - virtual void AcquireLockExclusive(); - virtual void ReleaseLockExclusive(); + virtual void AcquireLockExclusive(); + virtual void ReleaseLockExclusive(); - virtual void AcquireLockShared(); - virtual void ReleaseLockShared(); + virtual void AcquireLockShared(); + virtual void ReleaseLockShared(); -private: - CriticalSectionWrapper* critical_section_; - ConditionVariableWrapper* read_condition_; - ConditionVariableWrapper* write_condition_; + private: + CriticalSectionWrapper* critical_section_; + ConditionVariableWrapper* read_condition_; + ConditionVariableWrapper* write_condition_; - int readers_active_; - bool writer_active_; - int readers_waiting_; - int writers_waiting_; + int readers_active_; + bool writer_active_; + int readers_waiting_; + int writers_waiting_; }; } // namespace webrtc diff --git a/webrtc/system_wrappers/source/rw_lock_posix.cc b/webrtc/system_wrappers/source/rw_lock_posix.cc index f21e0b043..cdcb7fb5b 100644 --- a/webrtc/system_wrappers/source/rw_lock_posix.cc +++ b/webrtc/system_wrappers/source/rw_lock_posix.cc @@ -8,15 +8,15 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "system_wrappers/source/rw_lock_posix.h" +#include "webrtc/system_wrappers/source/rw_lock_posix.h" namespace webrtc { -RWLockPosix::RWLockPosix() : _lock() { +RWLockPosix::RWLockPosix() : lock_() { } RWLockPosix::~RWLockPosix() { - pthread_rwlock_destroy(&_lock); + pthread_rwlock_destroy(&lock_); } RWLockPosix* RWLockPosix::Create() { @@ -29,23 +29,23 @@ RWLockPosix* RWLockPosix::Create() { } bool RWLockPosix::Init() { - return pthread_rwlock_init(&_lock, 0) == 0; + return pthread_rwlock_init(&lock_, 0) == 0; } void RWLockPosix::AcquireLockExclusive() { - pthread_rwlock_wrlock(&_lock); + pthread_rwlock_wrlock(&lock_); } void RWLockPosix::ReleaseLockExclusive() { - pthread_rwlock_unlock(&_lock); + pthread_rwlock_unlock(&lock_); } void RWLockPosix::AcquireLockShared() { - pthread_rwlock_rdlock(&_lock); + pthread_rwlock_rdlock(&lock_); } void RWLockPosix::ReleaseLockShared() { - pthread_rwlock_unlock(&_lock); + pthread_rwlock_unlock(&lock_); } } // namespace webrtc diff --git a/webrtc/system_wrappers/source/rw_lock_posix.h b/webrtc/system_wrappers/source/rw_lock_posix.h index 930e7cc10..a56ae12d5 100644 --- a/webrtc/system_wrappers/source/rw_lock_posix.h +++ b/webrtc/system_wrappers/source/rw_lock_posix.h @@ -11,29 +11,28 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_POSIX_H_ #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_POSIX_H_ -#include "system_wrappers/interface/rw_lock_wrapper.h" +#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" #include namespace webrtc { -class RWLockPosix : public RWLockWrapper -{ -public: - static RWLockPosix* Create(); - virtual ~RWLockPosix(); +class RWLockPosix : public RWLockWrapper { + public: + static RWLockPosix* Create(); + virtual ~RWLockPosix(); - virtual void AcquireLockExclusive(); - virtual void ReleaseLockExclusive(); + virtual void AcquireLockExclusive(); + virtual void ReleaseLockExclusive(); - virtual void AcquireLockShared(); - virtual void ReleaseLockShared(); + virtual void AcquireLockShared(); + virtual void ReleaseLockShared(); -private: - RWLockPosix(); - bool Init(); + private: + RWLockPosix(); + bool Init(); - pthread_rwlock_t _lock; + pthread_rwlock_t lock_; }; } // namespace webrtc diff --git a/webrtc/system_wrappers/source/rw_lock_win.cc b/webrtc/system_wrappers/source/rw_lock_win.cc index f0333b82b..aea74fa4a 100644 --- a/webrtc/system_wrappers/source/rw_lock_win.cc +++ b/webrtc/system_wrappers/source/rw_lock_win.cc @@ -8,9 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "system_wrappers/source/rw_lock_win.h" +#include "webrtc/system_wrappers/source/rw_lock_win.h" -#include "trace.h" +#include "webrtc/system_wrappers/interface/trace.h" namespace webrtc { @@ -18,13 +18,13 @@ static bool native_rw_locks_supported = false; static bool module_load_attempted = false; static HMODULE library = NULL; -typedef void (WINAPI *InitializeSRWLock)(PSRWLOCK); +typedef void (WINAPI* InitializeSRWLock)(PSRWLOCK); -typedef void (WINAPI *AcquireSRWLockExclusive)(PSRWLOCK); -typedef void (WINAPI *ReleaseSRWLockExclusive)(PSRWLOCK); +typedef void (WINAPI* AcquireSRWLockExclusive)(PSRWLOCK); +typedef void (WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK); -typedef void (WINAPI *AcquireSRWLockShared)(PSRWLOCK); -typedef void (WINAPI *ReleaseSRWLockShared)(PSRWLOCK); +typedef void (WINAPI* AcquireSRWLockShared)(PSRWLOCK); +typedef void (WINAPI* ReleaseSRWLockShared)(PSRWLOCK); InitializeSRWLock initialize_srw_lock; AcquireSRWLockExclusive acquire_srw_lock_exclusive; @@ -72,18 +72,18 @@ bool RWLockWin::LoadModule() { WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, "Loaded Kernel.dll"); initialize_srw_lock = - (InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock"); + (InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock"); acquire_srw_lock_exclusive = - (AcquireSRWLockExclusive)GetProcAddress(library, - "AcquireSRWLockExclusive"); + (AcquireSRWLockExclusive)GetProcAddress(library, + "AcquireSRWLockExclusive"); release_srw_lock_exclusive = - (ReleaseSRWLockExclusive)GetProcAddress(library, - "ReleaseSRWLockExclusive"); + (ReleaseSRWLockExclusive)GetProcAddress(library, + "ReleaseSRWLockExclusive"); acquire_srw_lock_shared = - (AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared"); + (AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared"); release_srw_lock_shared = - (ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared"); + (ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared"); if (initialize_srw_lock && acquire_srw_lock_exclusive && release_srw_lock_exclusive && acquire_srw_lock_shared && diff --git a/webrtc/system_wrappers/source/rw_lock_win.h b/webrtc/system_wrappers/source/rw_lock_win.h index bc052e410..6f7cd3344 100644 --- a/webrtc/system_wrappers/source/rw_lock_win.h +++ b/webrtc/system_wrappers/source/rw_lock_win.h @@ -8,10 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN__H_ -#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN__H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN_H_ +#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN_H_ -#include "system_wrappers/interface/rw_lock_wrapper.h" +#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" #include @@ -37,4 +37,4 @@ class RWLockWin : public RWLockWrapper { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN__H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WIN_H_