summaryrefslogtreecommitdiff
path: root/components/libc/cplusplus/os/cxx_Thread.cpp
diff options
context:
space:
mode:
authorlct1001 <[email protected]>2025-12-10 09:34:21 +0800
committerR b b666 <[email protected]>2025-12-12 14:00:36 +0800
commit170069b292da4af9129ad630608780942cc0e4c3 (patch)
treec3ef2eec72c74a751585518b65e7016a213ed7bc /components/libc/cplusplus/os/cxx_Thread.cpp
parentb75828f07945e79d8fa900b92847b8ee7aadb670 (diff)
components:libc:cplusplus:os/utest:Some comments have been initially added.
Some comments have been initially added as a bignner task. components/libc/cplusplus/os/cxx_Semaphore.cpp components/libc/cplusplus/os/cxx_Thread.cpp components/libc/cplusplus/utest/tc_atomic.cpp components/libc/cplusplus/utest/tc_smartptr.cpp components/libc/cplusplus/utest/tc_thread.cpp Signed-off-by:Liu Chengtao<[email protected]>
Diffstat (limited to 'components/libc/cplusplus/os/cxx_Thread.cpp')
-rw-r--r--components/libc/cplusplus/os/cxx_Thread.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/components/libc/cplusplus/os/cxx_Thread.cpp b/components/libc/cplusplus/os/cxx_Thread.cpp
index f3484bb1f4..dc444c255b 100644
--- a/components/libc/cplusplus/os/cxx_Thread.cpp
+++ b/components/libc/cplusplus/os/cxx_Thread.cpp
@@ -11,6 +11,13 @@
using namespace rtthread;
+/**
+ * @brief Thread class constructor with parameters for stack size, priority, tick, and name.
+ * @param stack_size Stack size in bytes
+ * @param priority Thread priority
+ * @param tick Time slice in ticks
+ * @param name Thread name
+ */
Thread::Thread(rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick,
@@ -27,6 +34,15 @@ Thread::Thread(rt_uint32_t stack_size,
tick);
}
+/**
+ * @brief Thread class constructor with entry function and parameters.
+ * @param entry The entry function pointer for the thread.
+ * @param p The parameter to pass to the entry function.
+ * @param stack_size The size of the thread stack in bytes.
+ * @param priority The priority of the thread.
+ * @param tick The time slice (tick) for the thread.
+ * @param name The name of the thread.
+ */
Thread::Thread(void (*entry)(void *p),
void *p,
rt_uint32_t stack_size,
@@ -45,12 +61,19 @@ Thread::Thread(void (*entry)(void *p),
tick);
}
+/**
+ * @brief Detach the event and delete the thread when the object is destroyed.
+ */
Thread::~Thread()
{
rt_event_detach(&_event);
rt_thread_delete(_thread);
}
+/**
+ * @brief Start the thread execution.
+ * @return true if the thread was successfully started.
+ */
bool Thread::start()
{
if (rt_thread_startup(_thread) == RT_EOK)
@@ -61,6 +84,10 @@ bool Thread::start()
return started;
}
+/**
+ * @brief Make the thread sleep for a specified duration.
+ * @param millisec Duration in milliseconds.
+ */
void Thread::sleep(int32_t millisec)
{
rt_int32_t tick;
@@ -73,6 +100,9 @@ void Thread::sleep(int32_t millisec)
rt_thread_delay(tick);
}
+/**
+ * @brief Function to run the thread's entry function.
+ */
void Thread::func(Thread *pThis)
{
if (pThis->_entry != RT_NULL)
@@ -87,22 +117,34 @@ void Thread::func(Thread *pThis)
rt_event_send(&pThis->_event, 1);
}
+/**
+ * @brief Default run function that can be overridden by subclasses.
+ */
void Thread::run(void *parameter)
{
/* please overload this method */
}
+/**
+ * @brief Wait for the thread to complete with a timeout.
+ * @param millisec Timeout in milliseconds.
+ * @return RT_EOK if the thread completed within the timeout, error code otherwise.
+ */
rt_err_t Thread::wait(int32_t millisec)
{
return join(millisec);
}
+/**
+ * @brief Join the thread with a timeout.
+ * @param millisec Timeout in milliseconds.
+ * @return RT_EOK if the thread completed within the timeout, error code otherwise.
+ */
rt_err_t Thread::join(int32_t millisec)
{
if (started)
{
rt_int32_t tick;
-
if (millisec < 0)
tick = -1;
else
@@ -114,4 +156,4 @@ rt_err_t Thread::join(int32_t millisec)
{
return -RT_ENOSYS;
}
-}
+} \ No newline at end of file