| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/system_wrappers/source/rw_lock_winxp_win.h" | |
| 12 | |
| 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 } | |
| 27 | |
| 28 RWLockWinXP::RWLockWinXP() { | |
| 29 InitializeCriticalSection(&critical_section_); | |
| 30 } | |
| 31 | |
| 32 RWLockWinXP::~RWLockWinXP() { | |
| 33 DeleteCriticalSection(&critical_section_); | |
| 34 } | |
| 35 | |
| 36 void RWLockWinXP::AcquireLockExclusive() { | |
| 37 ScopedLock cs(&critical_section_); | |
| 38 if (writer_active_ || readers_active_ > 0) { | |
| 39 ++writers_waiting_; | |
| 40 while (writer_active_ || readers_active_ > 0) { | |
| 41 write_condition_.SleepCS(&critical_section_); | |
| 42 } | |
| 43 --writers_waiting_; | |
| 44 } | |
| 45 writer_active_ = true; | |
| 46 } | |
| 47 | |
| 48 void RWLockWinXP::ReleaseLockExclusive() { | |
| 49 ScopedLock cs(&critical_section_); | |
| 50 writer_active_ = false; | |
| 51 if (writers_waiting_ > 0) { | |
| 52 write_condition_.Wake(); | |
| 53 } else if (readers_waiting_ > 0) { | |
| 54 read_condition_.WakeAll(); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 void RWLockWinXP::AcquireLockShared() { | |
| 59 ScopedLock cs(&critical_section_); | |
| 60 if (writer_active_ || writers_waiting_ > 0) { | |
| 61 ++readers_waiting_; | |
| 62 | |
| 63 while (writer_active_ || writers_waiting_ > 0) { | |
| 64 read_condition_.SleepCS(&critical_section_); | |
| 65 } | |
| 66 --readers_waiting_; | |
| 67 } | |
| 68 ++readers_active_; | |
| 69 } | |
| 70 | |
| 71 void RWLockWinXP::ReleaseLockShared() { | |
| 72 ScopedLock cs(&critical_section_); | |
| 73 --readers_active_; | |
| 74 if (readers_active_ == 0 && writers_waiting_ > 0) { | |
| 75 write_condition_.Wake(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 } // namespace webrtc | |
| OLD | NEW |