blob: 82ae8af1e52676b4cc86bb0d7a7341c749adf8dc [file] [log] [blame]
Owen Anderson324f94c2009-06-16 20:19:28 +00001//= llvm/System/Win32/Mutex.inc - Win32 Reader/Writer Mutual Exclusion Lock =//
Michael J. Spencer447762d2010-11-29 18:16:10 +00002//
Owen Anderson324f94c2009-06-16 20:19:28 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer447762d2010-11-29 18:16:10 +00007//
Owen Anderson324f94c2009-06-16 20:19:28 +00008//===----------------------------------------------------------------------===//
9//
10// This file implements the Win32 specific (non-pthread) RWMutex 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
Michael J. Spencer447762d2010-11-29 18:16:10 +000019#include "Windows.h"
Owen Anderson324f94c2009-06-16 20:19:28 +000020
Owen Anderson74af4ee2009-06-17 09:10:42 +000021// FIXME: Windows does not have reader-writer locks pre-Vista. If you want
Michael J. Spencer447762d2010-11-29 18:16:10 +000022// real reader-writer locks, you a threads implementation for Windows.
Owen Anderson896cee72009-06-16 20:49:20 +000023
Owen Anderson324f94c2009-06-16 20:19:28 +000024namespace llvm {
25using namespace sys;
26
Owen Anderson1498a7a2009-06-18 18:26:15 +000027RWMutexImpl::RWMutexImpl() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000028 data_ = calloc(1, sizeof(CRITICAL_SECTION));
29 InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
30}
Owen Anderson324f94c2009-06-16 20:19:28 +000031
Owen Anderson1498a7a2009-06-18 18:26:15 +000032RWMutexImpl::~RWMutexImpl() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000033 DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
34 free(data_);
35}
Owen Anderson324f94c2009-06-16 20:19:28 +000036
Owen Anderson1498a7a2009-06-18 18:26:15 +000037bool RWMutexImpl::reader_acquire() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000038 EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
Owen Anderson324f94c2009-06-16 20:19:28 +000039 return true;
40}
41
Owen Anderson1498a7a2009-06-18 18:26:15 +000042bool RWMutexImpl::reader_release() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000043 LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
Owen Anderson324f94c2009-06-16 20:19:28 +000044 return true;
45}
46
Owen Anderson1498a7a2009-06-18 18:26:15 +000047bool RWMutexImpl::writer_acquire() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000048 EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
Owen Anderson324f94c2009-06-16 20:19:28 +000049 return true;
50}
51
Owen Anderson1498a7a2009-06-18 18:26:15 +000052bool RWMutexImpl::writer_release() {
Owen Anderson74af4ee2009-06-17 09:10:42 +000053 LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
Owen Anderson324f94c2009-06-16 20:19:28 +000054 return true;
55}
56
57
58}