File: clSetEventCallback.c

package info (click to toggle)
pocl 6.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,320 kB
  • sloc: lisp: 149,513; ansic: 103,778; cpp: 54,947; python: 1,513; sh: 949; ruby: 255; pascal: 226; tcl: 180; makefile: 175; java: 72; xml: 49
file content (48 lines) | stat: -rw-r--r-- 1,481 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "pocl_cl.h"
#include "utlist.h"

CL_API_ENTRY cl_int CL_API_CALL
POname(clSetEventCallback) (cl_event     event ,
                    cl_int       command_exec_callback_type ,
                    void (CL_CALLBACK *  pfn_notify )(cl_event, cl_int, void *),
                    void *       user_data ) CL_API_SUFFIX__VERSION_1_1
{
  event_callback_item *cb_ptr = NULL;

  POCL_RETURN_ERROR_COND ((!IS_CL_OBJECT_VALID (event)), CL_INVALID_EVENT);

  POCL_RETURN_ERROR_COND((pfn_notify == NULL), CL_INVALID_VALUE);

  POCL_RETURN_ERROR_ON((command_exec_callback_type != CL_SUBMITTED &&
       command_exec_callback_type != CL_RUNNING && 
       command_exec_callback_type != CL_COMPLETE), CL_INVALID_VALUE,
       "callback type must be CL_SUBMITTED, CL_RUNNING or CL_COMPLETE");

  cb_ptr = (event_callback_item*) malloc (sizeof (event_callback_item));
  if (cb_ptr == NULL)
    return CL_OUT_OF_HOST_MEMORY;

  cb_ptr->callback_function = pfn_notify;
  cb_ptr->user_data = user_data;
  cb_ptr->trigger_status = command_exec_callback_type;
  cb_ptr->next = NULL;

  POCL_LOCK_OBJ (event);
  if (event->status > command_exec_callback_type)
    {
      LL_APPEND (event->callback_list, cb_ptr);
      POCL_UNLOCK_OBJ (event);
    }
  else
    {
      POCL_UNLOCK_OBJ (event);
      cb_ptr->callback_function (event, cb_ptr->trigger_status, 
                                 cb_ptr->user_data);
      free (cb_ptr);
    }
  

  return CL_SUCCESS;
}

POsym(clSetEventCallback)