blob: 0af145ec9a4e6c6c61dcf8fd98d9aa39912e744c [file] [log] [blame]
Charles Davis54c9eb62010-11-29 19:44:50 +00001//===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
Michael J. Spencer447762d2010-11-29 18:16:10 +00002//
Reid Spencerf4049812005-07-12 15:37:43 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer447762d2010-11-29 18:16:10 +00007//
Reid Spencerf4049812005-07-12 15:37:43 +00008//===----------------------------------------------------------------------===//
9//
10// This file implements the Win32 specific (non-pthread) Mutex class.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15//=== WARNING: Implementation here must contain only generic Win32 code that
16//=== is guaranteed to work on *all* Win32 variants.
17//===----------------------------------------------------------------------===//
18
Reid Klecknerd59e2fa2014-02-12 21:26:20 +000019#include "WindowsSupport.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000020#include "llvm/Support/Mutex.h"
Jeff Cohen3800a282005-07-13 02:15:18 +000021
22namespace llvm {
Reid Spencerf4049812005-07-12 15:37:43 +000023
Kristof Beylsa11dbf22017-03-31 14:26:44 +000024sys::MutexImpl::MutexImpl(bool /*recursive*/)
Reid Spencerf4049812005-07-12 15:37:43 +000025{
Jeff Cohen3800a282005-07-13 02:15:18 +000026 data_ = new CRITICAL_SECTION;
27 InitializeCriticalSection((LPCRITICAL_SECTION)data_);
Reid Spencerf4049812005-07-12 15:37:43 +000028}
29
Kristof Beylsa11dbf22017-03-31 14:26:44 +000030sys::MutexImpl::~MutexImpl()
Reid Spencerf4049812005-07-12 15:37:43 +000031{
Jeff Cohen3800a282005-07-13 02:15:18 +000032 DeleteCriticalSection((LPCRITICAL_SECTION)data_);
Jeff Cohen65806e62005-07-13 02:58:04 +000033 delete (LPCRITICAL_SECTION)data_;
Jeff Cohen3800a282005-07-13 02:15:18 +000034 data_ = 0;
Reid Spencerf4049812005-07-12 15:37:43 +000035}
36
Michael J. Spencer447762d2010-11-29 18:16:10 +000037bool
Kristof Beylsa11dbf22017-03-31 14:26:44 +000038sys::MutexImpl::acquire()
Reid Spencerf4049812005-07-12 15:37:43 +000039{
Jeff Cohen3800a282005-07-13 02:15:18 +000040 EnterCriticalSection((LPCRITICAL_SECTION)data_);
41 return true;
Reid Spencerf4049812005-07-12 15:37:43 +000042}
43
Michael J. Spencer447762d2010-11-29 18:16:10 +000044bool
Kristof Beylsa11dbf22017-03-31 14:26:44 +000045sys::MutexImpl::release()
Reid Spencerf4049812005-07-12 15:37:43 +000046{
Jeff Cohen3800a282005-07-13 02:15:18 +000047 LeaveCriticalSection((LPCRITICAL_SECTION)data_);
48 return true;
Reid Spencerf4049812005-07-12 15:37:43 +000049}
50
Michael J. Spencer447762d2010-11-29 18:16:10 +000051bool
Kristof Beylsa11dbf22017-03-31 14:26:44 +000052sys::MutexImpl::tryacquire()
Reid Spencerf4049812005-07-12 15:37:43 +000053{
Jeff Cohen3800a282005-07-13 02:15:18 +000054 return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
Reid Spencerf4049812005-07-12 15:37:43 +000055}
56
57}