From d27d5447789c8cbd2faf86e93e68d65fc5c8fea7 Mon Sep 17 00:00:00 2001 From: Shoji Morita Date: Fri, 26 Jan 2024 19:01:28 +0900 Subject: [PATCH] Modified the structure of member names to reflect the point made on the thread below. https://github.com/ros-infrastructure/rep/pull/385#discussion_r1350512216 Signed-off-by: Shoji Morita --- include/rcutils/thread_attr.h | 8 ++++---- src/thread_attr.c | 28 ++++++++++++++-------------- test/test_thread_attr.cpp | 22 +++++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/rcutils/thread_attr.h b/include/rcutils/thread_attr.h index 7100e82e..278e0a27 100644 --- a/include/rcutils/thread_attr.h +++ b/include/rcutils/thread_attr.h @@ -58,8 +58,8 @@ typedef struct rcutils_thread_attr_s rcutils_thread_scheduling_policy_t scheduling_policy; /// Thread priority. int priority; - /// Thread name - char const * name; + /// Thread attribute tag + char const * tag; } rcutils_thread_attr_t; /// Hold thread attribute rules. @@ -148,7 +148,7 @@ rcutils_thread_attrs_copy( * \param[in] sched_policy thread scheduling policy of adding attribute * \param[in] core_affinity thread core affinity of adding attribute * \param[in] priority thread priority of adding attribute - * \param[in] name thread name of adding attribute + * \param[in] tag thread attribute tag of adding attribute * \return #RCUTILS_RET_OK if the thread attribute was successfully added, or * \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or * \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or @@ -162,7 +162,7 @@ rcutils_thread_attrs_add_attr( rcutils_thread_scheduling_policy_t sched_policy, rcutils_thread_core_affinity_t const * core_affinity, int priority, - char const * name); + char const * tag); /** * \brief Return a zero-initialized rcutils_thread_core_affinity_t object. diff --git a/src/thread_attr.c b/src/thread_attr.c index 95a58ca9..b01794fc 100644 --- a/src/thread_attr.c +++ b/src/thread_attr.c @@ -83,8 +83,8 @@ rcutils_thread_attrs_fini(rcutils_thread_attrs_t * thread_attrs) RCUTILS_CHECK_ALLOCATOR(allocator, return RCUTILS_RET_INVALID_ARGUMENT); for (size_t i = 0; i < thread_attrs->num_attributes; ++i) { rcutils_thread_attr_t * attr = thread_attrs->attributes + i; - if (NULL != attr->name) { - allocator->deallocate((char *)attr->name, allocator->state); + if (NULL != attr->tag) { + allocator->deallocate((char *)attr->tag, allocator->state); } } allocator->deallocate(thread_attrs->attributes, allocator->state); @@ -121,13 +121,13 @@ rcutils_thread_attrs_copy( } for (i = 0; i < thread_attrs->num_attributes; ++i) { - char * dup_name = rcutils_strdup(thread_attrs->attributes[i].name, allocator); - if (NULL == dup_name) { + char * dup_tag = rcutils_strdup(thread_attrs->attributes[i].tag, allocator); + if (NULL == dup_tag) { ret = RCUTILS_RET_BAD_ALLOC; goto error; } new_attrs[i] = thread_attrs->attributes[i]; - new_attrs[i].name = dup_name; + new_attrs[i].tag = dup_tag; } *out_thread_attrs = *thread_attrs; out_thread_attrs->attributes = new_attrs; @@ -137,7 +137,7 @@ rcutils_thread_attrs_copy( error: if (NULL != new_attrs) { for (size_t j = 0; j < i; ++j) { - allocator.deallocate((char *)new_attrs[i].name, allocator.state); + allocator.deallocate((char *)new_attrs[i].tag, allocator.state); } allocator.deallocate(new_attrs, allocator.state); } @@ -173,14 +173,14 @@ rcutils_thread_attrs_add_attr( rcutils_thread_scheduling_policy_t sched_policy, rcutils_thread_core_affinity_t const * core_affinity, int priority, - char const * name) + char const * tag) { RCUTILS_CHECK_ARGUMENT_FOR_NULL(thread_attrs, RCUTILS_RET_INVALID_ARGUMENT); - RCUTILS_CHECK_ARGUMENT_FOR_NULL(name, RCUTILS_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ARGUMENT_FOR_NULL(tag, RCUTILS_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ARGUMENT_FOR_NULL(core_affinity, RCUTILS_RET_INVALID_ARGUMENT); rcutils_ret_t ret; - char const * dup_name = NULL; + char const * dup_tag = NULL; rcutils_thread_core_affinity_t new_affinity = rcutils_get_zero_initialized_thread_core_affinity(); if (thread_attrs->num_attributes == thread_attrs->capacity_attributes) { @@ -197,8 +197,8 @@ rcutils_thread_attrs_add_attr( } } - dup_name = rcutils_strdup(name, thread_attrs->allocator); - if (NULL == dup_name) { + dup_tag = rcutils_strdup(tag, thread_attrs->allocator); + if (NULL == dup_tag) { goto error; } @@ -213,15 +213,15 @@ rcutils_thread_attrs_add_attr( attr->scheduling_policy = sched_policy; attr->core_affinity = new_affinity; attr->priority = priority; - attr->name = dup_name; + attr->tag = dup_tag; ++thread_attrs->num_attributes; return RCUTILS_RET_OK; error: - if (NULL != dup_name) { - thread_attrs->allocator.deallocate((char *)dup_name, thread_attrs->allocator.state); + if (NULL != dup_tag) { + thread_attrs->allocator.deallocate((char *)dup_tag, thread_attrs->allocator.state); } if (0 < new_affinity.core_count) { rcutils_ret_t tmp_ret = rcutils_thread_core_affinity_fini(&new_affinity); diff --git a/test/test_thread_attr.cpp b/test/test_thread_attr.cpp index ba9ab688..67013058 100644 --- a/test/test_thread_attr.cpp +++ b/test/test_thread_attr.cpp @@ -243,11 +243,11 @@ TEST_F(TestThreadAttrs, add_attribute) { ret = rcutils_thread_core_affinity_init(&affinity, alloc); ret = rcutils_thread_core_affinity_set(&affinity, 0xaa); - char thread_name[32]; + char attr_tag[32]; for (size_t i = 0; i < 100; ++i) { - snprintf(thread_name, sizeof(thread_name), "thread name %lu", i); + snprintf(attr_tag, sizeof(attr_tag), "attr tag %lu", i); ret = rcutils_thread_attrs_add_attr( - &attrs, RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, &affinity, 0xbb, thread_name); + &attrs, RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, &affinity, 0xbb, attr_tag); EXPECT_EQ(RCUTILS_RET_OK, ret); ASSERT_NE(nullptr, attrs.attributes); ASSERT_LE(i + 1, attrs.capacity_attributes); @@ -257,14 +257,14 @@ TEST_F(TestThreadAttrs, add_attribute) { for (size_t i = 0; i < 100; ++i) { rcutils_thread_attr_t attr = attrs.attributes[i]; - snprintf(thread_name, sizeof(thread_name), "thread name %lu", i); + snprintf(attr_tag, sizeof(attr_tag), "attr tag %lu", i); EXPECT_EQ(RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, attr.scheduling_policy); EXPECT_NE(affinity.set, attr.core_affinity.set); EXPECT_EQ(affinity.core_count, attr.core_affinity.core_count); EXPECT_EQ(0, memcmp(affinity.set, attr.core_affinity.set, affinity.core_count / CHAR_BIT)); EXPECT_EQ(0xbb, attr.priority); - EXPECT_NE(thread_name, attr.name); - EXPECT_STREQ(thread_name, attr.name); + EXPECT_NE(attr_tag, attr.tag); + EXPECT_STREQ(attr_tag, attr.tag); } ret = rcutils_thread_attrs_fini(&attrs); @@ -277,11 +277,11 @@ TEST_F(TestThreadAttrs, copy) { ret = rcutils_thread_core_affinity_init(&affinity, alloc); ret = rcutils_thread_core_affinity_set(&affinity, 0xaa); - char thread_name[32]; + char attr_tag[32]; for (size_t i = 0; i < 100; ++i) { - snprintf(thread_name, sizeof(thread_name), "thread name %lu", i); + snprintf(attr_tag, sizeof(attr_tag), "attr tag %lu", i); ret = rcutils_thread_attrs_add_attr( - &attrs, RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, &affinity, 0xbb, thread_name); + &attrs, RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, &affinity, 0xbb, attr_tag); ASSERT_EQ(RCUTILS_RET_OK, ret); } @@ -296,8 +296,8 @@ TEST_F(TestThreadAttrs, copy) { EXPECT_EQ(RCUTILS_THREAD_SCHEDULING_POLICY_FIFO, attr.scheduling_policy); EXPECT_EQ(0, memcmp(affinity.set, attr.core_affinity.set, affinity.core_count / CHAR_BIT)); EXPECT_EQ(0xbb, attr.priority); - EXPECT_NE(attrs.attributes[i].name, attr.name); - EXPECT_STREQ(attrs.attributes[i].name, attr.name); + EXPECT_NE(attrs.attributes[i].tag, attr.tag); + EXPECT_STREQ(attrs.attributes[i].tag, attr.tag); } ret = rcutils_thread_attrs_fini(&attrs);