LLVM API Documentation
00001 //===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===// 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) Mutex 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 "WindowsSupport.h" 00020 #include "llvm/Support/Mutex.h" 00021 00022 namespace llvm { 00023 using namespace sys; 00024 00025 MutexImpl::MutexImpl(bool /*recursive*/) 00026 { 00027 data_ = new CRITICAL_SECTION; 00028 InitializeCriticalSection((LPCRITICAL_SECTION)data_); 00029 } 00030 00031 MutexImpl::~MutexImpl() 00032 { 00033 DeleteCriticalSection((LPCRITICAL_SECTION)data_); 00034 delete (LPCRITICAL_SECTION)data_; 00035 data_ = 0; 00036 } 00037 00038 bool 00039 MutexImpl::acquire() 00040 { 00041 EnterCriticalSection((LPCRITICAL_SECTION)data_); 00042 return true; 00043 } 00044 00045 bool 00046 MutexImpl::release() 00047 { 00048 LeaveCriticalSection((LPCRITICAL_SECTION)data_); 00049 return true; 00050 } 00051 00052 bool 00053 MutexImpl::tryacquire() 00054 { 00055 return TryEnterCriticalSection((LPCRITICAL_SECTION)data_); 00056 } 00057 00058 }