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

Side by Side Diff: webrtc/system_wrappers/include/critical_section_wrapper.h

Issue 1614373002: Remove implementation of CriticalSectionWrapper and use rtc::CriticalSection (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix impl 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 unified diff | Download patch
« no previous file with comments | « webrtc/system_wrappers/BUILD.gn ('k') | webrtc/system_wrappers/source/critical_section.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ 11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ 12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
13 13
14 // If the critical section is heavily contended it may be beneficial to use 14 #include "webrtc/base/criticalsection.h"
15 // read/write locks instead.
16
17 #if defined (WEBRTC_WIN)
18 #include <windows.h>
19 #else
20 #include <pthread.h>
21 #endif
22
23 #include "webrtc/base/thread_annotations.h" 15 #include "webrtc/base/thread_annotations.h"
24 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
25 17
26 namespace webrtc { 18 namespace webrtc {
27 19
28 class LOCKABLE CriticalSectionWrapper { 20 class LOCKABLE CriticalSectionWrapper {
29 public: 21 public:
30 // Legacy factory method, being deprecated. Please use the constructor. 22 // Legacy factory method, being deprecated. Please use the constructor.
31 // TODO(tommi): Remove the CriticalSectionWrapper class and move users over 23 // TODO(tommi): Remove the CriticalSectionWrapper class and move users over
32 // to using rtc::CriticalSection. Before we can do that though, we need to 24 // to using rtc::CriticalSection.
33 // fix the problem with the ConditionVariable* classes (see below). 25 static CriticalSectionWrapper* CreateCriticalSection() {
34 static CriticalSectionWrapper* CreateCriticalSection(); 26 return new CriticalSectionWrapper();
27 }
35 28
36 CriticalSectionWrapper(); 29 CriticalSectionWrapper() {}
37 ~CriticalSectionWrapper(); 30 ~CriticalSectionWrapper() {}
38 31
39 // Tries to grab lock, beginning of a critical section. Will wait for the 32 // Tries to grab lock, beginning of a critical section. Will wait for the
40 // lock to become available if the grab failed. 33 // lock to become available if the grab failed.
41 void Enter() EXCLUSIVE_LOCK_FUNCTION(); 34 void Enter() EXCLUSIVE_LOCK_FUNCTION() { lock_.Enter(); }
42 35
43 // Returns a grabbed lock, end of critical section. 36 // Returns a grabbed lock, end of critical section.
44 void Leave() UNLOCK_FUNCTION(); 37 void Leave() UNLOCK_FUNCTION() { lock_.Leave(); }
45 38
46 private: 39 private:
47 #if defined (WEBRTC_WIN) 40 rtc::CriticalSection lock_;
48 CRITICAL_SECTION crit_;
49 #else
50 pthread_mutex_t mutex_;
51 #endif
52 }; 41 };
53 42
54 // RAII extension of the critical section. Prevents Enter/Leave mismatches and 43 // RAII extension of the critical section. Prevents Enter/Leave mismatches and
55 // provides more compact critical section syntax. 44 // provides more compact critical section syntax.
56 class SCOPED_LOCKABLE CriticalSectionScoped { 45 class SCOPED_LOCKABLE CriticalSectionScoped {
57 public: 46 public:
58 explicit CriticalSectionScoped(CriticalSectionWrapper* critsec) 47 explicit CriticalSectionScoped(CriticalSectionWrapper* critsec)
59 EXCLUSIVE_LOCK_FUNCTION(critsec) 48 EXCLUSIVE_LOCK_FUNCTION(critsec)
60 : ptr_crit_sec_(critsec) { 49 : ptr_crit_sec_(critsec) {
61 ptr_crit_sec_->Enter(); 50 ptr_crit_sec_->Enter();
62 } 51 }
63 52
64 ~CriticalSectionScoped() UNLOCK_FUNCTION() { ptr_crit_sec_->Leave(); } 53 ~CriticalSectionScoped() UNLOCK_FUNCTION() { ptr_crit_sec_->Leave(); }
65 54
66 private: 55 private:
67 CriticalSectionWrapper* ptr_crit_sec_; 56 CriticalSectionWrapper* ptr_crit_sec_;
68 }; 57 };
69 58
70 } // namespace webrtc 59 } // namespace webrtc
71 60
72 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ 61 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/BUILD.gn ('k') | webrtc/system_wrappers/source/critical_section.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698