From c8555af05dbef352782d1f07a875e3af4c6369a0 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sun, 21 Aug 2011 01:40:18 +0200
Subject: [PATCH] Implement NannyEvent.wait().

---
 doc/source/runtime.rst         |  5 +++++
 pyopencl/__init__.py           | 10 ----------
 src/wrapper/wrap_cl.hpp        | 11 +++++++++++
 src/wrapper/wrap_cl_part_1.cpp |  1 +
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/doc/source/runtime.rst b/doc/source/runtime.rst
index 978f83e2..3dff4bae 100644
--- a/doc/source/runtime.rst
+++ b/doc/source/runtime.rst
@@ -281,6 +281,11 @@ Command Queues and Events
 
     .. method:: get_ward()
 
+    .. method:: wait()
+
+        In addition to performing the same wait as :meth:`Event.wait()`, this
+        method also releases the reference to the guarded object.
+
 Memory
 ------
 
diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index e689051c..72f57e34 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -315,16 +315,6 @@ def _add_functionality():
 
     # }}}
 
-    # {{{ Event
-
-    def event_wait(self):
-        wait_for_events([self])
-        return self
-
-    Event.wait = event_wait
-
-    # }}}
-
     # {{{ Error
 
     def error_str(self):
diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index aa3a9409..fd1f947b 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -1060,6 +1060,11 @@ namespace pyopencl
             throw error("Event.get_profiling_info", CL_INVALID_VALUE);
         }
       }
+
+      virtual void wait()
+      {
+        PYOPENCL_CALL_GUARDED_THREADED(clWaitForEvents, (1, &m_event));
+      }
   };
 
   class nanny_event : public event
@@ -1085,6 +1090,12 @@ namespace pyopencl
 
       py::object get_ward() const
       { return m_ward; }
+
+      virtual void wait()
+      {
+        event::wait();
+        m_ward = py::object();
+      }
   };
 
 
diff --git a/src/wrapper/wrap_cl_part_1.cpp b/src/wrapper/wrap_cl_part_1.cpp
index 3ea37094..bb8cdda0 100644
--- a/src/wrapper/wrap_cl_part_1.cpp
+++ b/src/wrapper/wrap_cl_part_1.cpp
@@ -97,6 +97,7 @@ void pyopencl_expose_part_1()
     py::class_<cls, boost::noncopyable>("Event", py::no_init)
       .DEF_SIMPLE_METHOD(get_info)
       .DEF_SIMPLE_METHOD(get_profiling_info)
+      .DEF_SIMPLE_METHOD(wait)
       .add_property("obj_ptr", &cls::obj_ptr)
       .def(py::self == py::self)
       .def(py::self != py::self)
-- 
GitLab