
Alexander Gutenev
Updated, after looking into other's implementation:
I would add IncrementPolicy with following default. struct trivial_increment_policy { void inc( long& c ) { ++c; } bool dec( long& c ) { return --c == 0; } }
template<class Derived> template
class intrusive_pointee_base { private: typedef intrusive_pointee_base self; protected: intrusive_pointee_base(void) : reference_counter_(0) {} intrusive_pointee_base(self const&) : reference_counter_(0) {} intrusive_pointee_base operator=(self const&) { return *this } ~intrusive_pointee_base(void) {}
private: friend void intrusive_ptr_add_ref(const Derived * p) { IncrementPolicy::inc(&static_cast
(p)->reference_counter_); } friend void intrusive_ptr_release(const Derived * p) { if(!IncrementPolicy::dec( &static_cast<self const>*>(p)->reference_counter_)) delete p; }
mutable volatile long reference_counter_; };
Now you can add your own struct nt_mt_safe_increment { void inc( long& c ) { ::InterlockedIncrement(c); } bool dec( long& c ) { return ::InterlockedDecrement(--c) == 0; } }; Gennadiy