Skip to content

Commit

Permalink
Use boost::compressed_pair for EBO in rcu_obj_base
Browse files Browse the repository at this point in the history
This fixes a discrepancy between nonempty deleters, which will get constructed
when the rcu_obj_base is constructed, and empty deleters, which were only
getting constructed when retire() is run.

Signed-off-by: Lance Roy <[email protected]>
  • Loading branch information
ldr709 committed Aug 8, 2017
1 parent 5a8e75d commit c3be807
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions Test/paulmck/rcu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,34 @@
#include <cstddef>
#include <memory>
#include <mutex>
#include <tuple>
#include <utility>
#include <boost/compressed_pair.hpp>

// Derived-type approach. All RCU-protected data structures using this
// approach must derive from std::rcu_obj_base, which in turn derives
// from std::rcu_head. No idea what happens in case of multiple inheritance.

namespace std {
template<typename T, typename D = default_delete<T>, bool E = is_empty<D>::value>
class rcu_obj_base: private rcu_head {
D deleter;
public:
void retire(D d = {})
{
deleter = std::move(d);
::call_rcu(
static_cast<rcu_head *>(this),
[](rcu_head *rhp) {
auto rhdp = static_cast<rcu_obj_base *>(rhp);
auto obj = static_cast<T *>(rhdp);
rhdp->deleter(obj);
}
);
}
};

namespace detail {
struct rcu_obj_base_empty_type {};
}

// Specialization for when D is an empty type.

template<typename T, typename D>
class rcu_obj_base<T,D,true>: private rcu_head {
template<typename T, typename D = default_delete<T>>
class rcu_obj_base:
private rcu_head,
private boost::compressed_pair<D, detail::rcu_obj_base_empty_type> {
public:
void retire(D = {})
void retire(D d = {})
{
this->first() = std::move(d);
::call_rcu(
static_cast<rcu_head *>(this),
[](rcu_head *rhp) {
auto rhdp = static_cast<rcu_obj_base *>(rhp);
auto obj = static_cast<T *>(rhdp);
D()(obj);
rhdp->first()(obj);
}
);
}
Expand Down

0 comments on commit c3be807

Please sign in to comment.