Boost logo

Boost Users :

From: Alexander Gutenev (gutenev_at_[hidden])
Date: 2008-07-30 17:22:03


> This is not an answer to your question, but -- you can take a look at
> the boost::state_chart events implementation, I think I saw there
> something like this (search "intrusive_from_this").

Yes, not an answer, but not an answer.
Actually there's more than just implementation of counter.
However, counting base is implemented as virtual base, not CRTP base, so
this is not exactly what I want.
I have found something more like what I am trying to implement by searhing
entire Boost.
it is counted_base in xpressive. However, looks like better to implement it
like in Gennadiy's code:

struct refcount
{
  refcount(void) : count_(0) {}
  refcount(refcount const&) : count_(0) {}
  refcount& operator=(refcount const&) {}
  long operator++(void) const { return ::InterlockedIncrement(&count_); }
  long operator--(void) const { return ::InterlockedDecrement(&count_); }
private:
  mutable volatile long count_;
};

template<class Derived>
class intrusive_pointee_base
{
  friend void intrusive_ptr_add_ref(const Derived * p)
  {
    intrusive_pointee_base<Derived> const * pbase = p;
    ++(pbase->reference_counter_);
  }

  friend void intrusive_ptr_release(const Derived * p)
  {
    intrusive_pointee_base<Derived> const * pbase = p;
    if (!--(pbase->reference_counter_))
      delete p;
  }

  refcount reference_counter_;
protected:
  ~intrusive_pointee_base(void) {}
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net