diff options
| author | yangjie11 <[email protected]> | 2020-11-18 09:56:35 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-11-18 09:56:35 +0800 |
| commit | d4a682e8d97fa131e5a8d795f8c5451d55cdd5b0 (patch) | |
| tree | 4773b40cb012475c5daf74bfd55707e141477669 /components/cplusplus | |
| parent | 2b98f4720c827ae1850df78299f6b273d568c8c7 (diff) | |
| parent | 2ef3c9d861f55253620996a94831a4be31ca6620 (diff) | |
Merge pull request #3 from RT-Thread/master
sync
Diffstat (limited to 'components/cplusplus')
| -rw-r--r-- | components/cplusplus/Mail.h | 2 | ||||
| -rw-r--r-- | components/cplusplus/Mutex.h | 2 | ||||
| -rw-r--r-- | components/cplusplus/Queue.h | 2 | ||||
| -rw-r--r-- | components/cplusplus/Thread.h | 13 | ||||
| -rw-r--r-- | components/cplusplus/crt.h | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | components/cplusplus/crt_init.c | 29 | ||||
| -rw-r--r-- | components/cplusplus/cxx_Mutex.cpp (renamed from components/cplusplus/Mutex.cpp) | 0 | ||||
| -rw-r--r-- | components/cplusplus/cxx_Semaphore.cpp (renamed from components/cplusplus/Semaphore.cpp) | 0 | ||||
| -rw-r--r-- | components/cplusplus/cxx_Thread.cpp (renamed from components/cplusplus/Thread.cpp) | 21 | ||||
| -rw-r--r-- | components/cplusplus/cxx_crt.cpp (renamed from components/cplusplus/crt.cpp) | 2 |
10 files changed, 37 insertions, 36 deletions
diff --git a/components/cplusplus/Mail.h b/components/cplusplus/Mail.h index e6b11af9e8..a4c98e4007 100644 --- a/components/cplusplus/Mail.h +++ b/components/cplusplus/Mail.h @@ -28,7 +28,7 @@ template<typename T, uint32_t queue_sz> class Mail { public: /** Create and Initialise Mail queue. */ - Mail(const char* name = "") + Mail(const char *name = "") { rt_mb_init(&mID, name, mPool, queue_sz, RT_IPC_FLAG_FIFO); } diff --git a/components/cplusplus/Mutex.h b/components/cplusplus/Mutex.h index 4a54c41ebb..6fee315155 100644 --- a/components/cplusplus/Mutex.h +++ b/components/cplusplus/Mutex.h @@ -21,7 +21,7 @@ namespace rtthread { class Mutex { public: /** Create and Initialize a Mutex object */ - Mutex(const char* name = "mutex"); + Mutex(const char *name = "mutex"); ~Mutex(); /** Wait until a Mutex becomes available. diff --git a/components/cplusplus/Queue.h b/components/cplusplus/Queue.h index fba64bf51b..23a4638798 100644 --- a/components/cplusplus/Queue.h +++ b/components/cplusplus/Queue.h @@ -68,7 +68,7 @@ public: private: struct rt_messagequeue mID; - char mPool[(sizeof(struct rt_messagequeue)+sizeof(T)) * queue_sz]; + char mPool[(sizeof(void *) + RT_ALIGN(sizeof(T), RT_ALIGN_SIZE)) * queue_sz]; }; } diff --git a/components/cplusplus/Thread.h b/components/cplusplus/Thread.h index 9b6cf30884..b578659489 100644 --- a/components/cplusplus/Thread.h +++ b/components/cplusplus/Thread.h @@ -20,7 +20,7 @@ namespace rtthread class Thread { public: - typedef void (*thread_func_t) (void *param); + typedef void (*thread_func_t)(void *param); /** Allocate a new thread without starting execution @param priority initial priority of the thread function. (default: osPriorityNormal). @@ -28,14 +28,14 @@ public: @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). */ Thread(rt_uint32_t stack_size = 2048, - rt_uint8_t priority = (RT_THREAD_PRIORITY_MAX * 2)/3, + rt_uint8_t priority = (RT_THREAD_PRIORITY_MAX * 2) / 3, rt_uint32_t tick = 20, const char *name = "th"); Thread(void (*entry)(void *p), void *p = RT_NULL, rt_uint32_t stack_size = 2048, - rt_uint8_t priority = (RT_THREAD_PRIORITY_MAX * 2)/3, + rt_uint8_t priority = (RT_THREAD_PRIORITY_MAX * 2) / 3, rt_uint32_t tick = 20, const char *name = "th"); @@ -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/components/cplusplus/crt.h b/components/cplusplus/crt.h index 6228dab2a9..84e5a4b820 100644 --- a/components/cplusplus/crt.h +++ b/components/cplusplus/crt.h @@ -18,7 +18,7 @@ void *operator new(size_t size); void *operator new[](size_t size); void operator delete(void * ptr); -void operator delete[] (void *ptr); +void operator delete[](void *ptr); extern "C" void __cxa_pure_virtual(void); extern "C" int cplusplus_system_init(void); diff --git a/components/cplusplus/crt_init.c b/components/cplusplus/crt_init.c index e67939feeb..fe12932457 100755..100644 --- a/components/cplusplus/crt_init.c +++ b/components/cplusplus/crt_init.c @@ -13,10 +13,10 @@ #include <rtthread.h> -#ifdef __CC_ARM +#if defined(__CC_ARM) || defined(__CLANG_ARM) extern void $Super$$__cpp_initialize__aeabi_(void); /* we need to change the cpp_initialize order */ -void $Sub$$__cpp_initialize__aeabi_(void) +RT_WEAK void $Sub$$__cpp_initialize__aeabi_(void) { /* empty */ } @@ -34,19 +34,9 @@ RT_WEAK void *__dso_handle = 0; #endif -RT_WEAK -int cplusplus_system_init(void) +RT_WEAK int cplusplus_system_init(void) { -#if defined(__GNUC__) && !defined(__CC_ARM) - typedef void (*pfunc) (); - extern pfunc __ctors_start__[]; - extern pfunc __ctors_end__[]; - pfunc *p; - - for (p = __ctors_start__; p < __ctors_end__; p++) - (*p)(); - -#elif defined(__CC_ARM) +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* If there is no SHT$$INIT_ARRAY, calling * $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12 * the problem still exists. So we have to initialize the C++ runtime by ourself. @@ -60,12 +50,19 @@ int cplusplus_system_init(void) for (; base != lim; base++) { - PROC *proc = (PROC*)((const char*)base + *base); + PROC *proc = (PROC *)((const char *)base + *base); (*proc)(); } +#elif defined(__GNUC__) + typedef void(*pfunc)(); + extern pfunc __ctors_start__[]; + extern pfunc __ctors_end__[]; + pfunc *p; + + for (p = __ctors_start__; p < __ctors_end__; p++) + (*p)(); #endif return 0; } INIT_COMPONENT_EXPORT(cplusplus_system_init); - diff --git a/components/cplusplus/Mutex.cpp b/components/cplusplus/cxx_Mutex.cpp index 229e842446..229e842446 100644 --- a/components/cplusplus/Mutex.cpp +++ b/components/cplusplus/cxx_Mutex.cpp diff --git a/components/cplusplus/Semaphore.cpp b/components/cplusplus/cxx_Semaphore.cpp index c977a27c1a..c977a27c1a 100644 --- a/components/cplusplus/Semaphore.cpp +++ b/components/cplusplus/cxx_Semaphore.cpp diff --git a/components/cplusplus/Thread.cpp b/components/cplusplus/cxx_Thread.cpp index 0f6315d178..b21fbdce1f 100644 --- a/components/cplusplus/Thread.cpp +++ b/components/cplusplus/cxx_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; } } diff --git a/components/cplusplus/crt.cpp b/components/cplusplus/cxx_crt.cpp index cac1e5fa57..d4cb84f77c 100644 --- a/components/cplusplus/crt.cpp +++ b/components/cplusplus/cxx_crt.cpp @@ -26,7 +26,7 @@ void operator delete(void *ptr) rt_free(ptr); } -void operator delete[] (void *ptr) +void operator delete[](void *ptr) { return rt_free(ptr); } |
