1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 Mellanox Technologies, Ltd
3 * Copyright (C) 2022 Microsoft Corporation
9 #include <rte_compat.h>
11 #ifndef _RTE_THREAD_H_
12 #define _RTE_THREAD_H_
19 * Simple threads functionality supplied by EAL.
27 * Thread id descriptor.
30 uintptr_t opaque_id; /**< thread identifier */
34 * TLS key type, an opaque pointer.
36 typedef struct eal_tls_key *rte_thread_key;
40 * @b EXPERIMENTAL: this API may change without prior notice.
42 * Get the id of the calling thread.
45 * Return the thread id of the calling thread.
48 rte_thread_t rte_thread_self(void);
53 * Set core affinity of the current thread.
54 * Support both EAL and non-EAL thread and update TLS.
57 * Pointer to CPU affinity to set.
59 * On success, return 0; otherwise return -1;
61 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
64 * Get core affinity of the current thread.
67 * Pointer to CPU affinity of current thread.
68 * It presumes input is not NULL, otherwise it causes panic.
71 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
73 #endif /* RTE_HAS_CPUSET */
76 * Create a TLS data key visible to all threads in the process.
77 * the created key is later used to get/set a value.
78 * and optional destructor can be set to be called when a thread exits.
81 * Pointer to store the allocated key.
83 * The function to be called when the thread exits.
84 * Ignored on Windows OS.
88 * On failure, a negative number and an error number is set in rte_errno.
89 * rte_errno can be: ENOMEM - Memory allocation error.
90 * ENOEXEC - Specific OS error.
94 int rte_thread_key_create(rte_thread_key *key,
95 void (*destructor)(void *));
98 * Delete a TLS data key visible to all threads in the process.
101 * The key allocated by rte_thread_key_create().
105 * On failure, a negative number and an error number is set in rte_errno.
106 * rte_errno can be: EINVAL - Invalid parameter passed.
107 * ENOEXEC - Specific OS error.
110 int rte_thread_key_delete(rte_thread_key key);
113 * Set value bound to the TLS key on behalf of the calling thread.
116 * The key allocated by rte_thread_key_create().
118 * The value bound to the rte_thread_key key for the calling thread.
122 * On failure, a negative number and an error number is set in rte_errno.
123 * rte_errno can be: EINVAL - Invalid parameter passed.
124 * ENOEXEC - Specific OS error.
127 int rte_thread_value_set(rte_thread_key key, const void *value);
130 * Get value bound to the TLS key on behalf of the calling thread.
133 * The key allocated by rte_thread_key_create().
136 * On success, value data pointer (can also be NULL).
137 * On failure, NULL and an error number is set in rte_errno.
138 * rte_errno can be: EINVAL - Invalid parameter passed.
139 * ENOEXEC - Specific OS error.
142 void *rte_thread_value_get(rte_thread_key key);
148 #endif /* _RTE_THREAD_H_ */