#include "hud/hud_private.h"
#include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include <stdio.h>
#include <unistd.h>
*/
static int gdiskstat_count = 0;
static struct list_head gdiskstat_list;
+static mtx_t gdiskstat_mutex = _MTX_INITIALIZER_NP;
static struct diskstat_info *
find_dsi_by_name(const char *n, int mode)
}
}
-static void
-free_query_data(void *p)
-{
- struct diskstat_info *nic = (struct diskstat_info *) p;
- list_del(&nic->list);
- FREE(nic);
-}
-
/**
* Create and initialize a new object for a specific block I/O device.
* \param pane parent context.
gr->query_data = dsi;
gr->query_new_value = query_dsi_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 of block devices and partitions. */
- if (gdiskstat_count)
+ mtx_lock(&gdiskstat_mutex);
+ if (gdiskstat_count) {
+ mtx_unlock(&gdiskstat_mutex);
return gdiskstat_count;
+ }
/* Scan /sys/block, for every object type we support, create and
* persist an object to represent its different statistics.
*/
list_inithead(&gdiskstat_list);
DIR *dir = opendir("/sys/block/");
- if (!dir)
+ if (!dir) {
+ mtx_unlock(&gdiskstat_mutex);
return 0;
+ }
while ((dp = readdir(dir)) != NULL) {
/* Add any partitions */
struct dirent *dpart;
DIR *pdir = opendir(basename);
- if (!pdir)
+ if (!pdir) {
+ mtx_unlock(&gdiskstat_mutex);
+ closedir(dir);
return 0;
+ }
while ((dpart = readdir(pdir)) != NULL) {
/* Avoid 'lo' and '..' and '.' */
add_object_part(basename, dpart->d_name, DISKSTAT_WR);
}
}
+ closedir(dir);
if (displayhelp) {
list_for_each_entry(struct diskstat_info, dsi, &gdiskstat_list, list) {
puts(line);
}
}
+ mtx_unlock(&gdiskstat_mutex);
return gdiskstat_count;
}