diff options
| author | armink <[email protected]> | 2019-12-17 20:11:46 +0800 |
|---|---|---|
| committer | armink <[email protected]> | 2019-12-17 20:11:46 +0800 |
| commit | 4875ee8a3ab95c4fbf1e09941d3f44d99a9a632b (patch) | |
| tree | 15c596c04a842bac747bbcf05a703b8da76f8eac /components/cplusplus/Thread.cpp | |
| parent | fa46d6ac861f26b472d62abdf1278c445431ce4c (diff) | |
Sync from master (75a3f3dd3a930eab1dc58fa0258a9d1605a0ac11)
Diffstat (limited to 'components/cplusplus/Thread.cpp')
| -rw-r--r-- | components/cplusplus/Thread.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/Thread.cpp index 0f6315d178..b21fbdce1f 100644 --- a/components/cplusplus/Thread.cpp +++ b/components/cplusplus/Thread.cpp @@ -14,7 +14,7 @@ Thread::Thread(rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick, const char *name) -: _entry(RT_NULL), _param(RT_NULL), started(false) + : _entry(RT_NULL), _param(RT_NULL), started(false) { rt_event_init(&_event, name, 0); @@ -32,7 +32,7 @@ Thread::Thread(void (*entry)(void *p), rt_uint8_t priority, rt_uint32_t tick, const char *name) -: _entry(RT_NULL), _param(p), started(false) + : _entry(entry), _param(p), started(false) { rt_event_init(&_event, name, 0); @@ -46,6 +46,7 @@ Thread::Thread(void (*entry)(void *p), Thread::~Thread() { + rt_event_detach(&_event); rt_thread_delete(_thread); } @@ -79,23 +80,23 @@ void Thread::func(Thread *pThis) } else { - pThis->run(); + pThis->run(pThis->_param); } rt_event_send(&pThis->_event, 1); } -void Thread::run() +void Thread::run(void *parameter) { /* please overload this method */ } -void Thread::wait(int32_t millisec) +rt_err_t Thread::wait(int32_t millisec) { - join(millisec); + return join(millisec); } -void Thread::join(int32_t millisec) +rt_err_t Thread::join(int32_t millisec) { if (started) { @@ -106,6 +107,10 @@ void Thread::join(int32_t millisec) else tick = rt_tick_from_millisecond(millisec); - rt_event_recv(&_event, 1, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, tick, RT_NULL); + return rt_event_recv(&_event, 1, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, tick, RT_NULL); + } + else + { + return -RT_ENOSYS; } } |
