Bug 1769628 [wpt PR 34081] - Update wpt metadata, a=testonly
[gecko.git] / mozglue / misc / PlatformRWLock.h
blob0acd09b25b8dd71368e559acb165ad2eb30d7cf0
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/. */
7 #ifndef mozilla_PlatformRWLock_h
8 #define mozilla_PlatformRWLock_h
10 #include "mozilla/Types.h"
12 #ifndef XP_WIN
13 # include <pthread.h>
14 #endif
16 namespace mozilla::detail {
18 class RWLockImpl {
19 public:
20 explicit MFBT_API RWLockImpl();
21 MFBT_API ~RWLockImpl();
23 protected:
24 [[nodiscard]] MFBT_API bool tryReadLock();
25 MFBT_API void readLock();
26 MFBT_API void readUnlock();
28 [[nodiscard]] MFBT_API bool tryWriteLock();
29 MFBT_API void writeLock();
30 MFBT_API void writeUnlock();
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;
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
48 } // namespace mozilla::detail
50 #endif // mozilla_PlatformRWLock_h