2010-11-29 20:44:50 +01:00
|
|
|
//===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
|
2010-11-29 19:16:10 +01:00
|
|
|
//
|
2005-07-12 17:37:43 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2010-11-29 19:16:10 +01:00
|
|
|
//
|
2005-07-12 17:37:43 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-02-12 22:26:20 +01:00
|
|
|
#include "WindowsSupport.h"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2005-07-13 04:15:18 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2005-07-12 17:37:43 +02:00
|
|
|
using namespace sys;
|
|
|
|
|
2009-06-18 19:53:17 +02:00
|
|
|
MutexImpl::MutexImpl(bool /*recursive*/)
|
2005-07-12 17:37:43 +02:00
|
|
|
{
|
2005-07-13 04:15:18 +02:00
|
|
|
data_ = new CRITICAL_SECTION;
|
|
|
|
InitializeCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-12 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
2009-06-18 19:53:17 +02:00
|
|
|
MutexImpl::~MutexImpl()
|
2005-07-12 17:37:43 +02:00
|
|
|
{
|
2005-07-13 04:15:18 +02:00
|
|
|
DeleteCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-13 04:58:04 +02:00
|
|
|
delete (LPCRITICAL_SECTION)data_;
|
2005-07-13 04:15:18 +02:00
|
|
|
data_ = 0;
|
2005-07-12 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
2010-11-29 19:16:10 +01:00
|
|
|
bool
|
2009-06-18 19:53:17 +02:00
|
|
|
MutexImpl::acquire()
|
2005-07-12 17:37:43 +02:00
|
|
|
{
|
2005-07-13 04:15:18 +02:00
|
|
|
EnterCriticalSection((LPCRITICAL_SECTION)data_);
|
|
|
|
return true;
|
2005-07-12 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
2010-11-29 19:16:10 +01:00
|
|
|
bool
|
2009-06-18 19:53:17 +02:00
|
|
|
MutexImpl::release()
|
2005-07-12 17:37:43 +02:00
|
|
|
{
|
2005-07-13 04:15:18 +02:00
|
|
|
LeaveCriticalSection((LPCRITICAL_SECTION)data_);
|
|
|
|
return true;
|
2005-07-12 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
2010-11-29 19:16:10 +01:00
|
|
|
bool
|
2009-06-18 19:53:17 +02:00
|
|
|
MutexImpl::tryacquire()
|
2005-07-12 17:37:43 +02:00
|
|
|
{
|
2005-07-13 04:15:18 +02:00
|
|
|
return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
|
2005-07-12 17:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|