1 /*
2  * Copyright (c) 2006-2023, 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 
13 #define DBG_TAG "lwp.futex"
14 #define DBG_LVL DBG_INFO
15 #include <rtdbg.h>
16 
17 #include "rt_uthash.h"
18 #include "lwp_internal.h"
19 #include "lwp_pid.h"
20 
21 #include <rtthread.h>
22 #include <lwp.h>
23 
24 #ifdef ARCH_MM_MMU
25 #include <lwp_user_mm.h>
26 #endif /* ARCH_MM_MMU */
27 
28 struct shared_futex_key
29 {
30     rt_mem_obj_t mobj;
31     rt_base_t offset;
32 };
33 DEFINE_RT_UTHASH_TYPE(shared_futex_entry, struct shared_futex_key, key);
34 
35 struct rt_futex
36 {
37     union {
38         /* for private futex */
39         struct lwp_avl_struct node;
40         /* for shared futex */
41         struct shared_futex_entry entry;
42     };
43 
44     rt_list_t waiting_thread;
45     struct rt_object *custom_obj;
46     rt_mutex_t mutex;
47 };
48 typedef struct rt_futex *rt_futex_t;
49 
50 rt_err_t futex_global_table_add(struct shared_futex_key *key, rt_futex_t futex);
51 rt_err_t futex_global_table_find(struct shared_futex_key *key, rt_futex_t *futex);
52 rt_err_t futex_global_table_delete(struct shared_futex_key *key);
53 
54 #endif /* __LWP_FUTEX_INTERNAL_H__ */
55