futex.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020 Richard Braun.
  3. * Copyright (c) 2020 Agustina Arzille.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. *
  19. * Fast wait queues for userspace and kernel.
  20. */
  21. #ifndef KERN_FUTEX_H
  22. #define KERN_FUTEX_H
  23. #include <stdint.h>
  24. #define FUTEX_TIMED 0x01
  25. #define FUTEX_ABS 0x02
  26. #define FUTEX_BROADCAST 0x04
  27. #define FUTEX_MODIFY 0x08
  28. /*
  29. * Test that the futex address still contains the expected value, and if so,
  30. * sleep until another thread calls 'futex_wake' on the same address, or
  31. * a timeout elapses (if FUTEX_TIMED is set on the flags).
  32. *
  33. * If the futex address does not contain the expected value, the call returns
  34. * immediately with EAGAIN.
  35. */
  36. int futex_wait(void *addr, int value, unsigned int flags, uint64_t ticks);
  37. /*
  38. * Wake one or all waiters that are sleeping on a futex address (depending on
  39. * whether the FUTEX_BROADCAST flag is set or not). If FUTEX_MODIFY is in the
  40. * flags, set the content of the address to the value before waking up threads.
  41. */
  42. int futex_wake(void *addr, unsigned int flags, int value);
  43. /*
  44. * Rearrange the waiting queues so that threads waiting on a futex address
  45. * start waiting on a different address. Prior to requeueing, a thread may
  46. * be woken up if 'wake_one' is set. If FUTEX_BROADCAST is set, all threads
  47. * are moved instead of just one.
  48. */
  49. int futex_requeue(void *src_addr, void *dst_addr,
  50. unsigned int flags, bool wake_one);
  51. #endif