logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

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

Authors

       Kernel unit number allocator was written  by  Poul-Henning  Kamp.   This  manpage  was  written  by  Gleb
       Smirnoff.

Debian                                           October 4, 2017                                          UNR(9)

Code References

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

Description

       The kernel unit number allocator is a generic facility, which allows to allocate unit  numbers  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.

       clear_unrhdr(uh)
               Clear all units from the specified unit number allocator entity.  This function resets the entity
               as if it were just initialized with new_unrhdr().

       delete_unrhdr(uh)
               Delete specified unit number allocator entity.  This function frees the  memory  associated  with
               the entity, it does not free any units.  To free all units use clear_unrhdr().

       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.

       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 memory, and thus
               it can sleep.  There is no pre-locked variant.

History

       Kernel unit number allocator first appeared in FreeBSD 6.0.

Name

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

Synopsis

#include<sys/systm.h>structunrhdr*new_unrhdr(intlow, inthigh, structmtx*mutex);

       voidclear_unrhdr(structunrhdr*uh);

       voiddelete_unrhdr(structunrhdr*uh);

       intalloc_unr(structunrhdr*uh);

       intalloc_unrl(structunrhdr*uh);

       intalloc_unr_specific(structunrhdr*uh, u_intitem);

       voidfree_unr(structunrhdr*uh, u_intitem);

See Also