Skip to content

Commit

Permalink
Implement rcu_retire with unique_ptr and rcu_obj_base
Browse files Browse the repository at this point in the history
This makes rcu_retire more concise.

Signed-off-by: Lance Roy <[email protected]>
  • Loading branch information
ldr709 committed Aug 2, 2017
1 parent 09a5eca commit edcc50e
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions Test/paulmck/rcu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,18 @@ namespace std {
}
};

namespace details {
template<typename T, typename D = default_delete<T>>
class rcu_obj_base_ni: public rcu_head {
public:
rcu_obj_base_ni(T *pi, D di = {}) {
p = pi;
d = di;
}
T *p;
D d;
};
}

template<typename T, typename D = default_delete<T>>
void rcu_retire(T *p, D d = {})
{
auto robnp = new details::rcu_obj_base_ni<T, D>(p, d);

::call_rcu(
static_cast<rcu_head *>(robnp),
[](rcu_head *rhp) {
auto robnp2 = static_cast<details::rcu_obj_base_ni<T, D> *>(rhp);

robnp2->d(robnp2->p);
delete robnp2;
});
typedef std::unique_ptr<T, D> ptr_type;
ptr_type ptr(p, std::move(d));

struct rcu_obj_base_ni :
public rcu_obj_base<rcu_obj_base_ni>,
public ptr_type {
rcu_obj_base_ni(ptr_type p) : ptr_type(std::move(p)) {}
};
(new rcu_obj_base_ni(std::move(ptr)))->retire();
}

} // namespace std

0 comments on commit edcc50e

Please sign in to comment.