1fb2f18f8Sesaxe /* 2fb2f18f8Sesaxe * CDDL HEADER START 3fb2f18f8Sesaxe * 4fb2f18f8Sesaxe * The contents of this file are subject to the terms of the 5fb2f18f8Sesaxe * Common Development and Distribution License (the "License"). 6fb2f18f8Sesaxe * You may not use this file except in compliance with the License. 7fb2f18f8Sesaxe * 8fb2f18f8Sesaxe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fb2f18f8Sesaxe * or http://www.opensolaris.org/os/licensing. 10fb2f18f8Sesaxe * See the License for the specific language governing permissions 11fb2f18f8Sesaxe * and limitations under the License. 12fb2f18f8Sesaxe * 13fb2f18f8Sesaxe * When distributing Covered Code, include this CDDL HEADER in each 14fb2f18f8Sesaxe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fb2f18f8Sesaxe * If applicable, add the following below this CDDL HEADER, with the 16fb2f18f8Sesaxe * fields enclosed by brackets "[]" replaced with your own identifying 17fb2f18f8Sesaxe * information: Portions Copyright [yyyy] [name of copyright owner] 18fb2f18f8Sesaxe * 19fb2f18f8Sesaxe * CDDL HEADER END 20fb2f18f8Sesaxe */ 21fb2f18f8Sesaxe /* 220542eecfSRafael Vanoni * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 23*f06dce2cSAndrew Stormont * Copyright 2017 RackTop Systems. 24fb2f18f8Sesaxe */ 25fb2f18f8Sesaxe 26fb2f18f8Sesaxe #ifndef _BITSET_H 27fb2f18f8Sesaxe #define _BITSET_H 28fb2f18f8Sesaxe 29fb2f18f8Sesaxe #ifdef __cplusplus 30fb2f18f8Sesaxe extern "C" { 31fb2f18f8Sesaxe #endif 32fb2f18f8Sesaxe 33*f06dce2cSAndrew Stormont #if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER) 34fb2f18f8Sesaxe #include <sys/bitmap.h> 35fb2f18f8Sesaxe #include <sys/types.h> 36fb2f18f8Sesaxe 37fb2f18f8Sesaxe typedef struct bitset { 38fb2f18f8Sesaxe ulong_t *bs_set; 39fb2f18f8Sesaxe uint_t bs_words; 400542eecfSRafael Vanoni uint_t bs_fanout; 41fb2f18f8Sesaxe } bitset_t; 42fb2f18f8Sesaxe 43fb2f18f8Sesaxe /* 44fb2f18f8Sesaxe * Bitset initialiation / teardown 45fb2f18f8Sesaxe */ 46fb2f18f8Sesaxe void bitset_init(bitset_t *); 470542eecfSRafael Vanoni void bitset_init_fanout(bitset_t *, uint_t); 48fb2f18f8Sesaxe void bitset_fini(bitset_t *); 49fb2f18f8Sesaxe 50fb2f18f8Sesaxe /* 51fb2f18f8Sesaxe * Resize / query a bitset's holding capacity 52fb2f18f8Sesaxe */ 53fb2f18f8Sesaxe void bitset_resize(bitset_t *, uint_t); 54fb2f18f8Sesaxe uint_t bitset_capacity(bitset_t *); 55fb2f18f8Sesaxe 56fb2f18f8Sesaxe /* 57fb2f18f8Sesaxe * Set / clear a bit in the set 58fb2f18f8Sesaxe */ 59fb2f18f8Sesaxe void bitset_add(bitset_t *, uint_t); 60fb2f18f8Sesaxe void bitset_del(bitset_t *, uint_t); 61fb2f18f8Sesaxe 626890d023SEric Saxe /* 636890d023SEric Saxe * Atomic operations 646890d023SEric Saxe */ 656890d023SEric Saxe void bitset_atomic_add(bitset_t *, uint_t); 666890d023SEric Saxe void bitset_atomic_del(bitset_t *, uint_t); 676890d023SEric Saxe int bitset_atomic_test_and_add(bitset_t *, uint_t); 686890d023SEric Saxe int bitset_atomic_test_and_del(bitset_t *, uint_t); 696890d023SEric Saxe 70fb2f18f8Sesaxe /* 71fb2f18f8Sesaxe * Bitset queries 72fb2f18f8Sesaxe */ 73fb2f18f8Sesaxe int bitset_in_set(bitset_t *, uint_t); 74fb2f18f8Sesaxe int bitset_is_null(bitset_t *); 75fb2f18f8Sesaxe uint_t bitset_find(bitset_t *); 76fb2f18f8Sesaxe 774c06356bSdh /* 784c06356bSdh * Bitset computations 794c06356bSdh */ 804c06356bSdh int bitset_and(bitset_t *, bitset_t *, bitset_t *); 814c06356bSdh int bitset_or(bitset_t *, bitset_t *, bitset_t *); 824c06356bSdh int bitset_xor(bitset_t *, bitset_t *, bitset_t *); 834c06356bSdh 844c06356bSdh /* 854c06356bSdh * Miscellaneous bitset operations 864c06356bSdh */ 874c06356bSdh void bitset_zero(bitset_t *); 884c06356bSdh void bitset_copy(bitset_t *, bitset_t *); 894c06356bSdh int bitset_match(bitset_t *, bitset_t *); 904c06356bSdh 91*f06dce2cSAndrew Stormont #endif /* _KERNEL || _FAKE_KERNEL || _KMEMUSER */ 92fb2f18f8Sesaxe 93fb2f18f8Sesaxe #ifdef __cplusplus 94fb2f18f8Sesaxe } 95fb2f18f8Sesaxe #endif 96fb2f18f8Sesaxe 97fb2f18f8Sesaxe #endif /* _BITSET_H */ 98