callback synchronisation
- From: Drazen Kacar <dave srce hr>
- To: gtk-list redhat com
- Subject: callback synchronisation
- Date: Thu, 9 Dec 1999 06:20:15 +0100
I have a callback function which is called from the main loop whenever the
OS hits my application with SIGPOLL.
It looks like this (somewhat simplified):
void rescan(struct my_data *the_data)
{
update_os_data(os_data);
if(os_data->id != the_data->id)
{
if(the_data->killer > 0)
gtk_timeout_remove(the_data->killer);
replace_data(the_data, os_data);
return;
}
if(the_data->killer > 0)
return;
if(os_data->still_alive < 0) /* not alive */
{
the_data->killer = gtk_timeout_add(2000, kill_it, the_data)
return;
}
...
}
kill_it() frees some structures and destroys a notebook page. I'm showing
info about processes and it's perfectly possible that some GUI front-end
will generate several CLI processes in succession, which will replace each
other in the output of my application, so I'd like to wait 2 seconds before
removing process info from the screen. Otherwise I'd have flicker, because
the page would be removed from the notebook and then another would be created.
rescan(), replace_data() and kill_it() work on the same data, so I need
to prevent them from corrupting it for each other. The functions are
called asynchronously, whenever the OS signals come. SIGPOLL is being
handled by functions set with g_source_add(), so it behaves the same
way as SIGALRM, I think.
I don't know if glib main loop guarantees that my callbacks can't be
interrupted by another callback with the same priority (G_PRIORITY_DEFAULT).
If that's the case, then everything should work.
If not, I need to set up some lock for my data, which is probably possible,
but I don't know what to do when I detect that another callback holds the
lock, ie. how do I let it continue its job and then return to the current
callback.
And which values can't be returned by gtk_timeout_add()?
--
.-. .-. I don't work for my employer.
(_ \ / _)
| dave@srce.hr
| dave@fly.srk.fer.hr
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]