aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@zing.org>2017-11-28 11:04:16 -0800
committerAnders Broman <a.broman58@gmail.com>2017-11-29 04:43:41 +0000
commit67ffa3cf7da172df53a821d5cd4c1a6a849f4087 (patch)
treed6f0d7dd707776eaa1742da2ad1cd4f1195c0532
parent041e3e7c27c78308d0d515171f52a39f8260782b (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>
-rw-r--r--dumpcap.c8
-rw-r--r--epan/register.c24
-rw-r--r--ui/gtk/main_welcome.c4
-rw-r--r--wsutil/glib-compat.c9
-rw-r--r--wsutil/glib-compat.h5
5 files changed, 20 insertions, 30 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 38209b94a9..34e4bb5b7c 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1715,11 +1715,7 @@ cap_pipe_open_live(char *pipename,
}
#ifdef _WIN32
else {
-#if GLIB_CHECK_VERSION(2,31,0)
g_thread_new("cap_pipe_open_live", &cap_thread_read, pcap_src);
-#else
- g_thread_create(&cap_thread_read, pcap_src, FALSE, NULL);
-#endif
pcap_src->cap_pipe_buf = (char *) &magic;
pcap_src->cap_pipe_bytes_read = 0;
@@ -3238,12 +3234,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
pcap_queue_packets = 0;
for (i = 0; i < global_ld.pcaps->len; i++) {
pcap_src = g_array_index(global_ld.pcaps, capture_src *, i);
-#if GLIB_CHECK_VERSION(2,31,0)
/* XXX - Add an interface name here? */
pcap_src->tid = g_thread_new("Capture read", pcap_read_handler, pcap_src);
-#else
- pcap_src->tid = g_thread_create(pcap_read_handler, pcap_src, TRUE, NULL);
-#endif
}
}
while (global_ld.go) {
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", &register_all_protocols_worker, NULL);
-#else
- g_thread_create(&register_all_protocols_worker, TRUE, FALSE, NULL);
-#endif
+ rapw_thread = g_thread_new("register_all_protocols_worker", &register_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", &register_all_protocol_handoffs_worker, NULL);
-#else
- g_thread_create(&register_all_protocol_handoffs_worker, TRUE, FALSE, NULL);
-#endif
+ raphw_thread = g_thread_new("register_all_protocol_handoffs_worker", &register_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);
}
diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c
index 202ece3b7a..27b0f21434 100644
--- a/ui/gtk/main_welcome.c
+++ b/ui/gtk/main_welcome.c
@@ -653,12 +653,8 @@ welcome_filename_link_new(const gchar *filename, GtkWidget **label, GObject *men
g_signal_connect(w, "destroy", G_CALLBACK(welcome_filename_destroy_cb), ri_stat);
g_free(str_escaped);
-#if GLIB_CHECK_VERSION(2,31,0)
/* XXX - Add the filename here? */
g_thread_new("Recent item status", get_recent_item_status, ri_stat);
-#else
- g_thread_create(get_recent_item_status, ri_stat, FALSE, NULL);
-#endif
ri_stat->timer = g_timeout_add(200, update_recent_items, ri_stat);
/* event box */
diff --git a/wsutil/glib-compat.c b/wsutil/glib-compat.c
index 7dd67d16a7..8c2092edf2 100644
--- a/wsutil/glib-compat.c
+++ b/wsutil/glib-compat.c
@@ -129,6 +129,15 @@ g_async_queue_timeout_pop(GAsyncQueue *queue,
}
#endif /* GLIB_CHECK_VERSION(2,31,18)*/
+
+
+#if !GLIB_CHECK_VERSION(2,31,0)
+GThread *g_thread_new(const gchar *name _U_, GThreadFunc func, gpointer data)
+{
+ return g_thread_create(func, data, TRUE, NULL);
+}
+#endif /* GLIB_CHECK_VERSION(2,31,0)*/
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h
index 1acf587c19..a1f1d764d7 100644
--- a/wsutil/glib-compat.h
+++ b/wsutil/glib-compat.h
@@ -38,4 +38,9 @@ WS_DLL_PUBLIC GPtrArray* g_ptr_array_new_full(guint reserved_size, GDestroyNotif
WS_DLL_PUBLIC gpointer g_async_queue_timeout_pop(GAsyncQueue *queue, guint64 timeout);
#endif /* !GLIB_CHECK_VERSION(2,31,18) */
+// joinable = TRUE, error = NULL
+#if !GLIB_CHECK_VERSION(2,31,0)
+WS_DLL_PUBLIC GThread *g_thread_new (const gchar *name, GThreadFunc func, gpointer data);
+#endif /* !GLIB_CHECK_VERSION(2,31,0) */
+
#endif /* GLIB_COMPAT_H */