PlatformRWLock.h (1316B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_PlatformRWLock_h 8 #define mozilla_PlatformRWLock_h 9 10 #include "mozilla/Types.h" 11 12 #ifndef XP_WIN 13 # include <pthread.h> 14 #endif 15 16 namespace mozilla::detail { 17 18 class RWLockImpl { 19 public: 20 explicit MFBT_API RWLockImpl(); 21 MFBT_API ~RWLockImpl(); 22 23 protected: 24 [[nodiscard]] MFBT_API bool tryReadLock(); 25 MFBT_API void readLock(); 26 MFBT_API void readUnlock(); 27 28 [[nodiscard]] MFBT_API bool tryWriteLock(); 29 MFBT_API void writeLock(); 30 MFBT_API void writeUnlock(); 31 32 private: 33 RWLockImpl(const RWLockImpl&) = delete; 34 void operator=(const RWLockImpl&) = delete; 35 RWLockImpl(RWLockImpl&&) = delete; 36 void operator=(RWLockImpl&&) = delete; 37 bool operator==(const RWLockImpl& rhs) = delete; 38 39 #ifndef XP_WIN 40 pthread_rwlock_t mRWLock; 41 #else 42 // SRWLock is pointer-sized. We declare it in such a fashion here to avoid 43 // pulling in windows.h wherever this header is used. 44 void* mRWLock; 45 #endif 46 }; 47 48 } // namespace mozilla::detail 49 50 #endif // mozilla_PlatformRWLock_h