RWMutex.inc revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
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
21namespace llvm {
22
23using 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
29RWMutexImpl::RWMutexImpl() : data_(new Mutex(false)) { }
30
31RWMutexImpl::~RWMutexImpl() {
32  delete static_cast<Mutex *>(data_);
33}
34
35bool RWMutexImpl::reader_acquire() {
36  return static_cast<Mutex *>(data_)->acquire();
37}
38
39bool RWMutexImpl::reader_release() {
40  return static_cast<Mutex *>(data_)->release();
41}
42
43bool RWMutexImpl::writer_acquire() {
44  return static_cast<Mutex *>(data_)->acquire();
45}
46
47bool RWMutexImpl::writer_release() {
48  return static_cast<Mutex *>(data_)->release();
49}
50
51}
52