From a559179e6fe68a21687e9203ec583bd38b7573e7 Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Mon, 24 Jun 2019 15:59:26 +0800 Subject: fix cpp thread class error --- components/cplusplus/Thread.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'components/cplusplus/Thread.cpp') diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/Thread.cpp index 0f6315d178..103649b639 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,12 +32,12 @@ 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); _thread = rt_thread_create(name, - (thread_func_t)func, + (thread_func_t)entry, this, stack_size, priority, @@ -46,6 +46,7 @@ Thread::Thread(void (*entry)(void *p), Thread::~Thread() { + rt_event_detach(&_event); rt_thread_delete(_thread); } -- cgit v1.3.1 From 9efd293bb99aa22ffe78b22f31ed1844e0ff3114 Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Mon, 24 Jun 2019 16:05:32 +0800 Subject: fix format display --- components/cplusplus/Thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/cplusplus/Thread.cpp') diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/Thread.cpp index 103649b639..26043a3581 100644 --- a/components/cplusplus/Thread.cpp +++ b/components/cplusplus/Thread.cpp @@ -46,7 +46,7 @@ Thread::Thread(void (*entry)(void *p), Thread::~Thread() { - rt_event_detach(&_event); + rt_event_detach(&_event); rt_thread_delete(_thread); } -- cgit v1.3.1 From 759848122e47775cfd8a0e9e3e7a2fa7189754c4 Mon Sep 17 00:00:00 2001 From: mulan <43946994+tyustli@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:14:58 +0800 Subject: Update Thread.cpp --- components/cplusplus/Thread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/cplusplus/Thread.cpp') diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/Thread.cpp index 26043a3581..9b2a2ad5e0 100644 --- a/components/cplusplus/Thread.cpp +++ b/components/cplusplus/Thread.cpp @@ -37,7 +37,7 @@ Thread::Thread(void (*entry)(void *p), rt_event_init(&_event, name, 0); _thread = rt_thread_create(name, - (thread_func_t)entry, + (thread_func_t)func, this, stack_size, priority, -- cgit v1.3.1 From 85a9f5add9fd54b3917cfca2a8555c6525df0538 Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Sat, 27 Jul 2019 17:33:36 +0800 Subject: fix bug in Thread.cpp/Thread.h/components.c files --- components/cplusplus/Thread.cpp | 16 ++++++++++------ components/cplusplus/Thread.h | 7 +++---- src/components.c | 3 +-- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'components/cplusplus/Thread.cpp') diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/Thread.cpp index 9b2a2ad5e0..b21fbdce1f 100644 --- a/components/cplusplus/Thread.cpp +++ b/components/cplusplus/Thread.cpp @@ -80,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) { @@ -107,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; } } diff --git a/components/cplusplus/Thread.h b/components/cplusplus/Thread.h index 71ee50e1f9..b578659489 100644 --- a/components/cplusplus/Thread.h +++ b/components/cplusplus/Thread.h @@ -45,16 +45,15 @@ public: static void sleep(int32_t millisec); - void wait(int32_t millisec); - void join(int32_t millisec = -1); + rt_err_t wait(int32_t millisec); + rt_err_t join(int32_t millisec = -1); protected: - virtual void run(); + virtual void run(void *parameter); private: static void func(Thread *pThis); -private: rt_thread_t _thread; thread_func_t _entry; diff --git a/src/components.c b/src/components.c index 3b9f131eaf..b9fc4c178c 100644 --- a/src/components.c +++ b/src/components.c @@ -153,7 +153,6 @@ int __low_level_init(void) return 0; } #elif defined(__GNUC__) -extern int main(void); /* Add -eentry to arm-none-eabi-gcc argument */ int entry(void) { @@ -204,7 +203,7 @@ void rt_application_init(void) result = rt_thread_init(tid, "main", main_thread_entry, RT_NULL, main_stack, sizeof(main_stack), RT_MAIN_THREAD_PRIORITY, 20); RT_ASSERT(result == RT_EOK); - + /* if not define RT_USING_HEAP, using to eliminate the warning */ (void)result; #endif -- cgit v1.3.1