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

Side by Side Diff: webrtc/system_wrappers/source/rw_lock_winxp_win.cc

Issue 1601523009: Remove ConditionVariableWrapper. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Move include inside guard 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
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 #include "webrtc/system_wrappers/source/rw_lock_winxp_win.h" 11 #include "webrtc/system_wrappers/source/rw_lock_winxp_win.h"
12 12
13 namespace webrtc { 13 namespace webrtc {
14 namespace {
15 class ScopedLock {
16 public:
17 ScopedLock(CRITICAL_SECTION* lock) : lock_(lock) {
18 EnterCriticalSection(lock_);
19 }
20 ~ScopedLock() {
21 LeaveCriticalSection(lock_);
22 }
23 private:
24 CRITICAL_SECTION* const lock_;
25 };
26 }
14 27
15 RWLockWinXP::RWLockWinXP() {} 28 RWLockWinXP::RWLockWinXP() {
16 RWLockWinXP::~RWLockWinXP() {} 29 InitializeCriticalSection(&critical_section_);
30 }
31
32 RWLockWinXP::~RWLockWinXP() {
33 DeleteCriticalSection(&critical_section_);
34 }
17 35
18 void RWLockWinXP::AcquireLockExclusive() { 36 void RWLockWinXP::AcquireLockExclusive() {
19 CriticalSectionScoped cs(&critical_section_); 37 ScopedLock cs(&critical_section_);
20 if (writer_active_ || readers_active_ > 0) { 38 if (writer_active_ || readers_active_ > 0) {
21 ++writers_waiting_; 39 ++writers_waiting_;
22 while (writer_active_ || readers_active_ > 0) { 40 while (writer_active_ || readers_active_ > 0) {
23 write_condition_.SleepCS(critical_section_); 41 write_condition_.SleepCS(&critical_section_);
24 } 42 }
25 --writers_waiting_; 43 --writers_waiting_;
26 } 44 }
27 writer_active_ = true; 45 writer_active_ = true;
28 } 46 }
29 47
30 void RWLockWinXP::ReleaseLockExclusive() { 48 void RWLockWinXP::ReleaseLockExclusive() {
31 CriticalSectionScoped cs(&critical_section_); 49 ScopedLock cs(&critical_section_);
32 writer_active_ = false; 50 writer_active_ = false;
33 if (writers_waiting_ > 0) { 51 if (writers_waiting_ > 0) {
34 write_condition_.Wake(); 52 write_condition_.Wake();
35 } else if (readers_waiting_ > 0) { 53 } else if (readers_waiting_ > 0) {
36 read_condition_.WakeAll(); 54 read_condition_.WakeAll();
37 } 55 }
38 } 56 }
39 57
40 void RWLockWinXP::AcquireLockShared() { 58 void RWLockWinXP::AcquireLockShared() {
41 CriticalSectionScoped cs(&critical_section_); 59 ScopedLock cs(&critical_section_);
42 if (writer_active_ || writers_waiting_ > 0) { 60 if (writer_active_ || writers_waiting_ > 0) {
43 ++readers_waiting_; 61 ++readers_waiting_;
44 62
45 while (writer_active_ || writers_waiting_ > 0) { 63 while (writer_active_ || writers_waiting_ > 0) {
46 read_condition_.SleepCS(critical_section_); 64 read_condition_.SleepCS(&critical_section_);
47 } 65 }
48 --readers_waiting_; 66 --readers_waiting_;
49 } 67 }
50 ++readers_active_; 68 ++readers_active_;
51 } 69 }
52 70
53 void RWLockWinXP::ReleaseLockShared() { 71 void RWLockWinXP::ReleaseLockShared() {
54 CriticalSectionScoped cs(&critical_section_); 72 ScopedLock cs(&critical_section_);
55 --readers_active_; 73 --readers_active_;
56 if (readers_active_ == 0 && writers_waiting_ > 0) { 74 if (readers_active_ == 0 && writers_waiting_ > 0) {
57 write_condition_.Wake(); 75 write_condition_.Wake();
58 } 76 }
59 } 77 }
60 78
61 } // namespace webrtc 79 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/source/rw_lock_winxp_win.h ('k') | webrtc/system_wrappers/system_wrappers.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698