blob: 0a4bc4b75149d04f1fc289d03de906cb102ba6c1 [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_);
Jeff Cohen24972512005-07-13 02:58:04 +000034 delete (LPCRITICAL_SECTION)data_;
Jeff Cohen6d235222005-07-13 02:15:18 +000035 data_ = 0;
Reid Spencerb2164e52005-07-12 15:37:43 +000036}
37
38bool
39Mutex::acquire()
40{
Jeff Cohen6d235222005-07-13 02:15:18 +000041 EnterCriticalSection((LPCRITICAL_SECTION)data_);
42 return true;
Reid Spencerb2164e52005-07-12 15:37:43 +000043}
44
45bool
46Mutex::release()
47{
Jeff Cohen6d235222005-07-13 02:15:18 +000048 LeaveCriticalSection((LPCRITICAL_SECTION)data_);
49 return true;
Reid Spencerb2164e52005-07-12 15:37:43 +000050}
51
52bool
Jeff Cohen6d235222005-07-13 02:15:18 +000053Mutex::tryacquire()
Reid Spencerb2164e52005-07-12 15:37:43 +000054{
Jeff Cohen6d235222005-07-13 02:15:18 +000055 return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
Reid Spencerb2164e52005-07-12 15:37:43 +000056}
57
58}