} catch (error &e) {
return e.get();
}
+
+CLOVER_API cl_int
+clSetContextDestructorCallback(cl_context d_ctx,
+ void (CL_CALLBACK *pfn_notify)(cl_context, void *),
+ void *user_data) try {
+ CLOVER_NOT_SUPPORTED_UNTIL("3.0");
+ auto &ctx = obj(d_ctx);
+
+ if (!pfn_notify)
+ return CL_INVALID_VALUE;
+
+ ctx.destroy_notify([=]{ pfn_notify(d_ctx, user_data); });
+
+ return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
+}
NULL, // clSetProgramSpecializationConstant
NULL, // clCreateBufferWithProperties
NULL, // clCreateImageWithProperties
- NULL, // clSetContextDestructorCallback
+ clSetContextDestructorCallback
};
}
notify(notify), props(props), devs(devs) {
}
+context::~context() {
+ while (_destroy_notify.size()) {
+ _destroy_notify.top()();
+ _destroy_notify.pop();
+ }
+}
+
bool
context::operator==(const context &ctx) const {
return this == &ctx;
return this != &ctx;
}
+void
+context::destroy_notify(std::function<void ()> f) {
+ _destroy_notify.push(f);
+}
+
const context::property_list &
context::properties() const {
return props;
#ifndef CLOVER_CORE_CONTEXT_HPP
#define CLOVER_CORE_CONTEXT_HPP
+#include <stack>
+
#include "core/object.hpp"
#include "core/device.hpp"
#include "core/property.hpp"
typedef clover::property_list<cl_context_properties> property_list;
public:
+ ~context();
+
typedef std::function<void (const char *)> notify_action;
context(const property_list &props, const ref_vector<device> &devs,
bool
operator!=(const context &ctx) const;
+ void destroy_notify(std::function<void ()> f);
+
const property_list &
properties() const;
private:
property_list props;
const std::vector<intrusive_ref<device>> devs;
+ std::stack<std::function<void ()>> _destroy_notify;
};
}