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

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