refcounted.h
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_REFCOUNTED_H
#define BOOSTER_REFCOUNTED_H
#include <booster/atomic_counter.h>
namespace booster {
class refcounted;
void intrusive_ptr_add_ref(refcounted *ptr);
void intrusive_ptr_release(refcounted *ptr);
class refcounted {
public:
refcounted() :
refs_(0)
{
}
virtual ~refcounted()
{
}
private:
friend void intrusive_ptr_add_ref(refcounted *);
friend void intrusive_ptr_release(refcounted *);
refcounted(refcounted const &other);
refcounted const &operator=(refcounted const &other);
atomic_counter refs_;
};
inline void intrusive_ptr_add_ref(refcounted *p)
{
++p->refs_;
}
inline void intrusive_ptr_release(refcounted *p)
{
if(p && --p->refs_ == 0)
delete p;
}
}
#endif
booster::refcounted
This class is used as base class for reference counted objects that use intrusive_ptr. Deriving from this class allows simple way to manage reference counting for single object.
Definition: refcounted.h:25
booster::refcounted::intrusive_ptr_release
friend void intrusive_ptr_release(refcounted *)
Definition: refcounted.h:55
booster::refcounted::intrusive_ptr_add_ref
friend void intrusive_ptr_add_ref(refcounted *)
Definition: refcounted.h:48
booster::atomic_counter
Atomic counter is a class that allows perform counting in thread safe way.
Definition: atomic_counter.h:33