diff options
author | Francisco Jerez <currojerez@riseup.net> | 2014-08-17 23:18:45 +0300 |
---|---|---|
committer | Francisco Jerez <currojerez@riseup.net> | 2014-08-18 09:32:24 +0300 |
commit | 37e4d22e957b59483ecbec4c036476f944a584dc (patch) | |
tree | 7f53b092ac894a06f7b69bb7881845a3547b42ff | |
parent | ce4d3f3104b01b6148ce7b1c7ecd354fd2f062c9 (diff) |
clover/util: Implement minimalist reference to clover::ref_counter object.
Tested-by: EdB <edb+mesa@sigluy.net>
-rw-r--r-- | src/gallium/state_trackers/clover/util/pointer.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/clover/util/pointer.hpp b/src/gallium/state_trackers/clover/util/pointer.hpp index 59c6e6e9f6..b790fd451c 100644 --- a/src/gallium/state_trackers/clover/util/pointer.hpp +++ b/src/gallium/state_trackers/clover/util/pointer.hpp @@ -53,6 +53,51 @@ namespace clover { }; /// + /// 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 /// clover::ref_counter interface. /// |