Skip to content

Commit eb1d86a

Browse files
committed
components:libc:cplusplus:Adjust the annotation to fit the rtthread specification
Modify the os:cxx_Semaphore.cpp and cxx_Thread.cpp to comply with the rtthread specification. Change the comment symbol in utest:tc_thread.cpp from '//' to '/**/' to comply with rtthread specifications.For utest:tc_atomic.cpp and tc_smartptr.cpp,select the original respository files without modification. signed-off-by: Liu Chengtao<2739960959@qq.com>
1 parent e5875df commit eb1d86a

File tree

5 files changed

+55
-54
lines changed

5 files changed

+55
-54
lines changed

components/libc/cplusplus/os/cxx_Semaphore.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ using namespace rtthread;
1313

1414
/**
1515
* @brief Semaphore class implementation.
16+
* @param name Semaphore name
17+
* @param count Initial semaphore count
1618
*/
1719
Semaphore::Semaphore(const char *name, int32_t count)
1820
{
19-
// Initialize the semaphore with a specified count and FIFO order.
2021
rt_sem_init(&mID, name, count, RT_IPC_FLAG_FIFO);
2122
}
2223

2324
/**
2425
* @brief Wait on the semaphore.
25-
* @param millisec Timeout in milliseconds.
26-
* @return Boolean indicating if the semaphore was successfully taken.
26+
* @param millisec Timeout in milliseconds (-1 for infinite wait).
27+
* @return true if the semaphore was successfully taken, false on timeout.
2728
*/
2829
bool Semaphore::wait(int32_t millisec)
2930
{
3031
rt_int32_t tick;
3132

32-
// Convert milliseconds to system ticks.
3333
if (millisec < 0)
3434
tick = -1;
3535
else
3636
tick = rt_tick_from_millisecond(millisec);
3737

38-
// Attempt to take the semaphore.
3938
return rt_sem_take(&mID, tick) == RT_EOK;
4039
}
4140

@@ -48,7 +47,7 @@ void Semaphore::release(void)
4847
}
4948

5049
/**
51-
* Detach the semaphore when the object is destroyed.
50+
* @brief Detach the semaphore when the object is destroyed.
5251
*/
5352
Semaphore::~Semaphore()
5453
{

components/libc/cplusplus/os/cxx_Thread.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ using namespace rtthread;
1313

1414
/**
1515
* @brief Thread class constructor with parameters for stack size, priority, tick, and name.
16+
* @param stack_size Stack size in bytes
17+
* @param priority Thread priority
18+
* @param tick Time slice in ticks
19+
* @param name Thread name
1620
*/
1721
Thread::Thread(rt_uint32_t stack_size,
1822
rt_uint8_t priority,
@@ -32,6 +36,12 @@ Thread::Thread(rt_uint32_t stack_size,
3236

3337
/**
3438
* @brief Thread class constructor with entry function and parameters.
39+
* @param entry The entry function pointer for the thread.
40+
* @param p The parameter to pass to the entry function.
41+
* @param stack_size The size of the thread stack in bytes.
42+
* @param priority The priority of the thread.
43+
* @param tick The time slice (tick) for the thread.
44+
* @param name The name of the thread.
3545
*/
3646
Thread::Thread(void (*entry)(void *p),
3747
void *p,
@@ -62,7 +72,7 @@ Thread::~Thread()
6272

6373
/**
6474
* @brief Start the thread execution.
65-
* @return Boolean indicating if the thread was successfully started.
75+
* @return true if the thread was successfully started.
6676
*/
6777
bool Thread::start()
6878
{
@@ -75,29 +85,26 @@ bool Thread::start()
7585
}
7686

7787
/**
78-
* Make the thread sleep for a specified duration.
88+
* @brief Make the thread sleep for a specified duration.
7989
* @param millisec Duration in milliseconds.
8090
*/
8191
void Thread::sleep(int32_t millisec)
8292
{
8393
rt_int32_t tick;
8494

85-
// Convert milliseconds to system ticks.
8695
if (millisec < 0)
8796
tick = 1;
8897
else
8998
tick = rt_tick_from_millisecond(millisec);
9099

91-
// Delay the thread for a specified number of ticks.
92100
rt_thread_delay(tick);
93101
}
94102

95103
/**
96-
* Static function to run the thread's entry function.
104+
* @brief function to run the thread's entry function.
97105
*/
98106
void Thread::func(Thread *pThis)
99107
{
100-
// If an entry function is provided, execute it.
101108
if (pThis->_entry != RT_NULL)
102109
{
103110
pThis->_entry(pThis->_param);
@@ -107,30 +114,29 @@ void Thread::func(Thread *pThis)
107114
pThis->run(pThis->_param);
108115
}
109116

110-
// Send an event to signal thread completion.
111117
rt_event_send(&pThis->_event, 1);
112118
}
113119

114120
/**
115-
* Default run function that can be overridden by subclasses.
121+
* @brief Default run function that can be overridden by subclasses.
116122
*/
117123
void Thread::run(void *parameter)
118124
{
119125
/* please overload this method */
120126
}
121127

122128
/**
123-
* Wait for the thread to complete with a timeout.
129+
* @brief Wait for the thread to complete with a timeout.
124130
* @param millisec Timeout in milliseconds.
125-
* @return Status code indicating the execution status.
131+
* @return RT_EOK if the thread completed within the timeout, error code otherwise.
126132
*/
127133
rt_err_t Thread::wait(int32_t millisec)
128134
{
129135
return join(millisec);
130136
}
131137

132138
/**
133-
* Join the thread with a timeout.
139+
* @brief the thread with a timeout.
134140
* @param millisec Timeout in milliseconds.
135141
* @return Status code indicating the execution status.
136142
*/
@@ -139,14 +145,11 @@ rt_err_t Thread::join(int32_t millisec)
139145
if (started)
140146
{
141147
rt_int32_t tick;
142-
143-
// Convert milliseconds to system ticks.
144148
if (millisec < 0)
145149
tick = -1;
146150
else
147151
tick = rt_tick_from_millisecond(millisec);
148152

149-
// Wait for the thread's completion event.
150153
return rt_event_recv(&_event, 1, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, tick, RT_NULL);
151154
}
152155
else

components/libc/cplusplus/utest/tc_atomic.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
static void test_atomic_load_store_int32(void)
2222
{
23-
constexpr int kRound = 10000000;
23+
constexpr int kRound = 10000000;
2424
std::atomic<int32_t> thread_count(0);
2525
std::atomic<int32_t> count(100);
2626
uassert_int_equal(count.load(), 100);
@@ -56,7 +56,7 @@ static void test_atomic_load_store_int32(void)
5656
*/
5757
static void test_atomic_load_store_int64(void)
5858
{
59-
constexpr int kRound = 10000000;
59+
constexpr int kRound = 10000000;
6060
std::atomic<int64_t> thread_count(0);
6161
std::atomic<int64_t> count(100);
6262
uassert_int_equal(count.load(), 100);
@@ -121,9 +121,9 @@ static void test_atomic_basic_int32(void)
121121
val.exchange(1);
122122
uassert_int_equal(val.load(), 1);
123123

124-
int32_t x = 2;
125-
int32_t y = 3;
126-
bool exchanged = val.compare_exchange_strong(x, y);
124+
int32_t x = 2;
125+
int32_t y = 3;
126+
bool exchanged = val.compare_exchange_strong(x, y);
127127
uassert_false(exchanged);
128128
uassert_int_equal(val.load(), 1);
129129
uassert_int_equal(x, 1);
@@ -168,9 +168,9 @@ static void test_atomic_basic_int64(void)
168168
val.exchange(1);
169169
uassert_int_equal(val.load(), 1);
170170

171-
int64_t x = 2;
172-
int64_t y = 3;
173-
bool exchanged = val.compare_exchange_strong(x, y);
171+
int64_t x = 2;
172+
int64_t y = 3;
173+
bool exchanged = val.compare_exchange_strong(x, y);
174174
uassert_false(exchanged);
175175
uassert_int_equal(val.load(), 1);
176176
uassert_int_equal(x, 1);
@@ -191,7 +191,7 @@ static void test_atomic_bool(void)
191191
flag.exchange(false);
192192
uassert_false(flag.load());
193193
bool expected = false;
194-
bool desired = true;
194+
bool desired = true;
195195
uassert_true(flag.compare_exchange_strong(expected, desired));
196196
uassert_true(flag.load());
197197
}
@@ -201,7 +201,7 @@ static void test_atomic_bool(void)
201201
*/
202202
static void test_atomic_pointer(void)
203203
{
204-
int a = 1, b = 2;
204+
int a = 1, b = 2;
205205
std::atomic<int *> ptr(&a);
206206
ptr.store(&b);
207207
uassert_int_equal(*ptr.load(), 2);
@@ -230,8 +230,8 @@ static void test_memory_order(void)
230230
static void test_compare_exchange_weak(void)
231231
{
232232
std::atomic<int> val(1);
233-
int expected = 1;
234-
int desired = 2;
233+
int expected = 1;
234+
int desired = 2;
235235
while (!val.compare_exchange_weak(expected, desired))
236236
{
237237
expected = 1; // reset
@@ -269,4 +269,4 @@ static void testcase(void)
269269
/* Test compare_exchange_weak operation */
270270
UTEST_UNIT_RUN(test_compare_exchange_weak);
271271
}
272-
UTEST_TC_EXPORT(testcase, "components.libc.cpp.atomic_tc", utest_tc_init, utest_tc_cleanup, 10);
272+
UTEST_TC_EXPORT(testcase, "components.libc.cpp.atomic_tc", utest_tc_init, utest_tc_cleanup, 10);

components/libc/cplusplus/utest/tc_smartptr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ static rt_err_t utest_tc_init(void)
4242
{
4343
return RT_EOK;
4444
}
45+
4546
/**
4647
* @brief Test case cleanup function.
4748
*/
48-
4949
static rt_err_t utest_tc_cleanup(void)
5050
{
5151
return RT_EOK;
@@ -58,4 +58,4 @@ static void testcase(void)
5858
/* Test shared_ptr basic operations */
5959
UTEST_UNIT_RUN(test_shared_ptr);
6060
}
61-
UTEST_TC_EXPORT(testcase, "components.libc.cpp.smartptr_tc", utest_tc_init, utest_tc_cleanup, 10);
61+
UTEST_TC_EXPORT(testcase, "components.libc.cpp.smartptr_tc", utest_tc_init, utest_tc_cleanup, 10);

components/libc/cplusplus/utest/tc_thread.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,37 @@
1818
*/
1919
static void test_thread(void)
2020
{
21-
int count = 0; // Initialize a counter to zero.
21+
int count = 0;
2222

23-
// Lambda function to increment the count.
24-
auto func = [&]() mutable
25-
{
23+
/* Lambda function to increment the count.*/
24+
auto func = [&]() mutable {
2625
for (int i = 0; i < 100; ++i)
2726
{
28-
++count; // Increment the count 100 times.
27+
++count;
2928
}
3029
};
3130

32-
// Create and run a thread executing the lambda function.
31+
/* Create and run a thread executing the lambda function. */
3332
std::thread t1(func);
34-
t1.join(); // Wait for the thread to finish execution.
33+
/* Wait for the thread to finish execution.*/
34+
t1.join();
3535

36-
// Verify if the count is as expected after the first thread execution.
36+
/* Verify if the count is as expected after the first thread execution.*/
3737
if (count != 100)
3838
{
39-
uassert_false(1); // Assert failure if count is not 100.
39+
uassert_false(1);
4040
}
4141

42-
// Create and run another thread executing the same lambda function.
42+
/* Create and run another thread executing the same lambda function. */
4343
std::thread t2(func);
44-
t2.join(); // Wait for the second thread to finish execution.
44+
t2.join();
4545

46-
// Verify if the count is as expected after the second thread execution.
4746
if (count != 200)
4847
{
49-
uassert_false(1); // Assert failure if count is not 200.
48+
uassert_false(1);
5049
}
5150

52-
// If both assertions passed, the test is successful.
51+
/* If both assertions passed, the test is successful.*/
5352
uassert_true(1);
5453
}
5554

@@ -60,23 +59,23 @@ static void test_thread(void)
6059

6160
static rt_err_t utest_tc_init(void)
6261
{
63-
return RT_EOK;
62+
return RT_EOK;
6463
}
6564
/**
6665
* @brief Test case cleanup function.
6766
*/
6867
static rt_err_t utest_tc_cleanup(void)
6968
{
70-
return RT_EOK;
69+
return RT_EOK;
7170
}
7271

7372
/**
7473
* @brief Main test case function that runs the test.
75-
*/
74+
*/
7675
static void testcase(void)
7776
{
7877
UTEST_UNIT_RUN(test_thread);
7978
}
8079

81-
// Export the test case with initialization and cleanup functions and a timeout of 10 ticks.
82-
UTEST_TC_EXPORT(testcase, "components.libc.cpp.thread_tc", utest_tc_init, utest_tc_cleanup, 10);
80+
/* Export the test case with initialization and cleanup functions and a timeout of 10 ticks. */
81+
UTEST_TC_EXPORT(testcase, "components.libc.cpp.thread_tc", utest_tc_init, utest_tc_cleanup, 10);

0 commit comments

Comments
 (0)