Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_handle_table.h
4561 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.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/**28* @file29* Generic handle table.30*31* @author José Fonseca <[email protected]>32*/3334#ifndef U_HANDLE_TABLE_H_35#define U_HANDLE_TABLE_H_363738#ifdef __cplusplus39extern "C" {40#endif414243/**44* Abstract data type to map integer handles to objects.45*46* Also referred as "pointer array".47*/48struct handle_table;495051struct handle_table *52handle_table_create(void);535455/**56* Set an optional destructor callback.57*58* If set, it will be called during handle_table_remove and59* handle_table_destroy calls.60*/61void62handle_table_set_destroy(struct handle_table *ht,63void (*destroy)(void *object));646566/**67* Add a new object.68*69* Returns a zero handle on failure (out of memory).70*/71unsigned72handle_table_add(struct handle_table *ht,73void *object);7475/**76* Returns zero on failure (out of memory).77*/78unsigned79handle_table_set(struct handle_table *ht,80unsigned handle,81void *object);8283/**84* Fetch an existing object.85*86* Returns NULL for an invalid handle.87*/88void *89handle_table_get(struct handle_table *ht,90unsigned handle);919293void94handle_table_remove(struct handle_table *ht,95unsigned handle);969798void99handle_table_destroy(struct handle_table *ht);100101102unsigned103handle_table_get_first_handle(struct handle_table *ht);104105106unsigned107handle_table_get_next_handle(struct handle_table *ht,108unsigned handle);109110111#ifdef __cplusplus112}113#endif114115#endif /* U_HANDLE_TABLE_H_ */116117118