Debian Codegraph @

mozglue/misc/Mutex_windows.cpp

raw
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 #include "mozilla/Assertions.h"
8 #include "mozilla/DebugOnly.h"
9 #include "mozilla/PlatformMutex.h"
10
11 #include <windows.h>
12
13 #include "MutexPlatformData_windows.h"
14
15 mozilla::detail::MutexImpl::MutexImpl() {
16 InitializeSRWLock(&platformData()->lock);
17 }
18
19 mozilla::detail::MutexImpl::~MutexImpl() {}
20
21 void mozilla::detail::MutexImpl::lock() {
22 AcquireSRWLockExclusive(&platformData()->lock);
23 }
24
25 bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }
26
27 bool mozilla::detail::MutexImpl::mutexTryLock() {
28 return !!TryAcquireSRWLockExclusive(&platformData()->lock);
29 }
30
31 void mozilla::detail::MutexImpl::unlock() {
32 ReleaseSRWLockExclusive(&platformData()->lock);
33 }
34
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_);
40 }