summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/util
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2014-02-18 13:16:19 +0100
committerFrancisco Jerez <[email protected]>2014-02-21 12:51:22 +0100
commit9ae0bd3829a34d4239521d9c7838089395c2336c (patch)
tree2cbac7b2a4ceed8a186e3210aa694d458e53d42d /src/gallium/state_trackers/clover/util
parent198cd136b94b2ddfb8e2d50e567f3e391eb93915 (diff)
clover: Some improvements for the intrusive pointer class.
Define some additional convenience operators, clean up the implementation slightly, and rename it to 'intrusive_ptr' for reasons that will be obvious in the next commit. Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/util')
-rw-r--r--src/gallium/state_trackers/clover/util/pointer.hpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/gallium/state_trackers/clover/util/pointer.hpp b/src/gallium/state_trackers/clover/util/pointer.hpp
index f0c5b1618a5..b7a633b523c 100644
--- a/src/gallium/state_trackers/clover/util/pointer.hpp
+++ b/src/gallium/state_trackers/clover/util/pointer.hpp
@@ -57,35 +57,43 @@ namespace clover {
/// clover::ref_counter interface.
///
template<typename T>
- class ref_ptr {
+ class intrusive_ptr {
public:
- ref_ptr(T *q = NULL) : p(NULL) {
- reset(q);
+ intrusive_ptr(T *q = NULL) : p(q) {
+ if (p)
+ p->retain();
}
- ref_ptr(const ref_ptr<T> &ref) : p(NULL) {
- reset(ref.p);
+ intrusive_ptr(const intrusive_ptr &ptr) :
+ intrusive_ptr(ptr.p) {
}
- ~ref_ptr() {
- reset(NULL);
+ intrusive_ptr(intrusive_ptr &&ptr) :
+ p(ptr.p) {
+ ptr.p = NULL;
}
- void
- reset(T *q = NULL) {
- if (q)
- q->retain();
+ ~intrusive_ptr() {
if (p && p->release())
delete p;
- p = q;
}
- ref_ptr &
- operator=(const ref_ptr &ref) {
- reset(ref.p);
+ intrusive_ptr &
+ operator=(intrusive_ptr ptr) {
+ std::swap(ptr.p, p);
return *this;
}
+ bool
+ operator==(const intrusive_ptr &ref) const {
+ return p == ref.p;
+ }
+
+ bool
+ operator!=(const intrusive_ptr &ref) const {
+ return p != ref.p;
+ }
+
T &
operator*() const {
return *p;
@@ -96,22 +104,31 @@ namespace clover {
return p;
}
+ T *
+ operator()() const {
+ return p;
+ }
+
explicit operator bool() const {
return p;
}
+ explicit operator T *() const {
+ return p;
+ }
+
private:
T *p;
};
///
/// Transfer the caller's ownership of a reference-counted object
- /// to a clover::ref_ptr smart pointer.
+ /// to a clover::intrusive_ptr smart pointer.
///
template<typename T>
- inline ref_ptr<T>
+ inline intrusive_ptr<T>
transfer(T *p) {
- ref_ptr<T> ref { p };
+ intrusive_ptr<T> ref { p };
p->release();
return ref;
}