2 * Copyright 2009 Colin Günther, coling@gmx.de
3 * All Rights Reserved. Distributed under the terms of the MIT License.
8 /*! Implementation of a number allocator.*/
13 #include <compat/sys/mutex.h>
18 extern struct mtx gIdStoreLock
;
22 new_unrhdr(int low
, int high
, struct mtx
* mutex
)
24 struct unrhdr
* idStore
;
25 uint32 maxIdCount
= high
- low
+ 1;
28 ("ID-Store: use error: %s(%u, %u)", __func__
, low
, high
));
30 idStore
= malloc(sizeof *idStore
);
34 if (_new_unrhdr_buffer(idStore
, maxIdCount
) != B_OK
) {
40 idStore
->storeMutex
= mutex
;
42 idStore
->storeMutex
= &gIdStoreLock
;
44 idStore
->idBias
= low
;
51 delete_unrhdr(struct unrhdr
* idStore
)
54 ("ID-Store: %s: NULL pointer as argument.", __func__
));
56 mtx_lock(idStore
->storeMutex
);
58 KASSERT(uh
->idBuffer
->root_size
== 0,
59 ("ID-Store: %s: some ids are still in use..", __func__
));
61 _delete_unrhdr_buffer_locked(idStore
);
62 mtx_unlock(idStore
->storeMutex
);
70 alloc_unr(struct unrhdr
* idStore
)
75 ("ID-Store: %s: NULL pointer as argument.", __func__
));
77 mtx_lock(idStore
->storeMutex
);
78 id
= _alloc_unr_locked(idStore
);
79 mtx_unlock(idStore
->storeMutex
);
86 free_unr(struct unrhdr
* idStore
, u_int identity
)
89 ("ID-Store: %s: NULL pointer as argument.", __func__
));
91 mtx_lock(idStore
->storeMutex
);
93 KASSERT((int32
)item
- uh
->idBias
>= 0, ("ID-Store: %s(%p, %u): second "
94 + "parameter is not in interval.", __func__
, uh
, item
));
96 _free_unr_locked(idStore
, identity
);
98 mtx_unlock(idStore
->storeMutex
);