lwp_futex_internal.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-11-01 Shell Init ver.
  9. */
  10. #ifndef __LWP_FUTEX_INTERNAL_H__
  11. #define __LWP_FUTEX_INTERNAL_H__
  12. #define DBG_TAG "lwp.futex"
  13. #define DBG_LVL DBG_INFO
  14. #include <rtdbg.h>
  15. #include "rt_uthash.h"
  16. #include "lwp_internal.h"
  17. #include "lwp_pid.h"
  18. #include <rtthread.h>
  19. #include <lwp.h>
  20. #ifdef ARCH_MM_MMU
  21. #include <lwp_user_mm.h>
  22. #endif /* ARCH_MM_MMU */
  23. /**
  24. * @brief Shared futex key structure
  25. *
  26. * @note This structure represents a key used to identify shared futexes
  27. * in the system.
  28. */
  29. struct shared_futex_key
  30. {
  31. rt_mem_obj_t mobj; /**< Memory object associated with the futex */
  32. rt_base_t offset; /**< Offset within the memory object */
  33. };
  34. DEFINE_RT_UTHASH_TYPE(shared_futex_entry, struct shared_futex_key, key);
  35. /**
  36. * @brief Futex structure for thread synchronization
  37. *
  38. * @note This structure represents a futex used for thread synchronization.
  39. * It can be either private (process-local) or shared between processes.
  40. */
  41. struct rt_futex
  42. {
  43. union
  44. {
  45. /* for private futex */
  46. struct lwp_avl_struct node; /**< AVL tree node for private futex */
  47. /* for shared futex */
  48. struct shared_futex_entry entry; /**< Entry for shared futex */
  49. };
  50. rt_list_t waiting_thread; /**< List of threads waiting on the futex */
  51. struct rt_object *custom_obj; /**< Custom object associated with the futex */
  52. rt_mutex_t mutex; /**< kernel mutex object for futex */
  53. };
  54. typedef struct rt_futex *rt_futex_t;
  55. rt_err_t futex_global_table_add(struct shared_futex_key *key, rt_futex_t futex);
  56. rt_err_t futex_global_table_find(struct shared_futex_key *key, rt_futex_t *futex);
  57. rt_err_t futex_global_table_delete(struct shared_futex_key *key);
  58. #endif /* __LWP_FUTEX_INTERNAL_H__ */