From nobody at rubyforge.org Sun May 4 13:04:11 2008 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sun, 4 May 2008 13:04:11 -0400 (EDT) Subject: [Ruburple-submits] [55] trunk/ruburple/ext/ruburple_ext.c: added a call_and_discard_result function for those times you don' t really need the result (or the waiting...) Message-ID: <20080504170411.8EBA91858614@rubyforge.org> Revision: 55 Author: zond Date: 2008-05-04 13:04:11 -0400 (Sun, 04 May 2008) Log Message: ----------- added a call_and_discard_result function for those times you don't really need the result (or the waiting...) Modified Paths: -------------- trunk/ruburple/ext/ruburple_ext.c Modified: trunk/ruburple/ext/ruburple_ext.c =================================================================== --- trunk/ruburple/ext/ruburple_ext.c 2008-01-28 01:39:43 UTC (rev 54) +++ trunk/ruburple/ext/ruburple_ext.c 2008-05-04 17:04:11 UTC (rev 55) @@ -230,6 +230,16 @@ g_free(call); } +/* Call one of our single shots and free the call structure */ +static gboolean +call_and_free_single_shot(gpointer data) +{ + RuburpleSingleShotCall *call = (RuburpleSingleShotCall *) data; + call->function(call->data); + ruburple_single_shot_call_free(call); + return FALSE; +} + /* Call one of our single shots */ static gboolean call_single_shot(gpointer data) @@ -256,6 +266,24 @@ return call; } +/* + * Ask glib to run something for us once and return immediately and discard the result. + * + * If the glib main loop is sleeping due to us we will do it ourselves, + * if it is NOT sleeping due to us we will register a single shot call. + * + */ +static void +call_and_discard_result(RuburpleCallFunc function, gpointer data) +{ + if (glib_sleeping) { + function(data); + } else { + RuburpleSingleShotCall *call = ruburple_single_shot_call_new(function, data); + g_idle_add(call_and_free_single_shot, call); + } +} + /* * Ask glib to run something for us once and wait for the result to be ready. *