mutex_abseil.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #ifndef RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_
  11. #define RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_
  12. #include "absl/synchronization/mutex.h"
  13. #include "rtc_base/thread_annotations.h"
  14. namespace webrtc {
  15. class RTC_LOCKABLE MutexImpl final {
  16. public:
  17. MutexImpl() = default;
  18. MutexImpl(const MutexImpl&) = delete;
  19. MutexImpl& operator=(const MutexImpl&) = delete;
  20. void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { mutex_.Lock(); }
  21. RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
  22. return mutex_.TryLock();
  23. }
  24. void Unlock() RTC_UNLOCK_FUNCTION() { mutex_.Unlock(); }
  25. private:
  26. absl::Mutex mutex_;
  27. };
  28. } // namespace webrtc
  29. #endif // RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_