LLVM API Documentation
00001 //= llvm/System/Win32/Mutex.inc - Win32 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 Win32 specific (non-pthread) RWMutex class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 //===----------------------------------------------------------------------===// 00015 //=== WARNING: Implementation here must contain only generic Win32 code that 00016 //=== is guaranteed to work on *all* Win32 variants. 00017 //===----------------------------------------------------------------------===// 00018 00019 #include "Win32.h" 00020 00021 // FIXME: Windows does not have reader-writer locks pre-Vista. If you want 00022 // real reader-writer locks, you a pthreads implementation for Windows. 00023 00024 namespace llvm { 00025 using namespace sys; 00026 00027 RWMutexImpl::RWMutexImpl() { 00028 data_ = calloc(1, sizeof(CRITICAL_SECTION)); 00029 InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00030 } 00031 00032 RWMutexImpl::~RWMutexImpl() { 00033 DeleteCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00034 free(data_); 00035 } 00036 00037 bool RWMutexImpl::reader_acquire() { 00038 EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00039 return true; 00040 } 00041 00042 bool RWMutexImpl::reader_release() { 00043 LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00044 return true; 00045 } 00046 00047 bool RWMutexImpl::writer_acquire() { 00048 EnterCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00049 return true; 00050 } 00051 00052 bool RWMutexImpl::writer_release() { 00053 LeaveCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); 00054 return true; 00055 } 00056 00057 00058 }