edcbd52f5f377b516f633df28b3ad9a61afad72a
[oota-llvm.git] / lib / Support / Unix / RWMutex.inc
1 //= llvm/Support/Unix/RWMutex.inc - Unix 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 Unix specific (non-pthread) RWMutex class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //===          is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18
19 #include "llvm/Support/Mutex.h"
20
21 namespace llvm {
22
23 using namespace sys;
24
25 // This naive implementation treats readers the same as writers.  This
26 // will therefore deadlock if a thread tries to acquire a read lock
27 // multiple times.
28
29 RWMutexImpl::RWMutexImpl() : data_(new Mutex(false)) { }
30
31 RWMutexImpl::~RWMutexImpl() {
32   delete static_cast<Mutex *>(data_);
33 }
34
35 bool RWMutexImpl::reader_acquire() {
36   return static_cast<Mutex *>(data_)->acquire();
37 }
38
39 bool RWMutexImpl::reader_release() {
40   return static_cast<Mutex *>(data_)->release();
41 }
42
43 bool RWMutexImpl::writer_acquire() {
44   return static_cast<Mutex *>(data_)->acquire();
45 }
46
47 bool RWMutexImpl::writer_release() {
48   return static_cast<Mutex *>(data_)->release();
49 }
50
51 }