idset_alloc(3)
SYNOPSIS
#include <flux/idset.h>
int idset_alloc (struct idset *idset, unsigned int *val);
void idset_free (struct idset *idset, unsigned int val);
int idset_free_check (struct idset *idset, unsigned int val);
Link with -lflux-idset.
DESCRIPTION
Refer to idset_create(3) for a general description of idsets.
These functions are useful when using an idset as an integer allocator. The idset must have been created with IDSET_FLAG_INITFULL.
Note
Unallocated is defined as "in the set" so that allocation can use the constant-time first operation to find the next available id. Defining unallocated as "not in the set" would mean that iteration would be required to find the next available id.
idset_alloc()
takes the next available id out of the set.
This is implemented as idset_first()
and idset_clear()
internally.
If there are no more ids available and the set was created with
IDSET_FLAG_AUTOGROW, the set is expanded in order to fulfill the request.
idset_free()
puts an id back in the set. This is implemented
as idset_set()
internally.
idset_free_check()
is identical to the above, except it fails
if the id is already in the set. This is implemented as idset_test()
and idset_set()
internally.
RETURN VALUE
idset_alloc()
and idset_free_check()
return 0 on success, or
-1 on error with errno
set.
ERRORS
- EINVAL
One or more arguments were invalid.
- ENOMEM
Out of memory.
- EEXIST
idset_free_check()
was called on an id that is already in the idset.
RESOURCES
Flux: http://flux-framework.org
Flux RFC: https://flux-framework.readthedocs.io/projects/flux-rfc
Issue Tracker: https://github.com/flux-framework/flux-core/issues