#include "util/u_hash_table.h"
#include "util/hash_table.h"
+#if DETECT_OS_UNIX
+#include <sys/stat.h>
+#endif
+
struct util_hash_table
{
}
+static unsigned hash_fd(void *key)
+{
+#if DETECT_OS_UNIX
+ int fd = pointer_to_intptr(key);
+ struct stat stat;
+
+ fstat(fd, &stat);
+
+ return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
+#else
+ return 0;
+#endif
+}
+
+
+static int compare_fd(void *key1, void *key2)
+{
+#if DETECT_OS_UNIX
+ int fd1 = pointer_to_intptr(key1);
+ int fd2 = pointer_to_intptr(key2);
+ struct stat stat1, stat2;
+
+ fstat(fd1, &stat1);
+ fstat(fd2, &stat2);
+
+ return stat1.st_dev != stat2.st_dev ||
+ stat1.st_ino != stat2.st_ino ||
+ stat1.st_rdev != stat2.st_rdev;
+#else
+ return 0;
+#endif
+}
+
+
+struct util_hash_table *
+util_hash_table_create_fd_keys(void)
+{
+ return util_hash_table_create(hash_fd, compare_fd);
+}
+
+
static inline struct cso_hash_iter
util_hash_table_find_iter(struct util_hash_table *ht,
void *key,
util_hash_table_create_ptr_keys(void);
+/**
+ * Create a hash table where the keys are device FDs.
+ */
+struct util_hash_table *
+util_hash_table_create_fd_keys(void);
+
+
enum pipe_error
util_hash_table_set(struct util_hash_table *ht,
void *key,
}
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
-
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
-
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
struct pipe_screen *
etna_drm_screen_create_renderonly(struct renderonly *ro)
{
mtx_lock(&etna_screen_mutex);
if (!etna_tab) {
- etna_tab = util_hash_table_create(hash_fd, compare_fd);
+ etna_tab = util_hash_table_create_fd_keys();
if (!etna_tab)
goto unlock;
}
}
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
struct pipe_screen *
fd_drm_screen_create(int fd, struct renderonly *ro)
{
mtx_lock(&fd_screen_mutex);
if (!fd_tab) {
- fd_tab = util_hash_table_create(hash_fd, compare_fd);
+ fd_tab = util_hash_table_create_fd_keys();
if (!fd_tab)
goto unlock;
}
}
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
-
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
-
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
struct pipe_screen *
lima_drm_screen_create(int fd)
{
mtx_lock(&lima_screen_mutex);
if (!fd_tab) {
- fd_tab = util_hash_table_create(hash_fd, compare_fd);
+ fd_tab = util_hash_table_create_fd_keys();
if (!fd_tab)
goto unlock;
}
return ret == 0;
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
PUBLIC struct pipe_screen *
nouveau_drm_screen_create(int fd)
{
mtx_lock(&nouveau_screen_mutex);
if (!fd_tab) {
- fd_tab = util_hash_table_create(hash_fd, compare_fd);
+ fd_tab = util_hash_table_create_fd_keys();
if (!fd_tab) {
mtx_unlock(&nouveau_screen_mutex);
return NULL;
return true;
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
DEBUG_GET_ONCE_BOOL_OPTION(thread, "RADEON_THREAD", true)
static bool radeon_winsys_unref(struct radeon_winsys *ws)
mtx_lock(&fd_tab_mutex);
if (!fd_tab) {
- fd_tab = util_hash_table_create(hash_fd, compare_fd);
+ fd_tab = util_hash_table_create_fd_keys();
}
ws = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
}
}
-static unsigned hash_fd(void *key)
-{
- int fd = pointer_to_intptr(key);
- struct stat stat;
- fstat(fd, &stat);
-
- return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
- int fd1 = pointer_to_intptr(key1);
- int fd2 = pointer_to_intptr(key2);
- struct stat stat1, stat2;
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino ||
- stat1.st_rdev != stat2.st_rdev;
-}
-
struct pipe_screen *
virgl_drm_screen_create(int fd, const struct pipe_screen_config *config)
{
mtx_lock(&virgl_screen_mutex);
if (!fd_tab) {
- fd_tab = util_hash_table_create(hash_fd, compare_fd);
+ fd_tab = util_hash_table_create_fd_keys();
if (!fd_tab)
goto unlock;
}