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