brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 6760b1f Raw
49 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___CXX03___MUTEX_LOCK_GUARD_H10#define _LIBCPP___CXX03___MUTEX_LOCK_GUARD_H11 12#include <__cxx03/__config>13#include <__cxx03/__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_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) lock_guard {23public:24  typedef _Mutex mutex_type;25 26private:27  mutex_type& __m_;28 29public:30  _LIBCPP_NODISCARD31  _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))32      : __m_(__m) {33    __m_.lock();34  }35 36  _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t)37      _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))38      : __m_(__m) {}39  _LIBCPP_HIDE_FROM_ABI ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }40 41  lock_guard(lock_guard const&)            = delete;42  lock_guard& operator=(lock_guard const&) = delete;43};44_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(lock_guard);45 46_LIBCPP_END_NAMESPACE_STD47 48#endif // _LIBCPP___CXX03___MUTEX_LOCK_GUARD_H49