Copyright (c) 2005 Gleb Smirnoff <glebius@FreeBSD.org> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the doc...
NAMEnew_unrhdr delete_unrhdr alloc_unr alloc_unr_specific free_unr - kernel unit number allocator
SYNOPSISIn sys/systm.h Ft struct unrhdr * Fn new_unrhdr int low int high struct mtx *mutex Ft void Fn delete_unrhdr struct unrhdr *uh Ft int Fn alloc_unr struct unrhdr *uh Ft int Fn alloc_unrl struct unrhdr *uh Ft int Fn alloc_unr_specific struct unrhdr *uh u_int item Ft void Fn free_unr struct unrhdr *uh u_int item
DESCRIPTIONThe kernel unit number allocator is a generic facility, which allows to allocate unit numbers within a specified range.
- Fn new_unrhdr low high mutex
- Initialize a new unit number allocator entity. The Fa low and Fa 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 Fa mutex is not NULL it is used for locking when allocating and freeing units. Otherwise, internal mutex is used.
- Fn delete_unrhdr uh
- Destroy specified unit number allocator entity.
- Fn alloc_unr uh
- Return a new unit number. The lowest free number is always allocated. This function does not allocate memory and never sleeps, however it may block on a mutex. If no free unit numbers are left, -1 is returned.
- Fn alloc_unrl uh
- Same as Fn alloc_unr except that mutex is assumed to be already locked and thus is not used.
- Fn 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.
- Fn free_unr uh item
- Free a previously allocated unit number. This function may require allocating memory, and thus it can sleep. There is no pre-locked variant.