mirror of
https://github.com/boostorg/atomic.git
synced 2026-02-02 20:32:09 +00:00
The generic implementation is based on the lock pool. A list of condition variables (or waiting futexes) is added per lock. Basically, the lock pool serves as a global hash table, where each lock represents a bucket and each wait state is an element. Every wait operation allocates a wait state keyed on the pointer to the atomic object. Notify operations look up the wait state by the atomic pointer and notify the condition variable/futex. The corresponding lock needs to be acquired to protect the wait state list during all wait/notify operations. Backends not involving the lock pool are going to be added later. The implementation of wait operation extends the C++20 definition in that it returns the newly loaded value instead of void. This allows the caller to avoid loading the value himself. The waiting/notifying operations are not address-free. Address-free variants will be added later. Added tests for the new operations and refactored existing tests for atomic operations. Added docs for the new operations.
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
// Copyright (c) 2020 Andrey Semashev
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
#ifndef BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
|
|
#define BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
|
|
|
|
#include <boost/atomic/atomic.hpp>
|
|
#include <boost/atomic/atomic_ref.hpp>
|
|
#include <boost/atomic/atomic_flag.hpp>
|
|
#include <boost/config.hpp>
|
|
#include "aligned_object.hpp"
|
|
|
|
//! Wrapper type for atomic template
|
|
template< typename T >
|
|
struct atomic_wrapper
|
|
{
|
|
typedef boost::atomic< T > atomic_type;
|
|
typedef atomic_type& atomic_reference_type;
|
|
|
|
atomic_type a;
|
|
|
|
BOOST_DEFAULTED_FUNCTION(atomic_wrapper(), {})
|
|
explicit atomic_wrapper(T const& value) : a(value) {}
|
|
};
|
|
|
|
//! Wrapper type for atomic_ref template
|
|
template< typename T >
|
|
struct atomic_ref_wrapper
|
|
{
|
|
typedef boost::atomic_ref< T > atomic_type;
|
|
typedef atomic_type const& atomic_reference_type;
|
|
|
|
aligned_object< T, atomic_type::required_alignment > object;
|
|
const atomic_type a;
|
|
|
|
atomic_ref_wrapper() : a(object.get()) {}
|
|
explicit atomic_ref_wrapper(T const& value) : object(value), a(object.get()) {}
|
|
};
|
|
|
|
#endif // BOOST_ATOMIC_TEST_ATOMIC_WRAPPER_HPP_INCLUDED_
|