diff options
author | Gerald Combs <gerald@zing.org> | 2017-11-28 11:04:16 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-11-29 04:43:41 +0000 |
commit | 67ffa3cf7da172df53a821d5cd4c1a6a849f4087 (patch) | |
tree | d6f0d7dd707776eaa1742da2ad1cd4f1195c0532 /epan/register.c | |
parent | 041e3e7c27c78308d0d515171f52a39f8260782b (diff) |
Threads: Set lifetimes and add a compatibility routine.
Join the protocol registration threads so that they call g_thread_unref
which in turn detaches/terminates the thread. This gets rid of many TSan
and DRD errors here. The remaining ones appear to be false positives.
Add g_thread_new to glib-compat (untested).
Change-Id: I4beb6746ed08656715cf7870ac63ff80cf1ef871
Reviewed-on: https://code.wireshark.org/review/24619
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 | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/epan/register.c b/epan/register.c index 877f7ff223..460913cf0d 100644 --- a/epan/register.c +++ b/epan/register.c @@ -16,15 +16,12 @@ #include "epan/dissectors/dissectors.h" static const char *cur_cb_name = NULL; -//static GMutex register_cb_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(register_cb_mtx); cur_cb_name = proto; - // g_mutex_unlock(register_cb_mtx); } static void * @@ -45,21 +42,17 @@ register_all_protocols(register_cb cb, gpointer cb_data) const char *cb_name; register_cb_done_q = g_async_queue_new(); gboolean called_back = FALSE; + GThread *rapw_thread; -#if GLIB_CHECK_VERSION(2,31,0) - g_thread_new("register_all_protocols_worker", ®ister_all_protocols_worker, NULL); -#else - g_thread_create(®ister_all_protocols_worker, TRUE, FALSE, NULL); -#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(register_cb_mtx); cb_name = cur_cb_name; - // g_mutex_unlock(register_cb_mtx); if (cb && cb_name) { cb(RA_REGISTER, cb_name, cb_data); called_back = TRUE; } } + g_thread_join(rapw_thread); if (cb && !called_back) { cb(RA_REGISTER, "Registration finished", cb_data); } @@ -83,25 +76,20 @@ register_all_protocol_handoffs(register_cb cb, gpointer cb_data) cur_cb_name = NULL; const char *cb_name; gboolean called_back = FALSE; + GThread *raphw_thread; -#if GLIB_CHECK_VERSION(2,31,0) - g_thread_new("register_all_protocol_handoffs_worker", ®ister_all_protocol_handoffs_worker, NULL); -#else - g_thread_create(®ister_all_protocol_handoffs_worker, TRUE, FALSE, NULL); -#endif + 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(register_cb_mtx); cb_name = cur_cb_name; - // g_mutex_unlock(register_cb_mtx); if (cb && cb_name) { cb(RA_HANDOFF, cb_name, cb_data); called_back = TRUE; } } + g_thread_join(raphw_thread); if (cb && !called_back) { cb(RA_HANDOFF, "Registration finished", cb_data); } - g_async_queue_unref(register_cb_done_q); } |