Results 1 to 5 of 5

Thread: Events and callback functions

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    7

    Events and callback functions

    Hello,

    I've been trying to code an application that calls clSetEventCallback, but it's not working. Are there any examples that call this function?

    Here's my code:

    Code :
    typedef void (CL_CALLBACK *cb_type)(cl_event, cl_int, void *);
    ...
    cb_type cb = func;
    cl_event e;   
    ...
    clSetEventCallback(e, CL_COMPLETE, cb(e, CL_COMPLETE, NULL), NULL);

    I've tried changing things around, but this won't compile. Any thoughts?

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Events and callback functions

    Declare your callback function like this:

    Code :
    void CL_CALLBACK myCallback(cl_event event, cl_int cmd_exec_status, void *user_data)
    {
        // handle the callback here.
    }

    Then you can bind it to a specific event like this:

    Code :
    cl_int errcode = clSetEventCallback(myEvent, CL_COMPLETE, &myCallback, NULL);

    I'm doing this from memory. If it doesn't compile give me a shout and I'll copy-and-paste some example code that is known to work.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    7

    Re: Events and callback functions

    Hello David,

    Thanks for the response, but your code doesn't work. I declared the callback function properly. My problem is clSetEventCallback. I tried code similar to your suggestion:

    Code :
    clSetEventCallback(e, CL_COMPLETE, &func(e, CL_COMPLETE, NULL), NULL);

    This doesn't compile. If you have working code, I'd be very grateful if you'd share.

    Thanks.

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Events and callback functions

    Have you actually tried exactly what I said? Because what you posted there is clearly syntactically incorrect which is why it won't compile.

    I'm referring to this:

    Code :
    // This is very much wrong
    clSetEventCallback(e, CL_COMPLETE, &func(e, CL_COMPLETE, NULL), NULL);

    This is what you should be doing:

    Code :
    clSetEventCallback(e, CL_COMPLETE, &func, NULL);
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    7

    Re: Events and callback functions

    You're right. Since the callback requires three arguments, I thought you'd have to send three arguments with clSetEventCallback. But as it turns out, you don't have to do that at all.

    My mistake. Thank you!

Similar Threads

  1. Callback When Event Already Set?
    By Quantam in forum OpenCL
    Replies: 2
    Last Post: 11-26-2012, 01:34 AM
  2. Replies: 0
    Last Post: 01-18-2011, 08:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •