summaryrefslogtreecommitdiff
path: root/components/cplusplus
diff options
context:
space:
mode:
authorxph <[email protected]>2020-04-09 16:35:28 +0800
committerGitHub <[email protected]>2020-04-09 16:35:28 +0800
commitca7f01d79b3e0a997c771cec298e4ebd65b75809 (patch)
tree3d2c48aae7203b14038ba7b98b500b5343ed7f2a /components/cplusplus
parentf763f8e7284b0492c5a65ad0abf94ee1963d7dcc (diff)
parentbaa3145bfe61b3330b6a160523cc5470fa5db3a7 (diff)
Merge pull request #1 from RT-Thread/master
sync rtt
Diffstat (limited to 'components/cplusplus')
-rw-r--r--components/cplusplus/Mail.h2
-rw-r--r--components/cplusplus/Mutex.h2
-rw-r--r--components/cplusplus/Queue.h2
-rw-r--r--components/cplusplus/Thread.cpp21
-rw-r--r--components/cplusplus/Thread.h13
-rw-r--r--components/cplusplus/crt.cpp2
-rw-r--r--components/cplusplus/crt.h2
-rwxr-xr-xcomponents/cplusplus/crt_init.c29
8 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.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;
}
}
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.cpp b/components/cplusplus/crt.cpp
index cac1e5fa57..d4cb84f77c 100644
--- a/components/cplusplus/crt.cpp
+++ b/components/cplusplus/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);
}
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
--- 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);
-