blob: 439ce1a401a8fe30c1cc77a34293af3ed8286840 [file] [log] [blame]
Reid Spencerb2164e52005-07-12 15:37:43 +00001//===- llvm/System/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Jeff Cohen6d235222005-07-13 02:15:18 +00005// This file was developed by Jeff Cohen and is distributed under the
Reid Spencerb2164e52005-07-12 15:37:43 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
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
Jeff Cohen6d235222005-07-13 02:15:18 +000019#include "Win32.h"
20#include "llvm/System/Mutex.h"
21
22namespace llvm {
Reid Spencerb2164e52005-07-12 15:37:43 +000023using namespace sys;
24
Jeff Cohen6d235222005-07-13 02:15:18 +000025Mutex::Mutex(bool /*recursive*/)
Reid Spencerb2164e52005-07-12 15:37:43 +000026{
Jeff Cohen6d235222005-07-13 02:15:18 +000027 data_ = new CRITICAL_SECTION;
28 InitializeCriticalSection((LPCRITICAL_SECTION)data_);
Reid Spencerb2164e52005-07-12 15:37:43 +000029}
30
31Mutex::~Mutex()
32{
Jeff Cohen6d235222005-07-13 02:15:18 +000033 DeleteCriticalSection((LPCRITICAL_SECTION)data_);
34 data_ = 0;
Reid Spencerb2164e52005-07-12 15:37:43 +000035}
36
37bool
38Mutex::acquire()
39{
Jeff Cohen6d235222005-07-13 02:15:18 +000040 EnterCriticalSection((LPCRITICAL_SECTION)data_);
41 return true;
Reid Spencerb2164e52005-07-12 15:37:43 +000042}
43
44bool
45Mutex::release()
46{
Jeff Cohen6d235222005-07-13 02:15:18 +000047 LeaveCriticalSection((LPCRITICAL_SECTION)data_);
48 return true;
Reid Spencerb2164e52005-07-12 15:37:43 +000049}
50
51bool
Jeff Cohen6d235222005-07-13 02:15:18 +000052Mutex::tryacquire()
Reid Spencerb2164e52005-07-12 15:37:43 +000053{
Jeff Cohen6d235222005-07-13 02:15:18 +000054 return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
Reid Spencerb2164e52005-07-12 15:37:43 +000055}
56
57}