From ea52b1fa67df6e446b285f5719fb30a26f774cf4 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 25 Mar 2020 17:49:32 -0700 Subject: [PATCH] virgl: move hash and compare functions to util Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/Makefile.am | 1 + src/meson.build | 1 + src/virgl_util.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/virgl_util.h | 4 ++++ src/vrend_object.c | 23 +++-------------------- 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 src/virgl_util.c diff --git a/src/Makefile.am b/src/Makefile.am index def2fe2..295bb84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ AM_CFLAGS = \ libvrend_la_SOURCES = \ virgl_hw.h \ virgl_protocol.h \ + virgl_util.c \ virgl_util.h \ vrend_iov.h \ vrend_renderer.c \ diff --git a/src/meson.build b/src/meson.build index 06d55bc..44a13c4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -27,6 +27,7 @@ virgl_sources = [ 'iov.c', 'virgl_hw.h', 'virgl_protocol.h', + 'virgl_util.c', 'virgl_util.h', 'vrend_blitter.c', 'vrend_blitter.h', diff --git a/src/virgl_util.c b/src/virgl_util.c new file mode 100644 index 0000000..bf8ce88 --- /dev/null +++ b/src/virgl_util.c @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright (C) 2019 Chromium. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "virgl_util.h" + +#include "util/u_pointer.h" + +unsigned hash_func_u32(void *key) +{ + intptr_t ip = pointer_to_intptr(key); + return (unsigned)(ip & 0xffffffff); +} + +int compare_func(void *key1, void *key2) +{ + if (key1 < key2) + return -1; + if (key1 > key2) + return 1; + else + return 0; +} diff --git a/src/virgl_util.h b/src/virgl_util.h index c0854ec..84d6ef8 100644 --- a/src/virgl_util.h +++ b/src/virgl_util.h @@ -45,4 +45,8 @@ static inline bool is_only_bit(uint32_t mask, uint32_t bit) return (mask == bit); } +unsigned hash_func_u32(void *key); + +int compare_func(void *key1, void *key2); + #endif /* VIRGL_UTIL_H */ diff --git a/src/vrend_object.c b/src/vrend_object.c index c00731a..03daa8d 100644 --- a/src/vrend_object.c +++ b/src/vrend_object.c @@ -26,6 +26,7 @@ #include "util/u_memory.h" #include "util/u_hash_table.h" +#include "virgl_util.h" #include "vrend_object.h" struct vrend_object_types { @@ -44,24 +45,6 @@ void vrend_resource_set_destroy_callback(void (*cb)(void *)) resource_unref = cb; } -static unsigned -hash_func(void *key) -{ - intptr_t ip = pointer_to_intptr(key); - return (unsigned)(ip & 0xffffffff); -} - -static int -compare(void *key1, void *key2) -{ - if (key1 < key2) - return -1; - if (key1 > key2) - return 1; - else - return 0; -} - static struct util_hash_table *res_hash; struct vrend_object { @@ -89,7 +72,7 @@ static void free_object(void *value) struct util_hash_table *vrend_object_init_ctx_table(void) { struct util_hash_table *ctx_hash; - ctx_hash = util_hash_table_create(hash_func, compare, free_object); + ctx_hash = util_hash_table_create(hash_func_u32, compare_func, free_object); return ctx_hash; } @@ -112,7 +95,7 @@ void vrend_object_init_resource_table(void) { if (!res_hash) - res_hash = util_hash_table_create(hash_func, compare, free_res); + res_hash = util_hash_table_create(hash_func_u32, compare_func, free_res); } void vrend_object_fini_resource_table(void)