Commit 37e4d22e authored by Francisco Jerez's avatar Francisco Jerez
Browse files

clover/util: Implement minimalist reference to clover::ref_counter object.


Tested-by: Serge Martin's avatarEdB <edb+mesa@sigluy.net>
parent ce4d3f31
...@@ -52,6 +52,51 @@ namespace clover { ...@@ -52,6 +52,51 @@ namespace clover {
std::atomic<unsigned> _ref_count; std::atomic<unsigned> _ref_count;
}; };
///
/// Simple reference to a clover::ref_counter object. Unlike
/// clover::intrusive_ptr and clover::intrusive_ref, it does nothing
/// special when the reference count drops to zero.
///
class ref_holder {
public:
ref_holder(ref_counter &o) : p(&o) {
p->retain();
}
ref_holder(const ref_holder &ref) :
ref_holder(*ref.p) {
}
ref_holder(ref_holder &&ref) :
p(ref.p) {
ref.p = NULL;
}
~ref_holder() {
if (p)
p->release();
}
ref_holder &
operator=(ref_holder ref) {
std::swap(ref.p, p);
return *this;
}
bool
operator==(const ref_holder &ref) const {
return p == ref.p;
}
bool
operator!=(const ref_holder &ref) const {
return p != ref.p;
}
private:
ref_counter *p;
};
/// ///
/// Intrusive smart pointer for objects that implement the /// Intrusive smart pointer for objects that implement the
/// clover::ref_counter interface. /// clover::ref_counter interface.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment