no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / mozglue / misc / RWLock_windows.cpp
blob2c347f218ca666e5f8f4118591f8dcf5acbfbe82
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 XP_WIN
8 # error This file should only be compiled on Windows.
9 #endif
11 #include "mozilla/PlatformRWLock.h"
13 #include <windows.h>
15 #define NativeHandle(m) (reinterpret_cast<SRWLOCK*>(&m))
17 mozilla::detail::RWLockImpl::RWLockImpl() {
18 static_assert(sizeof(SRWLOCK) <= sizeof(mRWLock), "SRWLOCK is too big!");
19 InitializeSRWLock(NativeHandle(mRWLock));
22 mozilla::detail::RWLockImpl::~RWLockImpl() {}
24 bool mozilla::detail::RWLockImpl::tryReadLock() {
25 return TryAcquireSRWLockShared(NativeHandle(mRWLock));
28 void mozilla::detail::RWLockImpl::readLock() {
29 AcquireSRWLockShared(NativeHandle(mRWLock));
32 void mozilla::detail::RWLockImpl::readUnlock() {
33 ReleaseSRWLockShared(NativeHandle(mRWLock));
36 bool mozilla::detail::RWLockImpl::tryWriteLock() {
37 return TryAcquireSRWLockExclusive(NativeHandle(mRWLock));
40 void mozilla::detail::RWLockImpl::writeLock() {
41 AcquireSRWLockExclusive(NativeHandle(mRWLock));
44 void mozilla::detail::RWLockImpl::writeUnlock() {
45 ReleaseSRWLockExclusive(NativeHandle(mRWLock));
48 #undef NativeHandle