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>
This commit is contained in:
Gerald Combs 2017-11-28 11:04:16 -08:00 committed by Anders Broman
parent 041e3e7c27
commit 67ffa3cf7d
5 changed files with 20 additions and 30 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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 */

View File

@ -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
*

View File

@ -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 */