One approach would be to have an event queue that you pull off of from Perl, and push onto from the C callback.
So instead of:
do something like:void my_callback(void *data) { call_into_perl_event_handler(data); }
Hope that helps.// XS: void my_callback(void *data) { pthread_mutex_lock(&event_queue_lock); push_onto_event_queue(data); pthread_mutex_unlock(&event_queue_lock); pthread_cond_broadcast(&event_queue_not_empty); } void get_next_event() PPCODE: pthread_mutex_lock(&event_queue_lock); while (event_queue_empty()) pthread_cond_wait(&event_queue_not_empty, &event_queue_loc +k); void *data = pull_off_event_queue(); pthread_mutex_unlock(&event_queue_lock); EXTEND(SP, 1); PUSHs(sv_2mortal(newSVpvn(data, ...))); # Perl: while (my $event = get_next_event()) { event_handler($event); }
In reply to Re: Callback from threaded shared library
by PreferredUserName
in thread Callback from threaded shared library
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |