zhugh
December 12, 2010, 3:43am
1
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:
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?
Declare your callback function like this:
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:
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.
zhugh
December 12, 2010, 1:47pm
3
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:
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.
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:
// This is very much wrong
clSetEventCallback(e, CL_COMPLETE, &func(e, CL_COMPLETE, NULL), NULL);
This is what you should be doing:
clSetEventCallback(e, CL_COMPLETE, &func, NULL);
zhugh
December 12, 2010, 5:55pm
5
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!