f1ae2d32cc621d17c0bc91173d3d84d16315ba67
[dpdk.git] / 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
7 #ifndef _RTE_THREAD_H_
8 #define _RTE_THREAD_H_
9
10 /**
11  * @file
12  *
13  * Threading functions
14  *
15  * Simple threads functionality supplied by EAL.
16  */
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /**
23  * TLS key type, an opaque pointer.
24  */
25 typedef struct eal_tls_key *rte_tls_key;
26
27 /**
28  * Set core affinity of the current thread.
29  * Support both EAL and non-EAL thread and update TLS.
30  *
31  * @param cpusetp
32  *   Pointer to CPU affinity to set.
33  * @return
34  *   On success, return 0; otherwise return -1;
35  */
36 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
37
38 /**
39  * Get core affinity of the current thread.
40  *
41  * @param cpusetp
42  *   Pointer to CPU affinity of current thread.
43  *   It presumes input is not NULL, otherwise it causes panic.
44  *
45  */
46 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
47
48 /**
49  * Create a TLS data key visible to all threads in the process.
50  * the created key is later used to get/set a value.
51  * and optional destructor can be set to be called when a thread exits.
52  *
53  * @param key
54  *   Pointer to store the allocated key.
55  * @param destructor
56  *   The function to be called when the thread exits.
57  *   Ignored on Windows OS.
58  *
59  * @return
60  *   On success, zero.
61  *   On failure, a negative number.
62  */
63
64 __rte_experimental
65 int rte_thread_tls_key_create(rte_tls_key *key, void (*destructor)(void *));
66
67 /**
68  * Delete a TLS data key visible to all threads in the process.
69  *
70  * @param key
71  *   The key allocated by rte_thread_tls_key_create().
72  *
73  * @return
74  *   On success, zero.
75  *   On failure, a negative number.
76  */
77 __rte_experimental
78 int rte_thread_tls_key_delete(rte_tls_key key);
79
80 /**
81  * Set value bound to the TLS key on behalf of the calling thread.
82  *
83  * @param key
84  *   The key allocated by rte_thread_tls_key_create().
85  * @param value
86  *   The value bound to the rte_tls_key key for the calling thread.
87  *
88  * @return
89  *   On success, zero.
90  *   On failure, a negative number.
91  */
92 __rte_experimental
93 int rte_thread_tls_value_set(rte_tls_key key, const void *value);
94
95 /**
96  * Get value bound to the TLS key on behalf of the calling thread.
97  *
98  * @param key
99  *   The key allocated by rte_thread_tls_key_create().
100  *
101  * @return
102  *   On success, value data pointer (can also be NULL).
103  *   On failure, NULL and an error number is set in rte_errno.
104  */
105 __rte_experimental
106 void *rte_thread_tls_value_get(rte_tls_key key);
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* _RTE_THREAD_H_ */