Skip to content

Commit

Permalink
Switched from atomic_count to Boost.Atomic for reference counting.
Browse files Browse the repository at this point in the history
This avoids including a deprecated header from Boost.SmartPtr implementation
details.

Closes #236.
  • Loading branch information
Lastique committed Sep 29, 2024
1 parent 028247d commit c126392
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions include/boost/log/core/record_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#include <boost/log/attributes/attribute_value_set.hpp>
#include <boost/log/expressions/keyword_fwd.hpp>
#ifndef BOOST_LOG_NO_THREADS
#include <boost/detail/atomic_count.hpp>
#include <boost/memory_order.hpp>
#include <boost/atomic/atomic.hpp>
#endif // BOOST_LOG_NO_THREADS
#include <boost/log/detail/header.hpp>

Expand Down Expand Up @@ -63,19 +64,34 @@ class record_view
//! Publicly available record data
struct public_data
{
private:
//! Reference counter
#ifndef BOOST_LOG_NO_THREADS
mutable boost::detail::atomic_count m_ref_counter;
mutable boost::atomic< unsigned int > m_ref_counter;

friend void intrusive_ptr_add_ref(const public_data* p) BOOST_NOEXCEPT
{
p->m_ref_counter.opaque_add(1u, boost::memory_order_relaxed);
}
friend void intrusive_ptr_release(const public_data* p) BOOST_NOEXCEPT
{
if (!p->m_ref_counter.sub_and_test(1u, boost::memory_order_acq_rel))
public_data::destroy(p);
}
#else
mutable unsigned int m_ref_counter;

friend void intrusive_ptr_add_ref(const public_data* p) BOOST_NOEXCEPT { ++p->m_ref_counter; }
friend void intrusive_ptr_release(const public_data* p) BOOST_NOEXCEPT { if (--p->m_ref_counter == 0u) public_data::destroy(p); }
#endif // BOOST_LOG_NO_THREADS

public:
//! Attribute values view
attribute_value_set m_attribute_values;

//! Constructor from the attribute value set
explicit public_data(BOOST_RV_REF(attribute_value_set) values) BOOST_NOEXCEPT :
m_ref_counter(1),
m_ref_counter(1u),
m_attribute_values(boost::move(values))
{
}
Expand All @@ -88,9 +104,6 @@ class record_view

BOOST_DELETED_FUNCTION(public_data(public_data const&))
BOOST_DELETED_FUNCTION(public_data& operator= (public_data const&))

friend void intrusive_ptr_add_ref(const public_data* p) BOOST_NOEXCEPT { ++p->m_ref_counter; }
friend void intrusive_ptr_release(const public_data* p) BOOST_NOEXCEPT { if (--p->m_ref_counter == 0) public_data::destroy(p); }
};

private:
Expand Down

0 comments on commit c126392

Please sign in to comment.