[Mesa-dev] [PATCH] clover: Increment an object's reference count in ret_object()

Tom Stellard tstellar at gmail.com
Wed Jun 27 13:15:38 PDT 2012


We need to increment the reference count for objects, like cl_event,
that the user is responsible for destroying when they are returned from
the API.  Otherwise, the object will be destroyed when clover is done with
it, even though the user will still have a reference to it.  For example:

1. clEnqueueNDRangeKernel(queue, ... , &event)
  - create an event object
  - refcount = 1

2. clFlush(queue)
  - event object is removed from the queue and its reference count is
    decremented.
  - refcount = 0, event is deleted

3. clGetEventInfo(event, ...)
  - segfault
---
 src/gallium/state_trackers/clover/api/util.hpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/util.hpp b/src/gallium/state_trackers/clover/api/util.hpp
index 2f9ec1f..5cfc528 100644
--- a/src/gallium/state_trackers/clover/api/util.hpp
+++ b/src/gallium/state_trackers/clover/api/util.hpp
@@ -156,8 +156,10 @@ namespace clover {
    template<typename T, typename S>
    void
    ret_object(T p, S v) {
-      if (p)
+      if (p) {
          *p = v;
+         v->retain();
+      }
       else
          v->release();
    }
-- 
1.7.7.6



More information about the mesa-dev mailing list