virgl: move hash and compare functions to util

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent 3c830d5e28
commit ea52b1fa67
  1. 1
      src/Makefile.am
  2. 1
      src/meson.build
  3. 43
      src/virgl_util.c
  4. 4
      src/virgl_util.h
  5. 23
      src/vrend_object.c

@ -21,6 +21,7 @@ AM_CFLAGS = \
libvrend_la_SOURCES = \ libvrend_la_SOURCES = \
virgl_hw.h \ virgl_hw.h \
virgl_protocol.h \ virgl_protocol.h \
virgl_util.c \
virgl_util.h \ virgl_util.h \
vrend_iov.h \ vrend_iov.h \
vrend_renderer.c \ vrend_renderer.c \

@ -27,6 +27,7 @@ virgl_sources = [
'iov.c', 'iov.c',
'virgl_hw.h', 'virgl_hw.h',
'virgl_protocol.h', 'virgl_protocol.h',
'virgl_util.c',
'virgl_util.h', 'virgl_util.h',
'vrend_blitter.c', 'vrend_blitter.c',
'vrend_blitter.h', 'vrend_blitter.h',

@ -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;
}

@ -45,4 +45,8 @@ static inline bool is_only_bit(uint32_t mask, uint32_t bit)
return (mask == bit); return (mask == bit);
} }
unsigned hash_func_u32(void *key);
int compare_func(void *key1, void *key2);
#endif /* VIRGL_UTIL_H */ #endif /* VIRGL_UTIL_H */

@ -26,6 +26,7 @@
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_hash_table.h" #include "util/u_hash_table.h"
#include "virgl_util.h"
#include "vrend_object.h" #include "vrend_object.h"
struct vrend_object_types { struct vrend_object_types {
@ -44,24 +45,6 @@ void vrend_resource_set_destroy_callback(void (*cb)(void *))
resource_unref = cb; 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; static struct util_hash_table *res_hash;
struct vrend_object { 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 *vrend_object_init_ctx_table(void)
{ {
struct util_hash_table *ctx_hash; 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; return ctx_hash;
} }
@ -112,7 +95,7 @@ void
vrend_object_init_resource_table(void) vrend_object_init_resource_table(void)
{ {
if (!res_hash) 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) void vrend_object_fini_resource_table(void)

Loading…
Cancel
Save