2005-07-12 15:37:43 +00:00
|
|
|
//===- llvm/System/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-07-13 02:15:18 +00:00
|
|
|
// This file was developed by Jeff Cohen and is distributed under the
|
2005-07-12 15:37:43 +00:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Win32 specific (non-pthread) Mutex class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-07-13 02:15:18 +00:00
|
|
|
#include "Win32.h"
|
|
|
|
#include "llvm/System/Mutex.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2005-07-12 15:37:43 +00:00
|
|
|
using namespace sys;
|
|
|
|
|
2005-07-13 02:15:18 +00:00
|
|
|
Mutex::Mutex(bool /*recursive*/)
|
2005-07-12 15:37:43 +00:00
|
|
|
{
|
2005-07-13 02:15:18 +00:00
|
|
|
data_ = new CRITICAL_SECTION;
|
|
|
|
InitializeCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-12 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Mutex::~Mutex()
|
|
|
|
{
|
2005-07-13 02:15:18 +00:00
|
|
|
DeleteCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-13 02:58:04 +00:00
|
|
|
delete (LPCRITICAL_SECTION)data_;
|
2005-07-13 02:15:18 +00:00
|
|
|
data_ = 0;
|
2005-07-12 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Mutex::acquire()
|
|
|
|
{
|
2005-07-13 02:15:18 +00:00
|
|
|
EnterCriticalSection((LPCRITICAL_SECTION)data_);
|
|
|
|
return true;
|
2005-07-12 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Mutex::release()
|
|
|
|
{
|
2005-07-13 02:15:18 +00:00
|
|
|
LeaveCriticalSection((LPCRITICAL_SECTION)data_);
|
|
|
|
return true;
|
2005-07-12 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2005-07-13 02:15:18 +00:00
|
|
|
Mutex::tryacquire()
|
2005-07-12 15:37:43 +00:00
|
|
|
{
|
2005-07-13 02:15:18 +00:00
|
|
|
return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-12 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|