1/************************************************************************** 2 * 3 * Copyright 2010 Younes Manton. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include "util/u_handle_table.h" 29#include "os/os_thread.h" 30 31#include "va_private.h" 32 33#ifdef VL_HANDLES 34static struct handle_table *htab = NULL; 35pipe_static_mutex(htab_lock); 36#endif 37 38bool vlCreateHTAB(void) 39{ 40#ifdef VL_HANDLES 41 bool ret; 42 /* Make sure handle table handles match VAAPI handles. */ 43 assert(sizeof(unsigned) <= sizeof(VAGenericID)); 44 pipe_mutex_lock(htab_lock); 45 if (!htab) 46 htab = handle_table_create(); 47 ret = htab != NULL; 48 pipe_mutex_unlock(htab_lock); 49 return ret; 50#else 51 return TRUE; 52#endif 53} 54 55void vlDestroyHTAB(void) 56{ 57#ifdef VL_HANDLES 58 pipe_mutex_lock(htab_lock); 59 if (htab) { 60 handle_table_destroy(htab); 61 htab = NULL; 62 } 63 pipe_mutex_unlock(htab_lock); 64#endif 65} 66 67VAGenericID vlAddDataHTAB(void *data) 68{ 69 assert(data); 70#ifdef VL_HANDLES 71 VAGenericID handle = 0; 72 pipe_mutex_lock(htab_lock); 73 if (htab) 74 handle = handle_table_add(htab, data); 75 pipe_mutex_unlock(htab_lock); 76 return handle; 77#else 78 return (VAGenericID)data; 79#endif 80} 81 82void* vlGetDataHTAB(VAGenericID handle) 83{ 84 assert(handle); 85#ifdef VL_HANDLES 86 void *data = NULL; 87 pipe_mutex_lock(htab_lock); 88 if (htab) 89 data = handle_table_get(htab, handle); 90 pipe_mutex_unlock(htab_lock); 91 return data; 92#else 93 return (void*)handle; 94#endif 95} 96