clover: Add support to mem objects for multiple destructor callbacks v2
authorTom Stellard <thomas.stellard@amd.com>
Mon, 22 Sep 2014 14:00:39 +0000 (10:00 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 22 Sep 2014 16:32:34 +0000 (12:32 -0400)
The spec says that mem objects should maintain a stack of callbacks
not just one.

v2:
  - Remove stray printf.

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
CC: "10.3" <mesa-stable@lists.freedesktop.org>
src/gallium/state_trackers/clover/core/memory.cpp
src/gallium/state_trackers/clover/core/memory.hpp

index ba6869d78bce553346dc815f4eaebd5488512476..905ebc0fd02996502bd6c9e001031c6d1c599929 100644 (file)
@@ -29,14 +29,16 @@ using namespace clover;
 memory_obj::memory_obj(clover::context &ctx, cl_mem_flags flags,
                        size_t size, void *host_ptr) :
    context(ctx), _flags(flags),
-   _size(size), _host_ptr(host_ptr),
-   _destroy_notify([]{}) {
+   _size(size), _host_ptr(host_ptr) {
    if (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR))
       data.append((char *)host_ptr, size);
 }
 
 memory_obj::~memory_obj() {
-   _destroy_notify();
+   while (_destroy_notify.size()) {
+      _destroy_notify.top()();
+      _destroy_notify.pop();
+   }
 }
 
 bool
@@ -46,7 +48,7 @@ memory_obj::operator==(const memory_obj &obj) const {
 
 void
 memory_obj::destroy_notify(std::function<void ()> f) {
-   _destroy_notify = f;
+   _destroy_notify.push(f);
 }
 
 cl_mem_flags
index f649ca0d29670e598af5e8d089cd5097f0bedd49..bd6da6be4d141bcceea8692c197bf88dd563fc93 100644 (file)
@@ -26,6 +26,7 @@
 #include <functional>
 #include <map>
 #include <memory>
+#include <stack>
 
 #include "core/object.hpp"
 #include "core/queue.hpp"
@@ -61,7 +62,7 @@ namespace clover {
       cl_mem_flags _flags;
       size_t _size;
       void *_host_ptr;
-      std::function<void ()> _destroy_notify;
+      std::stack<std::function<void ()>> _destroy_notify;
 
    protected:
       std::string data;