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.

refcnt.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef _GPXE_REFCNT_H
  2. #define _GPXE_REFCNT_H
  3. /** @file
  4. *
  5. * Reference counting
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. /**
  10. * A reference counter
  11. *
  12. * This data structure is designed to be embedded within a
  13. * reference-counted object.
  14. *
  15. * Reference-counted objects are freed when their reference count
  16. * drops below zero. This means that a freshly allocated-and-zeroed
  17. * reference-counted object will be freed on the first call to
  18. * ref_put().
  19. */
  20. struct refcnt {
  21. /** Current reference count
  22. *
  23. * When this count is decremented below zero, the free()
  24. * method will be called.
  25. */
  26. int refcnt;
  27. /** Free containing object
  28. *
  29. * This method is called when the reference count is
  30. * decremented below zero.
  31. *
  32. * If this method is left NULL, the standard library free()
  33. * function will be called. The upshot of this is that you
  34. * may omit the free() method if the @c refcnt object is the
  35. * first element of your reference-counted struct.
  36. */
  37. void ( * free ) ( struct refcnt *refcnt );
  38. };
  39. extern struct refcnt * ref_get ( struct refcnt *refcnt );
  40. extern void ref_put ( struct refcnt *refcnt );
  41. #endif /* _GPXE_REFCNT_H */