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 #include "mozilla/Assertions.h"
8 #include "mozilla/DebugOnly.h"
9 #include "mozilla/PlatformMutex.h"
13 #include "MutexPlatformData_windows.h"
15 mozilla::detail::MutexImpl::MutexImpl() {
16 InitializeSRWLock(&platformData()->lock
);
19 mozilla::detail::MutexImpl::~MutexImpl() {}
21 void mozilla::detail::MutexImpl::lock() {
22 AcquireSRWLockExclusive(&platformData()->lock
);
25 bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }
27 bool mozilla::detail::MutexImpl::mutexTryLock() {
28 return !!TryAcquireSRWLockExclusive(&platformData()->lock
);
31 void mozilla::detail::MutexImpl::unlock() {
32 ReleaseSRWLockExclusive(&platformData()->lock
);
35 mozilla::detail::MutexImpl::PlatformData
*
36 mozilla::detail::MutexImpl::platformData() {
37 static_assert(sizeof(platformData_
) >= sizeof(PlatformData
),
38 "platformData_ is too small");
39 return reinterpret_cast<PlatformData
*>(platformData_
);