diff options
| -rw-r--r-- | common/glib-ectomy.c | 16 | ||||
| -rw-r--r-- | common/glib-ectomy.h | 7 | ||||
| -rw-r--r-- | hcid/dbus.c | 24 | 
3 files changed, 28 insertions, 19 deletions
| diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index aa1007ee..fb737642 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -233,7 +233,16 @@ static void timeout_handlers_prepare(GMainContext *context)  static int timeout_cmp(const void *t1, const void *t2)  { -	return t1-t2; +	const struct timeout *tout1 = t1; +	const struct timeout *tout2 = t2; + +	if (!tout2) +		return -1; + +	if (tout1 != tout2) +		return -1; + +	return tout1->id - tout2->id;  }  static void timeout_handlers_check(GMainContext *context) @@ -248,9 +257,7 @@ static void timeout_handlers_check(GMainContext *context)  		t = l->data;  		l = l->next; -		if ((tv.tv_sec < t->expiration.tv_sec) || -			(tv.tv_sec == t->expiration.tv_sec && -			 tv.tv_usec < t->expiration.tv_usec)) +		if (timercmp(&tv, &t->expiration, <))  			continue;  		if (t->function(t->data)) { @@ -372,6 +379,7 @@ guint g_timeout_add(guint interval, GSourceFunc function, gpointer data)  	if (!t)  		return 0; +	memset(t, 0, sizeof(*t));  	t->interval = interval;  	t->function = function;  	t->data = data; diff --git a/common/glib-ectomy.h b/common/glib-ectomy.h index 333687b1..f52a9ce2 100644 --- a/common/glib-ectomy.h +++ b/common/glib-ectomy.h @@ -36,15 +36,10 @@ typedef struct _GIOChannel {  typedef gboolean (*GSourceFunc) (gpointer data); -typedef struct { -	glong tv_sec; -	glong tv_usec; -} time_val_t; -  struct timeout {  	guint id;  	guint interval; -	time_val_t expiration; +	struct timeval expiration;  	gpointer data;  	GSourceFunc function;  }; diff --git a/hcid/dbus.c b/hcid/dbus.c index 206d3343..3a6c8e53 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -1427,11 +1427,25 @@ static int timeout_handler_dispatch(gpointer data)  {  	timeout_handler_t *handler = data; +	/* if not enabled should not be polled by the main loop */ +	if (dbus_timeout_get_enabled(handler->timeout) != TRUE) +		return -1; +  	dbus_timeout_handle(handler->timeout);  	return -1;  } +static void timeout_handler_free(void *data) +{ +	timeout_handler_t *handler = data; +	if (!handler) +		return; + +	g_timeout_remove(handler->id); +	free(handler); +} +  static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)  {  	timeout_handler_t *handler; @@ -1446,22 +1460,14 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)  	handler->id = g_timeout_add(dbus_timeout_get_interval(timeout),  					timeout_handler_dispatch, handler); -	dbus_timeout_set_data(timeout, handler, NULL); +	dbus_timeout_set_data(timeout, handler, timeout_handler_free);  	return TRUE;  }  static void remove_timeout(DBusTimeout *timeout, void *data)  { -	timeout_handler_t *handler; - -	handler = dbus_timeout_get_data(timeout); -	if(handler == NULL) -		return; - -	g_timeout_remove(handler->id); -	free(handler);  }  static void timeout_toggled(DBusTimeout *timeout, void *data) | 
