From 7028c8a53f535f1e6642e22529fff8ceb32facbd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Apr 2015 17:59:07 +0200 Subject: [PATCH] utils: add nm_clear_g_source() helper Utility function to simplify the following common code: if (priv->timeout_id) { g_source_remove (priv->timeout_id); priv->timeout_id = 0; } to nm_clear_g_source (&priv->timeout_id); (cherry picked from commit b5beaef8fa19a85110582b3c4439daa49e567d85) --- include/nm-utils-internal.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/nm-utils-internal.h b/include/nm-utils-internal.h index 7ca44f3c4b..227a210b2c 100644 --- a/include/nm-utils-internal.h +++ b/include/nm-utils-internal.h @@ -160,4 +160,17 @@ NM_DEFINE_SINGLETON_DESTRUCTOR(TYPE) /*****************************************************************************/ +static inline gboolean +nm_clear_g_source (guint *id) +{ + if (id && *id) { + g_source_remove (*id); + *id = 0; + return TRUE; + } + return FALSE; +} + +/*****************************************************************************/ + #endif