08c31f1eb7d2249b0e1ef4b16c1dbf039f935643
[oota-llvm.git] / lib / System / Win32 / RWMutex.inc
1 //= 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
21 namespace llvm {
22 using namespace sys;
23
24 RWMutex::RWMutex() {
25   data_ = new PSRWLOCK;
26   InitializeSRWLock((PSRWLOCK*)data_);
27 }
28
29 RWMutex::~RWMutex() {
30   delete (PSRWLOCK*)data_;
31   data_ = 0;
32 }
33
34 bool RWMutex::reader_acquire() {
35   AcquireSRWLockShared((PSRWLOCK*)data_);
36   return true;
37 }
38
39 bool RWMutex::reader_release() {
40   ReleaseSRWLockShared((PSRWLOCK*)data_);
41   return true;
42 }
43
44 bool RWMutex::writer_acquire() {
45   AcquireSRWLockExclusive((PSRWLOCK*)data_);
46   return true;
47 }
48
49 bool RWMutex::writer_release() {
50   ReleaseSRWLockExclusive((PSRWLOCK*)data_);
51   return true;
52 }
53
54
55 }