diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-01-24 13:00:29 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-01-25 09:04:48 +0000 |
commit | ba3f29b62fcb362b5385b7e35691f0c466d811fd (patch) | |
tree | e288cc43af15a3603c845046af941abea5ad9066 /epan/register.c | |
parent | 9149af994817b89fdb37be963596828cb2b27a1b (diff) |
Don't use static GMutexes.
They're not supported in older versions of GLib.
Change-Id: I8342048bab90fb192b8d7f0253f8b3207be8c5b1
Reviewed-on: https://code.wireshark.org/review/25460
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/register.c')
-rw-r--r-- | epan/register.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/epan/register.c b/epan/register.c index d655e64eb6..1567c4685d 100644 --- a/epan/register.c +++ b/epan/register.c @@ -18,15 +18,15 @@ static const char *cur_cb_name = NULL; // We could use g_atomic_pointer_set/get instead of a mutex, but that's // currently (early 2018) invisible to TSAN. -static GMutex cur_cb_name_mtx; +static GMutex *cur_cb_name_mtx; static GAsyncQueue *register_cb_done_q; #define CB_WAIT_TIME (150 * 1000) // microseconds static void set_cb_name(const char *proto) { - g_mutex_lock(&cur_cb_name_mtx); + g_mutex_lock(cur_cb_name_mtx); cur_cb_name = proto; - g_mutex_unlock(&cur_cb_name_mtx); + g_mutex_unlock(cur_cb_name_mtx); } static void * @@ -49,11 +49,18 @@ register_all_protocols(register_cb cb, gpointer cb_data) gboolean called_back = FALSE; GThread *rapw_thread; +#if GLIB_CHECK_VERSION(2,32,0) + cur_cb_name_mtx = (GMutex *)g_malloc(sizeof(GMutex)); + g_mutex_init(cur_cb_name_mtx); +#else + cur_cb_name_mtx = g_mutex_new(); +#endif + rapw_thread = g_thread_new("register_all_protocols_worker", ®ister_all_protocols_worker, NULL); while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) { - g_mutex_lock(&cur_cb_name_mtx); + g_mutex_lock(cur_cb_name_mtx); cb_name = cur_cb_name; - g_mutex_unlock(&cur_cb_name_mtx); + g_mutex_unlock(cur_cb_name_mtx); if (cb && cb_name) { cb(RA_REGISTER, cb_name, cb_data); called_back = TRUE; @@ -87,9 +94,9 @@ register_all_protocol_handoffs(register_cb cb, gpointer cb_data) raphw_thread = g_thread_new("register_all_protocol_handoffs_worker", ®ister_all_protocol_handoffs_worker, NULL); while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) { - g_mutex_lock(&cur_cb_name_mtx); + g_mutex_lock(cur_cb_name_mtx); cb_name = cur_cb_name; - g_mutex_unlock(&cur_cb_name_mtx); + g_mutex_unlock(cur_cb_name_mtx); if (cb && cb_name) { cb(RA_HANDOFF, cb_name, cb_data); called_back = TRUE; @@ -100,6 +107,13 @@ register_all_protocol_handoffs(register_cb cb, gpointer cb_data) cb(RA_HANDOFF, "Registration finished", cb_data); } g_async_queue_unref(register_cb_done_q); + +#if GLIB_CHECK_VERSION(2,32,0) + g_free(cur_cb_name_mtx); +#else + g_mutex_free(cur_cb_name_mtx); +#endif + cur_cb_name_mtx = NULL; } gulong register_count(void) |