1 //===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Win32 specific (non-pthread) Mutex class.
11 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
14 //=== WARNING: Implementation here must contain only generic Win32 code that
15 //=== is guaranteed to work on *all* Win32 variants.
16 //===----------------------------------------------------------------------===//
18 #include "WindowsSupport.h"
19 #include "llvm/Support/Mutex.h"
23 sys::MutexImpl::MutexImpl(bool /*recursive*/)
25 data_ = new CRITICAL_SECTION;
26 InitializeCriticalSection((LPCRITICAL_SECTION)data_);
29 sys::MutexImpl::~MutexImpl()
31 DeleteCriticalSection((LPCRITICAL_SECTION)data_);
32 delete (LPCRITICAL_SECTION)data_;
37 sys::MutexImpl::acquire()
39 EnterCriticalSection((LPCRITICAL_SECTION)data_);
44 sys::MutexImpl::release()
46 LeaveCriticalSection((LPCRITICAL_SECTION)data_);
51 sys::MutexImpl::tryacquire()
53 return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);