Dan Matthews / Mbed 2 deprecated GPS_Incremental

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thread.cpp Source File

Thread.cpp

00001 #include "Thread.h"
00002 
00003 #include <stdlib.h>
00004 
00005 #include "error.h"
00006 
00007 namespace rtos {
00008 
00009 Thread::Thread (void (*task)(void const *argument), void *argument,
00010         osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
00011 #ifdef CMSIS_OS_RTX
00012     _thread_def.pthread = task;
00013     _thread_def.tpriority = priority;
00014     _thread_def.stacksize = stack_size;
00015     if (stack_pointer != NULL) {
00016         _thread_def.stack_pointer = stack_pointer;
00017     } else {
00018         _thread_def.stack_pointer = (unsigned char*) malloc(stack_size);
00019         if (_thread_def.stack_pointer == NULL)
00020             error("Error allocating the stack memory");
00021     }
00022 #endif
00023     _tid = osThreadCreate(&_thread_def, argument);
00024 }
00025 
00026 osStatus Thread::terminate () {
00027     return osThreadTerminate(_tid);
00028 }
00029 
00030 osStatus Thread::set_priority (osPriority priority) {
00031     return osThreadSetPriority(_tid, priority);
00032 }
00033 
00034 osPriority Thread::get_priority () {
00035     return osThreadGetPriority(_tid);
00036 }
00037 
00038 int32_t Thread::signal_set (int32_t signals) {
00039     return osSignalSet(_tid, signals);
00040 }
00041 
00042 osEvent Thread::signal_wait (int32_t signals, uint32_t millisec) {
00043     return osSignalWait(signals, millisec);
00044 }
00045 
00046 osStatus Thread::wait (uint32_t millisec) {
00047     return osDelay(millisec);
00048 }
00049 
00050 osStatus Thread::yield () {
00051     return osThreadYield();
00052 }
00053 
00054 osThreadId Thread::gettid () {
00055     return osThreadGetId();
00056 }
00057 
00058 }