// Create a temporary soft event that depends on all the events in
// the wait list
- ref_ptr<soft_event> sev =
+ intrusive_ptr<soft_event> sev =
transfer(new soft_event(evs.front().ctx, evs, true));
// ...and wait on it.
// Create a temporary soft event that depends on ev, with
// pfn_notify as completion action.
- ref_ptr<soft_event> sev = transfer(
+ intrusive_ptr<soft_event> sev = transfer(
new soft_event(ev.ctx, { ev }, true,
[=, &ev](event &) {
ev.wait();
// Create a hard event that depends on the events in the wait list:
// subsequent commands in the same queue will be implicitly
// serialized with respect to it -- hard events always are.
- ref_ptr<hard_event> hev = transfer(new hard_event(q, 0, evs));
+ intrusive_ptr<hard_event> hev = transfer(new hard_event(q, 0, evs));
return CL_SUCCESS;
// Create a temporary hard event -- it implicitly depends on all
// the previously queued hard events.
- ref_ptr<hard_event> hev = transfer(new hard_event(q, 0, { }));
+ intrusive_ptr<hard_event> hev = transfer(new hard_event(q, 0, { }));
// And wait on it.
hev->wait();
return _status;
else if (!signalled() ||
- any_of([](const ref_ptr<event> &ev) {
+ any_of([](const intrusive_ptr<event> &ev) {
return ev->status() != CL_COMPLETE;
}, deps))
return CL_SUBMITTED;
void chain(event *ev);
cl_int _status;
- std::vector<ref_ptr<event>> deps;
+ std::vector<intrusive_ptr<event>> deps;
private:
unsigned wait_count;
action action_ok;
action action_fail;
- std::vector<ref_ptr<event>> _chain;
+ std::vector<intrusive_ptr<event>> _chain;
};
///
namespace clover {
class platform : public _cl_platform_id,
public adaptor_range<
- derefs, std::vector<ref_ptr<device>> &> {
+ derefs, std::vector<intrusive_ptr<device>> &> {
public:
platform();
operator=(const platform &platform) = delete;
protected:
- std::vector<ref_ptr<device>> devs;
+ std::vector<intrusive_ptr<device>> devs;
};
}
cl_command_queue_properties _props;
pipe_context *pipe;
-
- typedef ref_ptr<hard_event> event_ptr;
- std::deque<event_ptr> queued_events;
+ std::deque<intrusive_ptr<hard_event>> queued_events;
};
}
/// 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;
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;
}