From 381edca826ee27b1a49f19b0731c777bdf241b20 Mon Sep 17 00:00:00 2001 From: Steven Toth Date: Mon, 24 Oct 2016 10:10:51 -0400 Subject: gallium/hud: protect against and initialization race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the event that multiple threads attempt to install a graph concurrently, protect the shared list. Signed-off-by: Steven Toth Reviewed-by: Brian Paul Reviewed-by: Nicolai Hähnle --- src/gallium/auxiliary/hud/hud_nic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/gallium/auxiliary/hud/hud_nic.c') diff --git a/src/gallium/auxiliary/hud/hud_nic.c b/src/gallium/auxiliary/hud/hud_nic.c index 2795c933369..f9935dea8b7 100644 --- a/src/gallium/auxiliary/hud/hud_nic.c +++ b/src/gallium/auxiliary/hud/hud_nic.c @@ -35,6 +35,7 @@ #include "hud/hud_private.h" #include "util/list.h" #include "os/os_time.h" +#include "os/os_thread.h" #include "util/u_memory.h" #include #include @@ -66,6 +67,7 @@ struct nic_info */ static int gnic_count = 0; static struct list_head gnic_list; +pipe_static_mutex(gnic_mutex); static struct nic_info * find_nic_by_name(const char *n, int mode) @@ -329,16 +331,21 @@ hud_get_num_nics(bool displayhelp) char name[64]; /* Return the number if network interfaces. */ - if (gnic_count) + pipe_mutex_lock(gnic_mutex); + if (gnic_count) { + pipe_mutex_unlock(gnic_mutex); return gnic_count; + } /* Scan /sys/block, for every object type we support, create and * persist an object to represent its different statistics. */ list_inithead(&gnic_list); DIR *dir = opendir("/sys/class/net/"); - if (!dir) + if (!dir) { + pipe_mutex_unlock(gnic_mutex); return 0; + } while ((dp = readdir(dir)) != NULL) { @@ -412,6 +419,7 @@ hud_get_num_nics(bool displayhelp) } + pipe_mutex_unlock(gnic_mutex); return gnic_count; } -- cgit v1.2.3