Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:58

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * Copyright (c) 2020 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/wait_ops_dragonfly_umtx.hpp
0010  *
0011  * This header contains implementation of the waiting/notifying atomic operations based on DragonFly BSD umtx.
0012  * https://man.dragonflybsd.org/?command=umtx&section=2
0013  */
0014 
0015 #ifndef BOOST_ATOMIC_DETAIL_WAIT_OPS_DRAGONFLY_UMTX_HPP_INCLUDED_
0016 #define BOOST_ATOMIC_DETAIL_WAIT_OPS_DRAGONFLY_UMTX_HPP_INCLUDED_
0017 
0018 #include <unistd.h>
0019 #include <boost/memory_order.hpp>
0020 #include <boost/atomic/detail/config.hpp>
0021 #include <boost/atomic/detail/wait_operations_fwd.hpp>
0022 #include <boost/atomic/detail/header.hpp>
0023 
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027 
0028 namespace boost {
0029 namespace atomics {
0030 namespace detail {
0031 
0032 template< typename Base, bool Interprocess >
0033 struct wait_operations< Base, sizeof(int), true, Interprocess > :
0034     public Base
0035 {
0036     typedef Base base_type;
0037     typedef typename base_type::storage_type storage_type;
0038 
0039     static BOOST_CONSTEXPR_OR_CONST bool always_has_native_wait_notify = true;
0040 
0041     static BOOST_FORCEINLINE bool has_native_wait_notify(storage_type const volatile&) BOOST_NOEXCEPT
0042     {
0043         return true;
0044     }
0045 
0046     static BOOST_FORCEINLINE storage_type wait(storage_type const volatile& storage, storage_type old_val, memory_order order) BOOST_NOEXCEPT
0047     {
0048         storage_type new_val = base_type::load(storage, order);
0049         while (new_val == old_val)
0050         {
0051             ::umtx_sleep(reinterpret_cast< int* >(const_cast< storage_type* >(&storage)), static_cast< int >(old_val), 0);
0052             new_val = base_type::load(storage, order);
0053         }
0054 
0055         return new_val;
0056     }
0057 
0058     static BOOST_FORCEINLINE void notify_one(storage_type volatile& storage) BOOST_NOEXCEPT
0059     {
0060         ::umtx_wakeup(reinterpret_cast< int* >(const_cast< storage_type* >(&storage)), 1);
0061     }
0062 
0063     static BOOST_FORCEINLINE void notify_all(storage_type volatile& storage) BOOST_NOEXCEPT
0064     {
0065         ::umtx_wakeup(reinterpret_cast< int* >(const_cast< storage_type* >(&storage)), 0);
0066     }
0067 };
0068 
0069 } // namespace detail
0070 } // namespace atomics
0071 } // namespace boost
0072 
0073 #include <boost/atomic/detail/footer.hpp>
0074 
0075 #endif // BOOST_ATOMIC_DETAIL_WAIT_OPS_DRAGONFLY_UMTX_HPP_INCLUDED_