#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>
#include <sys/ioctl.h>
#include <linux/wireless.h>
-#define LOCAL_DEBUG 0
-
struct nic_info
{
struct list_head list;
*/
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)
*leveldBm = ((char) stats.qual.level * -1);
close(sockfd);
-
-#if LOCAL_DEBUG
- printf("NIC signal level%s is %d%s.\n",
- (stats.qual.updated & IW_QUAL_DBM ? " (in dBm)" : ""),
- (char) stats.qual.level,
- (stats.qual.updated & IW_QUAL_LEVEL_UPDATED ? " (updated)" : ""));
-#endif
}
static void
}
}
-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.
if (num_nics <= 0)
return;
-#if LOCAL_DEBUG
- printf("%s(%s, %s) - Creating HUD object\n", __func__, nic_name,
- mode == NIC_DIRECTION_RX ? "RX" :
- mode == NIC_DIRECTION_TX ? "TX" :
- mode == NIC_RSSI_DBM ? "RSSI" : "UNDEFINED");
-#endif
-
nic = find_nic_by_name(nic_name, mode);
if (!nic)
return;
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)
+ 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) {
}
}
+ closedir(dir);
list_for_each_entry(struct nic_info, nic, &gnic_list, list) {
char line[64];
}
+ pipe_mutex_unlock(gnic_mutex);
return gnic_count;
}