1848b8605Smrg/************************************************************************** 2b8e80941Smrg * 3848b8605Smrg * Copyright 2009 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5b8e80941Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13b8e80941Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17b8e80941Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25b8e80941Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * @file 30848b8605Smrg * Generic bitmask. 31b8e80941Smrg * 32848b8605Smrg * @author Jose Fonseca <jfonseca@vmware.com> 33848b8605Smrg */ 34848b8605Smrg 35848b8605Smrg#ifndef U_HANDLE_BITMASK_H_ 36848b8605Smrg#define U_HANDLE_BITMASK_H_ 37848b8605Smrg 38848b8605Smrg 39848b8605Smrg#include "pipe/p_compiler.h" 40848b8605Smrg 41848b8605Smrg 42848b8605Smrg#ifdef __cplusplus 43848b8605Smrgextern "C" { 44848b8605Smrg#endif 45848b8605Smrg 46848b8605Smrg 47848b8605Smrg#define UTIL_BITMASK_INVALID_INDEX (~0U) 48b8e80941Smrg 49b8e80941Smrg 50848b8605Smrg/** 51848b8605Smrg * Abstract data type to represent arbitrary set of bits. 52848b8605Smrg */ 53848b8605Smrgstruct util_bitmask; 54848b8605Smrg 55848b8605Smrg 56848b8605Smrgstruct util_bitmask * 57848b8605Smrgutil_bitmask_create(void); 58848b8605Smrg 59848b8605Smrg 60848b8605Smrg/** 61848b8605Smrg * Search a cleared bit and set it. 62b8e80941Smrg * 63848b8605Smrg * It searches for the first cleared bit. 64b8e80941Smrg * 65b8e80941Smrg * Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of 66848b8605Smrg * memory growing the bitmask. 67848b8605Smrg */ 68848b8605Smrgunsigned 69848b8605Smrgutil_bitmask_add(struct util_bitmask *bm); 70848b8605Smrg 71848b8605Smrg/** 72848b8605Smrg * Set a bit. 73b8e80941Smrg * 74b8e80941Smrg * Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of 75848b8605Smrg * memory growing the bitmask. 76848b8605Smrg */ 77848b8605Smrgunsigned 78b8e80941Smrgutil_bitmask_set(struct util_bitmask *bm, 79848b8605Smrg unsigned index); 80848b8605Smrg 81848b8605Smrgvoid 82b8e80941Smrgutil_bitmask_clear(struct util_bitmask *bm, 83848b8605Smrg unsigned index); 84848b8605Smrg 85848b8605Smrgboolean 86b8e80941Smrgutil_bitmask_get(struct util_bitmask *bm, 87848b8605Smrg unsigned index); 88848b8605Smrg 89848b8605Smrg 90848b8605Smrgvoid 91848b8605Smrgutil_bitmask_destroy(struct util_bitmask *bm); 92848b8605Smrg 93848b8605Smrg 94848b8605Smrg/** 95848b8605Smrg * Search for the first set bit. 96b8e80941Smrg * 97b8e80941Smrg * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. 98848b8605Smrg */ 99848b8605Smrgunsigned 100848b8605Smrgutil_bitmask_get_first_index(struct util_bitmask *bm); 101848b8605Smrg 102848b8605Smrg 103848b8605Smrg/** 104848b8605Smrg * Search for the first set bit, starting from the giving index. 105b8e80941Smrg * 106b8e80941Smrg * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. 107848b8605Smrg */ 108848b8605Smrgunsigned 109848b8605Smrgutil_bitmask_get_next_index(struct util_bitmask *bm, 110848b8605Smrg unsigned index); 111848b8605Smrg 112848b8605Smrg 113848b8605Smrg#ifdef __cplusplus 114848b8605Smrg} 115848b8605Smrg#endif 116848b8605Smrg 117848b8605Smrg#endif /* U_HANDLE_BITMASK_H_ */ 118