Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: webrtc/base/criticalsection.h

Issue 1611223002: Make rtc::CriticalSection lockable from f() const. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: comment Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/criticalsection.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/criticalsection.h
diff --git a/webrtc/base/criticalsection.h b/webrtc/base/criticalsection.h
index 5b3eaf56840cd1698701ac1669ccca9b3763c0b4..cc54eca1f0d4e7ddbbf9d5d201fdb83575950480 100644
--- a/webrtc/base/criticalsection.h
+++ b/webrtc/base/criticalsection.h
@@ -41,14 +41,17 @@
namespace rtc {
+// Locking methods (Enter, TryEnter, Leave)are const to permit protecting
+// members inside a const context without requiring mutable CriticalSections
+// everywhere.
class LOCKABLE CriticalSection {
public:
CriticalSection();
~CriticalSection();
- void Enter() EXCLUSIVE_LOCK_FUNCTION();
- bool TryEnter() EXCLUSIVE_TRYLOCK_FUNCTION(true);
- void Leave() UNLOCK_FUNCTION();
+ void Enter() const EXCLUSIVE_LOCK_FUNCTION();
+ bool TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true);
+ void Leave() const UNLOCK_FUNCTION();
// Use only for RTC_DCHECKing.
bool CurrentThreadIsOwner() const;
@@ -57,21 +60,21 @@ class LOCKABLE CriticalSection {
private:
#if defined(WEBRTC_WIN)
- CRITICAL_SECTION crit_;
+ mutable CRITICAL_SECTION crit_;
#elif defined(WEBRTC_POSIX)
- pthread_mutex_t mutex_;
- CS_DEBUG_CODE(pthread_t thread_);
- CS_DEBUG_CODE(int recursion_count_);
+ mutable pthread_mutex_t mutex_;
+ CS_DEBUG_CODE(mutable pthread_t thread_);
+ CS_DEBUG_CODE(mutable int recursion_count_);
#endif
};
// CritScope, for serializing execution through a scope.
class SCOPED_LOCKABLE CritScope {
public:
- explicit CritScope(CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs);
+ explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs);
~CritScope() UNLOCK_FUNCTION();
private:
- CriticalSection* const cs_;
+ const CriticalSection* const cs_;
RTC_DISALLOW_COPY_AND_ASSIGN(CritScope);
};
@@ -84,7 +87,7 @@ class SCOPED_LOCKABLE CritScope {
// lock was taken. If you're not calling locked(), you're doing it wrong!
class TryCritScope {
public:
- explicit TryCritScope(CriticalSection* cs);
+ explicit TryCritScope(const CriticalSection* cs);
~TryCritScope();
#if defined(WEBRTC_WIN)
_Check_return_ bool locked() const;
@@ -92,7 +95,7 @@ class TryCritScope {
bool locked() const __attribute__ ((__warn_unused_result__));
#endif
private:
- CriticalSection* const cs_;
+ const CriticalSection* const cs_;
const bool locked_;
CS_DEBUG_CODE(mutable bool lock_was_called_);
RTC_DISALLOW_COPY_AND_ASSIGN(TryCritScope);
« no previous file with comments | « no previous file | webrtc/base/criticalsection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698