2009-06-17 04:19:28 +08:00
|
|
|
//= llvm/System/Win32/Mutex.inc - Win32 Reader/Writer Mutual Exclusion Lock =//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Win32 specific (non-pthread) RWMutex class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Win32.h"
|
|
|
|
|
2009-06-17 17:10:42 +08:00
|
|
|
// FIXME: Windows does not have reader-writer locks pre-Vista. If you want
|
|
|
|
// real reader-writer locks, you a pthreads implementation for Windows.
|
2009-06-17 04:49:20 +08:00
|
|
|
|
2009-06-17 04:19:28 +08:00
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
RWMutexImpl::RWMutexImpl() {
|
2009-06-17 17:10:42 +08:00
|
|
|
data_ = calloc(1, sizeof(CRITICAL_SECTION));
|
|
|
|
InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
|
|
|
}
|
2009-06-17 04:19:28 +08:00
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
RWMutexImpl::~RWMutexImpl() {
|
2009-06-17 17:10:42 +08:00
|
|
|
DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
|
|
|
free(data_);
|
|
|
|
}
|
2009-06-17 04:19:28 +08:00
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
bool RWMutexImpl::reader_acquire() {
|
2009-06-17 17:10:42 +08:00
|
|
|
EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
2009-06-17 04:19:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
bool RWMutexImpl::reader_release() {
|
2009-06-17 17:10:42 +08:00
|
|
|
LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
2009-06-17 04:19:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
bool RWMutexImpl::writer_acquire() {
|
2009-06-17 17:10:42 +08:00
|
|
|
EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
2009-06-17 04:19:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:26:15 +08:00
|
|
|
bool RWMutexImpl::writer_release() {
|
2009-06-17 17:10:42 +08:00
|
|
|
LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
|
2009-06-17 04:19:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|