atomic_c.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 1997-2015, Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_
  7. #define ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_
  8. /* Included from <atomic.h> */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Simple and correct (but very slow) implementation of atomic
  13. * primitives that require nothing more than kernel interrupt locking.
  14. */
  15. __syscall bool atomic_cas(atomic_t *target, atomic_val_t old_value,
  16. atomic_val_t new_value);
  17. __syscall bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value,
  18. atomic_ptr_val_t new_value);
  19. __syscall atomic_val_t atomic_add(atomic_t *target, atomic_val_t value);
  20. __syscall atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value);
  21. static inline atomic_val_t atomic_inc(atomic_t *target)
  22. {
  23. return atomic_add(target, 1);
  24. }
  25. static inline atomic_val_t atomic_dec(atomic_t *target)
  26. {
  27. return atomic_sub(target, 1);
  28. }
  29. extern atomic_val_t atomic_get(const atomic_t *target);
  30. extern atomic_ptr_val_t atomic_ptr_get(const atomic_ptr_t *target);
  31. __syscall atomic_val_t atomic_set(atomic_t *target, atomic_val_t value);
  32. __syscall atomic_ptr_val_t atomic_ptr_set(atomic_ptr_t *target, atomic_ptr_val_t value);
  33. static inline atomic_val_t atomic_clear(atomic_t *target)
  34. {
  35. return atomic_set(target, 0);
  36. }
  37. static inline atomic_ptr_val_t atomic_ptr_clear(atomic_ptr_t *target)
  38. {
  39. return atomic_ptr_set(target, NULL);
  40. }
  41. __syscall atomic_val_t atomic_or(atomic_t *target, atomic_val_t value);
  42. __syscall atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value);
  43. __syscall atomic_val_t atomic_and(atomic_t *target, atomic_val_t value);
  44. __syscall atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #ifdef CONFIG_ATOMIC_OPERATIONS_C
  49. #include <syscalls/atomic_c.h>
  50. #endif
  51. #endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_ */