brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 67a25ed Raw
47 lines · c
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___MUTEX_LOCK_GUARD_H10#define _LIBCPP___MUTEX_LOCK_GUARD_H11 12#include <__config>13#include <__mutex/tag_types.h>14 15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16#  pragma GCC system_header17#endif18 19_LIBCPP_BEGIN_NAMESPACE_STD20 21template <class _Mutex>22class _LIBCPP_SCOPED_LOCKABLE lock_guard {23public:24  typedef _Mutex mutex_type;25 26private:27  mutex_type& __m_;28 29public:30  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m) _LIBCPP_ACQUIRE_CAPABILITY(__m)31      : __m_(__m) {32    __m_.lock();33  }34 35  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_REQUIRES_CAPABILITY(__m)36      : __m_(__m) {}37  _LIBCPP_RELEASE_CAPABILITY _LIBCPP_HIDE_FROM_ABI ~lock_guard() { __m_.unlock(); }38 39  lock_guard(lock_guard const&)            = delete;40  lock_guard& operator=(lock_guard const&) = delete;41};42_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(lock_guard);43 44_LIBCPP_END_NAMESPACE_STD45 46#endif // _LIBCPP___MUTEX_LOCK_GUARD_H47