| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef RTC_BASE_SYNCHRONIZATION_MUTEX_CRITICAL_SECTION_H_ |
| 12 |
#define RTC_BASE_SYNCHRONIZATION_MUTEX_CRITICAL_SECTION_H_ |
| 13 |
|
| 14 |
#if defined(WEBRTC_WIN) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <winsock2.h> |
| 22 |
#include <windows.h> |
| 23 |
#include <sal.h> |
| 24 |
|
| 25 |
|
| 26 |
#include "absl/base/attributes.h" |
| 27 |
#include "rtc_base/thread_annotations.h" |
| 28 |
|
| 29 |
namespace webrtc { |
| 30 |
|
| 31 |
class RTC_LOCKABLE MutexImpl final { |
| 32 |
public: |
| 33 |
MutexImpl() { InitializeCriticalSection(&critical_section_); } |
| 34 |
MutexImpl(const MutexImpl&) = delete; |
| 35 |
MutexImpl& operator=(const MutexImpl&) = delete; |
| 36 |
~MutexImpl() { DeleteCriticalSection(&critical_section_); } |
| 37 |
|
| 38 |
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { |
| 39 |
EnterCriticalSection(&critical_section_); |
| 40 |
} |
| 41 |
ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { |
| 42 |
return TryEnterCriticalSection(&critical_section_) != FALSE; |
| 43 |
} |
| 44 |
void Unlock() RTC_UNLOCK_FUNCTION() { |
| 45 |
LeaveCriticalSection(&critical_section_); |
| 46 |
} |
| 47 |
|
| 48 |
private: |
| 49 |
CRITICAL_SECTION critical_section_; |
| 50 |
}; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
#endif |
| 55 |
#endif |