ALLOC_UNR(9FREEBSD) - Linux man page online | System kernel interfaces

Kernel unit number allocator.

July 5, 2010
UNR(9) BSD Kernel Developer's Manual UNR(9)


new_unrhdr, delete_unrhdr, alloc_unr, alloc_unr_specific, free_unr — kernel unit number allocator


#include <sys/systm.h> struct unrhdr * new_unrhdr(int low, int high, struct mtx *mutex); void delete_unrhdr(struct unrhdr *uh); int alloc_unr(struct unrhdr *uh); int alloc_unrl(struct unrhdr *uh); int alloc_unr_specific(struct unrhdr *uh, u_int item); void free_unr(struct unrhdr *uh, u_int item);


The kernel unit number allocator is a generic facility, which allows to allocate unit num‐ bers within a specified range. new_unrhdr(low, high, mutex) Initialize a new unit number allocator entity. The low and high arguments specify minimum and maximum number of unit numbers. There is no cost associated with the range of unit numbers, so unless the resource really is finite, INT_MAX can be used. If mutex is not NULL, it is used for locking when allocating and freeing units. Otherwise, internal mutex is used. delete_unrhdr(uh) Destroy specified unit number allocator entity. alloc_unr(uh) Return a new unit number. The lowest free number is always allocated. This func‐ tion does not allocate memory and never sleeps, however it may block on a mutex. If no free unit numbers are left, -1 is returned. alloc_unrl(uh) Same as alloc_unr() except that mutex is assumed to be already locked and thus is not used. alloc_unr_specific(uh, item) Allocate a specific unit number. This function allocates memory and thus may sleep. The allocated unit number is returned on success. If the specified number is already allocated or out of the range, -1 is returned. free_unr(uh, item) Free a previously allocated unit number. This function may require allocating mem‐ ory, and thus it can sleep. There is no pre-locked variant.


The above functions are implemented in sys/kern/subr_unit.c.


Kernel unit number allocator first appeared in FreeBSD 6.0.


Kernel unit number allocator was written by Poul-Henning Kamp. This manpage was written by Gleb Smirnoff.
BSD July 5, 2010 BSD
This manual Reference Other manuals
alloc_unr(9freebsd) referred by
refer to unr(9freebsd)
Download raw manual
Index BSD Kernel Developer's Manual (+1909) BSD (+3984) № 9 (+1939)
Go top