Markus Handell | f70fbc8 | 2020-06-04 00:41:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | #ifndef RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ |
| 12 | #define RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ |
| 13 | |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame^] | 14 | #include "absl/base/attributes.h" |
Markus Handell | f70fbc8 | 2020-06-04 00:41:20 +0200 | [diff] [blame] | 15 | #include "absl/synchronization/mutex.h" |
| 16 | #include "rtc_base/thread_annotations.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class RTC_LOCKABLE MutexImpl final { |
| 21 | public: |
| 22 | MutexImpl() = default; |
| 23 | MutexImpl(const MutexImpl&) = delete; |
| 24 | MutexImpl& operator=(const MutexImpl&) = delete; |
| 25 | |
| 26 | void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { mutex_.Lock(); } |
Danil Chapovalov | 098da17 | 2021-01-14 16:15:31 +0100 | [diff] [blame^] | 27 | ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { |
Markus Handell | f70fbc8 | 2020-06-04 00:41:20 +0200 | [diff] [blame] | 28 | return mutex_.TryLock(); |
| 29 | } |
| 30 | void Unlock() RTC_UNLOCK_FUNCTION() { mutex_.Unlock(); } |
| 31 | |
| 32 | private: |
| 33 | absl::Mutex mutex_; |
| 34 | }; |
| 35 | |
| 36 | } // namespace webrtc |
| 37 | |
| 38 | #endif // RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ |