async library for manda (adaptive backend manager protocol)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

40 lines
1.2 KiB

  1. #ifndef _LIBMANDA_IDLIST_H_
  2. #define _LIBMANDA_IDLIST_H_
  3. #include "libmanda.h"
  4. struct manda_IDList {
  5. /* used ids are marked with a "1" in the bitvector (represented as array of gulong) */
  6. GArray *bitvector;
  7. /* all ids are in the range [0, max_ids[, i.e. 0 <= id < max_ids
  8. * although the type is guint, it has to fit in a gint too, as we
  9. * use gint for the ids in the interface, so we can use -1 as a special value.
  10. */
  11. guint max_ids;
  12. /* if all ids in [0, used_ids-1] are used, next_free_id is -1
  13. * if not, then all available ids are >= next_free_id,
  14. * so we can start at next_free_id for searching the next free id
  15. */
  16. gint next_free_id;
  17. guint used_ids;
  18. };
  19. /* create new idlist; the parameter max_ids is "signed" on purpose */
  20. manda_IDList* manda_idlist_new(gint max_ids);
  21. /* free idlist */
  22. void manda_idlist_free(manda_IDList *l);
  23. /* request new id; return -1 if no id is available, valid ids are always > 0 */
  24. gint manda_idlist_get(manda_IDList *l);
  25. /* check whether an id is in use and can be "_put" */
  26. gboolean manda_idlist_is_used(manda_IDList *l, gint id);
  27. /* release id. never release an id more than once! */
  28. void manda_idlist_put(manda_IDList *l, gint id);
  29. #endif