Path: blob/21.2-virgl/src/gallium/frontends/vdpau/htab.c
4565 views
/**************************************************************************1*2* Copyright 2010 Younes Manton.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "util/u_handle_table.h"28#include "os/os_thread.h"29#include "vdpau_private.h"3031static struct handle_table *htab = NULL;32static mtx_t htab_lock = _MTX_INITIALIZER_NP;3334boolean vlCreateHTAB(void)35{36boolean ret;3738/* Make sure handle table handles match VDPAU handles. */39assert(sizeof(unsigned) <= sizeof(vlHandle));40mtx_lock(&htab_lock);41if (!htab)42htab = handle_table_create();43ret = htab != NULL;44mtx_unlock(&htab_lock);45return ret;46}4748void vlDestroyHTAB(void)49{50mtx_lock(&htab_lock);51if (htab && !handle_table_get_first_handle(htab)) {52handle_table_destroy(htab);53htab = NULL;54}55mtx_unlock(&htab_lock);56}5758vlHandle vlAddDataHTAB(void *data)59{60vlHandle handle = 0;6162assert(data);63mtx_lock(&htab_lock);64if (htab)65handle = handle_table_add(htab, data);66mtx_unlock(&htab_lock);67return handle;68}6970void* vlGetDataHTAB(vlHandle handle)71{72void *data = NULL;7374assert(handle);75mtx_lock(&htab_lock);76if (htab)77data = handle_table_get(htab, handle);78mtx_unlock(&htab_lock);79return data;80}8182void vlRemoveDataHTAB(vlHandle handle)83{84mtx_lock(&htab_lock);85if (htab)86handle_table_remove(htab, handle);87mtx_unlock(&htab_lock);88}899091