blob: 7fc4b33b1e9819a276b0c1365068f09dd9a0343d [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 Andersona8e47ae2009-06-17 09:10:42 +000027RWMutex::RWMutex() {
28 data_ = calloc(1, sizeof(CRITICAL_SECTION));
29 InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
30}
Owen Anderson0c2185a2009-06-16 20:19:28 +000031
Owen Andersona8e47ae2009-06-17 09:10:42 +000032RWMutex::~RWMutex() {
33 DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
34 free(data_);
35}
Owen Anderson0c2185a2009-06-16 20:19:28 +000036
37bool RWMutex::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
42bool RWMutex::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
47bool RWMutex::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
52bool RWMutex::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}