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