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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 6 | // |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the Win32 specific (non-pthread) Mutex class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | //=== WARNING: Implementation here must contain only generic Win32 code that |
| 15 | //=== is guaranteed to work on *all* Win32 variants. |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Reid Kleckner | d59e2fa | 2014-02-12 21:26:20 +0000 | [diff] [blame] | 18 | #include "WindowsSupport.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Mutex.h" |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 22 | |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 23 | sys::MutexImpl::MutexImpl(bool /*recursive*/) |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 24 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 25 | data_ = new CRITICAL_SECTION; |
| 26 | InitializeCriticalSection((LPCRITICAL_SECTION)data_); |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 29 | sys::MutexImpl::~MutexImpl() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 30 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 31 | DeleteCriticalSection((LPCRITICAL_SECTION)data_); |
Jeff Cohen | 65806e6 | 2005-07-13 02:58:04 +0000 | [diff] [blame] | 32 | delete (LPCRITICAL_SECTION)data_; |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 33 | data_ = 0; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 36 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 37 | sys::MutexImpl::acquire() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 38 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 39 | EnterCriticalSection((LPCRITICAL_SECTION)data_); |
| 40 | return true; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 43 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 44 | sys::MutexImpl::release() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 45 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 46 | LeaveCriticalSection((LPCRITICAL_SECTION)data_); |
| 47 | return true; |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 50 | bool |
Kristof Beyls | a11dbf2 | 2017-03-31 14:26:44 +0000 | [diff] [blame] | 51 | sys::MutexImpl::tryacquire() |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 52 | { |
Jeff Cohen | 3800a28 | 2005-07-13 02:15:18 +0000 | [diff] [blame] | 53 | return TryEnterCriticalSection((LPCRITICAL_SECTION)data_); |
Reid Spencer | f404981 | 2005-07-12 15:37:43 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } |