#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 <stdio.h>
#include <unistd.h>
*/
static int gnic_count = 0;
static struct list_head gnic_list;
+static mtx_t gnic_mutex = _MTX_INITIALIZER_NP;
static struct nic_info *
find_nic_by_name(const char *n, int mode)
}
}
-static void
-free_query_data(void *p)
-{
- struct nic_info *nic = (struct nic_info *) p;
- list_del(&nic->list);
- FREE(nic);
-}
-
/**
* Create and initialize a new object for a specific network interface dev.
* \param pane parent context.
nic->mode = mode;
if (nic->mode == NIC_DIRECTION_RX) {
- snprintf(gr->name, sizeof(gr->name), "%s-rx-%lldMbps", nic->name,
+ snprintf(gr->name, sizeof(gr->name), "%s-rx-%"PRId64"Mbps", nic->name,
nic->speedMbps);
}
else if (nic->mode == NIC_DIRECTION_TX) {
- snprintf(gr->name, sizeof(gr->name), "%s-tx-%lldMbps", nic->name,
+ snprintf(gr->name, sizeof(gr->name), "%s-tx-%"PRId64"Mbps", nic->name,
nic->speedMbps);
}
else if (nic->mode == NIC_RSSI_DBM)
gr->query_data = nic;
gr->query_new_value = query_nic_load;
- /* Don't use free() as our callback as that messes up Gallium's
- * memory debugger. Use simple free_query_data() wrapper.
- */
- gr->free_query_data = free_query_data;
-
hud_pane_add_graph(pane, gr);
hud_pane_set_max_value(pane, 100);
}
char name[64];
/* Return the number if network interfaces. */
- if (gnic_count)
+ mtx_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) {
}
}
+ closedir(dir);
list_for_each_entry(struct nic_info, nic, &gnic_list, list) {
char line[64];
}
+ pipe_mutex_unlock(gnic_mutex);
return gnic_count;
}