Charles Davis | 54c9eb6 | 2010-11-29 19:44:50 +0000 | [diff] [blame] | 1 | //===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===// |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Win32 specific (non-pthread) Mutex class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | //=== WARNING: Implementation here must contain only generic Win32 code that |
| 16 | //=== is guaranteed to work on *all* Win32 variants. |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Reid Kleckner | d59e2fa | 2014-02-12 21:26:20 +0000 | [diff] [blame] | 19 | #include "WindowsSupport.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Mutex.h" |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 23 | |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 24 | sys::MutexImpl::MutexImpl(bool /*recursive*/) |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 25 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 26 | data_ = new CRITICAL_SECTION; |
| 27 | InitializeCriticalSection((LPCRITICAL_SECTION)data_); |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 30 | sys::MutexImpl::~MutexImpl() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 31 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 32 | DeleteCriticalSection((LPCRITICAL_SECTION)data_); |
Jeff Cohen | 65806e6 | 2005-07-13 02:58:04 +0000 | [diff] [blame] | 33 | delete (LPCRITICAL_SECTION)data_; |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 34 | data_ = 0; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 37 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 38 | sys::MutexImpl::acquire() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 39 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 40 | EnterCriticalSection((LPCRITICAL_SECTION)data_); |
| 41 | return true; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 44 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 45 | sys::MutexImpl::release() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 46 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 47 | LeaveCriticalSection((LPCRITICAL_SECTION)data_); |
| 48 | return true; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 51 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 52 | sys::MutexImpl::tryacquire() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 53 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 54 | return TryEnterCriticalSection((LPCRITICAL_SECTION)data_); |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } |