tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Mutex_windows.cpp (1193B)


      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/PlatformMutex.h"
      8 
      9 #include <windows.h>
     10 
     11 #include "MutexPlatformData_windows.h"
     12 
     13 mozilla::detail::MutexImpl::MutexImpl() {
     14  InitializeSRWLock(&platformData()->lock);
     15 }
     16 
     17 mozilla::detail::MutexImpl::~MutexImpl() {}
     18 
     19 void mozilla::detail::MutexImpl::lock() {
     20  AcquireSRWLockExclusive(&platformData()->lock);
     21 }
     22 
     23 bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }
     24 
     25 bool mozilla::detail::MutexImpl::mutexTryLock() {
     26  return !!TryAcquireSRWLockExclusive(&platformData()->lock);
     27 }
     28 
     29 void mozilla::detail::MutexImpl::unlock() {
     30  ReleaseSRWLockExclusive(&platformData()->lock);
     31 }
     32 
     33 mozilla::detail::MutexImpl::PlatformData*
     34 mozilla::detail::MutexImpl::platformData() {
     35  static_assert(sizeof(platformData_) >= sizeof(PlatformData),
     36                "platformData_ is too small");
     37  return reinterpret_cast<PlatformData*>(platformData_);
     38 }