LLVM API Documentation

Win32/Mutex.inc

Go to the documentation of this file.
00001 //===- llvm/System/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by Jeff Cohen and is distributed under the 
00006 // University of Illinois Open Source 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 "Win32.h"
00020 #include "llvm/System/Mutex.h"
00021 
00022 namespace llvm {
00023 using namespace sys;
00024 
00025 Mutex::Mutex(bool /*recursive*/)
00026 {
00027   data_ = new CRITICAL_SECTION;
00028   InitializeCriticalSection((LPCRITICAL_SECTION)data_);
00029 }
00030 
00031 Mutex::~Mutex()
00032 {
00033   DeleteCriticalSection((LPCRITICAL_SECTION)data_);
00034   delete (LPCRITICAL_SECTION)data_;
00035   data_ = 0;
00036 }
00037 
00038 bool 
00039 Mutex::acquire()
00040 {
00041   EnterCriticalSection((LPCRITICAL_SECTION)data_);
00042   return true;
00043 }
00044 
00045 bool 
00046 Mutex::release()
00047 {
00048   LeaveCriticalSection((LPCRITICAL_SECTION)data_);
00049   return true;
00050 }
00051 
00052 bool 
00053 Mutex::tryacquire()
00054 {
00055   return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
00056 }
00057 
00058 }