Restore the "GPL licensing not permitted" in GLUT license headers.
[haiku.git] / src / libs / compat / freebsd_network / Unit.cpp
blob390878ef148f4b692157a2ef8e6661d16540c229
1 /*
2 * Copyright 2009 Colin Günther, coling@gmx.de
3 * All Rights Reserved. Distributed under the terms of the MIT License.
5 */
8 /*! Wrapper functions for accessing the number buffer.*/
11 #include "unit.h"
13 #include <util/RadixBitmap.h>
16 #define ID_STORE_FULL -1
19 status_t
20 _new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount)
22 status_t status = B_OK;
24 idStore->idBuffer = radix_bitmap_create(maxIdCount);
25 if (idStore->idBuffer == NULL)
26 status = B_NO_MEMORY;
28 return status;
32 void
33 _delete_unrhdr_buffer_locked(struct unrhdr* idStore)
35 radix_bitmap_destroy(idStore->idBuffer);
39 int
40 _alloc_unr_locked(struct unrhdr* idStore)
42 radix_slot_t slotIndex;
43 int id = ID_STORE_FULL;
45 slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1);
46 if (slotIndex != RADIX_SLOT_NONE)
47 id = slotIndex + idStore->idBias;
49 return id;
53 void
54 _free_unr_locked(struct unrhdr* idStore, u_int identity)
56 uint32 slotIndex = (int32)identity - idStore->idBias;
58 radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1);