eal/linux: fix illegal memory access in uevent handler
[dpdk.git] / lib / eal / include / rte_thread.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2021 Mellanox Technologies, Ltd
3  */
4
5 #include <rte_os.h>
6 #include <rte_compat.h>
7
8 #ifndef _RTE_THREAD_H_
9 #define _RTE_THREAD_H_
10
11 /**
12  * @file
13  *
14  * Threading functions
15  *
16  * Simple threads functionality supplied by EAL.
17  */
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /**
24  * TLS key type, an opaque pointer.
25  */
26 typedef struct eal_tls_key *rte_thread_key;
27
28 #ifdef RTE_HAS_CPUSET
29
30 /**
31  * Set core affinity of the current thread.
32  * Support both EAL and non-EAL thread and update TLS.
33  *
34  * @param cpusetp
35  *   Pointer to CPU affinity to set.
36  * @return
37  *   On success, return 0; otherwise return -1;
38  */
39 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
40
41 /**
42  * Get core affinity of the current thread.
43  *
44  * @param cpusetp
45  *   Pointer to CPU affinity of current thread.
46  *   It presumes input is not NULL, otherwise it causes panic.
47  *
48  */
49 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
50
51 #endif /* RTE_HAS_CPUSET */
52
53 /**
54  * Create a TLS data key visible to all threads in the process.
55  * the created key is later used to get/set a value.
56  * and optional destructor can be set to be called when a thread exits.
57  *
58  * @param key
59  *   Pointer to store the allocated key.
60  * @param destructor
61  *   The function to be called when the thread exits.
62  *   Ignored on Windows OS.
63  *
64  * @return
65  *   On success, zero.
66  *   On failure, a negative number and an error number is set in rte_errno.
67  *   rte_errno can be: ENOMEM  - Memory allocation error.
68  *                     ENOEXEC - Specific OS error.
69  */
70
71 __rte_experimental
72 int rte_thread_key_create(rte_thread_key *key,
73                         void (*destructor)(void *));
74
75 /**
76  * Delete a TLS data key visible to all threads in the process.
77  *
78  * @param key
79  *   The key allocated by rte_thread_key_create().
80  *
81  * @return
82  *   On success, zero.
83  *   On failure, a negative number and an error number is set in rte_errno.
84  *   rte_errno can be: EINVAL  - Invalid parameter passed.
85  *                     ENOEXEC - Specific OS error.
86  */
87 __rte_experimental
88 int rte_thread_key_delete(rte_thread_key key);
89
90 /**
91  * Set value bound to the TLS key on behalf of the calling thread.
92  *
93  * @param key
94  *   The key allocated by rte_thread_key_create().
95  * @param value
96  *   The value bound to the rte_thread_key key for the calling thread.
97  *
98  * @return
99  *   On success, zero.
100  *   On failure, a negative number and an error number is set in rte_errno.
101  *   rte_errno can be: EINVAL  - Invalid parameter passed.
102  *                     ENOEXEC - Specific OS error.
103  */
104 __rte_experimental
105 int rte_thread_value_set(rte_thread_key key, const void *value);
106
107 /**
108  * Get value bound to the TLS key on behalf of the calling thread.
109  *
110  * @param key
111  *   The key allocated by rte_thread_key_create().
112  *
113  * @return
114  *   On success, value data pointer (can also be NULL).
115  *   On failure, NULL and an error number is set in rte_errno.
116  *   rte_errno can be: EINVAL  - Invalid parameter passed.
117  *                     ENOEXEC - Specific OS error.
118  */
119 __rte_experimental
120 void *rte_thread_value_get(rte_thread_key key);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif /* _RTE_THREAD_H_ */