[02/11] eal: rename thread name length definition
Checks
Commit Message
RTE_MAX_THREAD_NAME_LEN is including the NUL character,
so it should be named "size" instead of "length".
A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy.
For API compatibility, the old name is kept.
At the same time, the original definition is moved
from rte_eal.h to rte_thread.h.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
lib/eal/freebsd/eal.c | 2 +-
lib/eal/freebsd/eal_thread.c | 2 +-
lib/eal/include/rte_eal.h | 3 ---
lib/eal/include/rte_thread.h | 9 +++++++--
lib/eal/linux/eal.c | 2 +-
lib/eal/linux/eal_thread.c | 2 +-
lib/eal/windows/eal.c | 2 +-
lib/eal/windows/rte_thread.c | 2 +-
8 files changed, 13 insertions(+), 11 deletions(-)
Comments
On Wed, Sep 06, 2023 at 06:12:19PM +0200, Thomas Monjalon wrote:
> RTE_MAX_THREAD_NAME_LEN is including the NUL character,
> so it should be named "size" instead of "length".
> A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy.
> For API compatibility, the old name is kept.
>
> At the same time, the original definition is moved
> from rte_eal.h to rte_thread.h.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
lgtm
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
@@ -583,7 +583,7 @@ rte_eal_init(int argc, char **argv)
static uint32_t run_once;
uint32_t has_run = 0;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- char thread_name[RTE_MAX_THREAD_NAME_LEN];
+ char thread_name[RTE_THREAD_NAME_SIZE];
const struct rte_config *config = rte_eal_get_configuration();
struct internal_config *internal_conf =
eal_get_internal_configuration();
@@ -34,7 +34,7 @@ int rte_sys_gettid(void)
void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
{
- char truncated[RTE_MAX_THREAD_NAME_LEN];
+ char truncated[RTE_THREAD_NAME_SIZE];
const size_t truncatedsz = sizeof(truncated);
if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
@@ -27,9 +27,6 @@ extern "C" {
#define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
-/* Maximum thread_name length. */
-#define RTE_MAX_THREAD_NAME_LEN 16
-
/**
* The type of process in a linux, multi-process setup
*/
@@ -23,6 +23,11 @@
extern "C" {
#endif
+/** Maximum thread name length (including '\0'). */
+#define RTE_THREAD_NAME_SIZE 16
+/* Old definition, aliased for compatibility. */
+#define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE
+
/**
* Thread id descriptor.
*/
@@ -110,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id,
* Filled with the thread id of the new created thread.
* @param name
* The name of the control thread
- * (max RTE_MAX_THREAD_NAME_LEN characters including '\0').
+ * (max RTE_THREAD_NAME_SIZE characters including '\0').
* @param thread_attr
* Attributes for the new thread.
* @param thread_func
@@ -188,7 +193,7 @@ rte_thread_t rte_thread_self(void);
* The id of the thread to set name.
*
* @param thread_name
- * The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN,
+ * The name to set. Truncated to RTE_THREAD_NAME_SIZE,
* including terminating NUL if necessary.
*/
__rte_experimental
@@ -970,7 +970,7 @@ rte_eal_init(int argc, char **argv)
static uint32_t run_once;
uint32_t has_run = 0;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- char thread_name[RTE_MAX_THREAD_NAME_LEN];
+ char thread_name[RTE_THREAD_NAME_SIZE];
bool phys_addrs;
const struct rte_config *config = rte_eal_get_configuration();
struct internal_config *internal_conf =
@@ -24,7 +24,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
int ret = ENOSYS;
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 12)
- char truncated[RTE_MAX_THREAD_NAME_LEN];
+ char truncated[RTE_THREAD_NAME_SIZE];
const size_t truncatedsz = sizeof(truncated);
if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz)
@@ -283,7 +283,7 @@ rte_eal_init(int argc, char **argv)
enum rte_iova_mode iova_mode;
int ret;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- char thread_name[RTE_MAX_THREAD_NAME_LEN];
+ char thread_name[RTE_THREAD_NAME_SIZE];
eal_log_init(NULL, 0);
@@ -324,7 +324,7 @@ void
rte_thread_set_name(rte_thread_t thread_id, const char *thread_name)
{
int ret = 0;
- wchar_t wname[RTE_MAX_THREAD_NAME_LEN];
+ wchar_t wname[RTE_THREAD_NAME_SIZE];
mbstate_t state = {0};
size_t rv;
HANDLE thread_handle;