lfitem.c 473 B

12345678910111213141516171819202122232425
  1. #include "nu/lfitem.h"
  2. #include "foundation/atomics.h"
  3. void lfitem_init(lfitem_t item)
  4. {
  5. item->item=0;
  6. }
  7. void *lfitem_get(lfitem_t item)
  8. {
  9. return nx_atomic_swap_pointer(0, &(item->item));
  10. }
  11. void *lfitem_set(lfitem_t item, const void *value)
  12. {
  13. return nx_atomic_swap_pointer((void *)value, &(item->item));
  14. }
  15. void *lfitem_set_if_zero(lfitem_t item, void *value)
  16. {
  17. if (nx_atomic_cmpxchg_pointer(0, value, &(item->item)) == 0)
  18. return 0;
  19. else
  20. return (void *)value;
  21. }