template <typename T>
inline void hazptr_owner<T>::set(const T* ptr) noexcept {
- DEBUG_PRINT(this << " " << ptr);
- hazptr_->set(ptr);
+ auto p = static_cast<hazptr_obj*>(const_cast<T*>(ptr));
+ DEBUG_PRINT(this << " " << ptr << " p:" << p);
+ hazptr_->set(p);
}
template <typename T>
/** Definition of hazptr_obj_base */
template <typename T, typename Deleter = std::default_delete<T>>
-class hazptr_obj_base : private hazptr_obj {
+class hazptr_obj_base : public hazptr_obj {
public:
/* Retire a removed object and pass the responsibility for
* reclaiming it to the hazptr library */
ret = s.cas(u, v);
CHECK(ret);
}
+
+TEST_F(HazptrTest, VirtualTest) {
+ struct Thing : public hazptr_obj_base<Thing> {
+ virtual ~Thing() {
+ DEBUG_PRINT("this: " << this << " &a: " << &a << " a: " << a);
+ }
+ int a;
+ };
+ for (int i = 0; i < 100; i++) {
+ auto bar = new Thing;
+ bar->a = i;
+
+ hazptr_owner<Thing> hptr;
+ hptr.set(bar);
+ bar->retire();
+ EXPECT_EQ(bar->a, i);
+ }
+}