LLVM API Documentation

Unix/RWMutex.inc
Go to the documentation of this file.
00001 //= llvm/Support/Unix/RWMutex.inc - Unix Reader/Writer Mutual Exclusion Lock  =//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the Unix specific (non-pthread) RWMutex class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 //===----------------------------------------------------------------------===//
00015 //=== WARNING: Implementation here must contain only generic UNIX code that
00016 //===          is guaranteed to work on *all* UNIX variants.
00017 //===----------------------------------------------------------------------===//
00018 
00019 #include "llvm/Support/Mutex.h"
00020 
00021 namespace llvm {
00022 
00023 using namespace sys;
00024 
00025 // This naive implementation treats readers the same as writers.  This
00026 // will therefore deadlock if a thread tries to acquire a read lock
00027 // multiple times.
00028 
00029 RWMutexImpl::RWMutexImpl() : data_(new Mutex(false)) { }
00030 
00031 RWMutexImpl::~RWMutexImpl() {
00032   delete static_cast<Mutex *>(data_);
00033 }
00034 
00035 bool RWMutexImpl::reader_acquire() {
00036   return static_cast<Mutex *>(data_)->acquire();
00037 }
00038 
00039 bool RWMutexImpl::reader_release() {
00040   return static_cast<Mutex *>(data_)->release();
00041 }
00042 
00043 bool RWMutexImpl::writer_acquire() {
00044   return static_cast<Mutex *>(data_)->acquire();
00045 }
00046 
00047 bool RWMutexImpl::writer_release() {
00048   return static_cast<Mutex *>(data_)->release();
00049 }
00050 
00051 }