Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to rcu_obj_base and rcu_retire #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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