Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-rtos by
Thread.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2012 ARM Limited 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 */ 00022 #ifndef THREAD_H 00023 #define THREAD_H 00024 00025 #include <stdint.h> 00026 #include "cmsis_os.h" 00027 00028 namespace rtos { 00029 00030 /** The Thread class allow defining, creating, and controlling thread functions in the system. */ 00031 class Thread { 00032 public: 00033 /** Create a new thread, and start it executing the specified function. 00034 @param task function to be executed by this thread. 00035 @param argument pointer that is passed to the thread function as start argument. (default: NULL). 00036 @param priority initial priority of the thread function. (default: osPriorityNormal). 00037 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). 00038 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). 00039 */ 00040 Thread(void (*task)(void const *argument), void *argument=NULL, 00041 osPriority priority=osPriorityNormal, 00042 uint32_t stack_size=DEFAULT_STACK_SIZE, 00043 unsigned char *stack_pointer=NULL); 00044 00045 /** Terminate execution of a thread and remove it from Active Threads 00046 @return status code that indicates the execution status of the function. 00047 */ 00048 osStatus terminate(); 00049 00050 /** Set priority of an active thread 00051 @param priority new priority value for the thread function. 00052 @return status code that indicates the execution status of the function. 00053 */ 00054 osStatus set_priority(osPriority priority); 00055 00056 /** Get priority of an active thread 00057 @return current priority value of the thread function. 00058 */ 00059 osPriority get_priority(); 00060 00061 /** Set the specified Signal Flags of an active thread. 00062 @param signals specifies the signal flags of the thread that should be set. 00063 @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 00064 */ 00065 int32_t signal_set(int32_t signals); 00066 00067 /** State of the Thread */ 00068 enum State { 00069 Inactive, /**< Not created or terminated */ 00070 Ready, /**< Ready to run */ 00071 Running, /**< Running */ 00072 WaitingDelay, /**< Waiting for a delay to occur */ 00073 WaitingInterval, /**< Waiting for an interval to occur */ 00074 WaitingOr, /**< Waiting for one event in a set to occur */ 00075 WaitingAnd, /**< Waiting for multiple events in a set to occur */ 00076 WaitingSemaphore, /**< Waiting for a semaphore event to occur */ 00077 WaitingMailbox, /**< Waiting for a mailbox event to occur */ 00078 WaitingMutex, /**< Waiting for a mutex event to occur */ 00079 }; 00080 00081 /** State of this Thread 00082 @return the State of this Thread 00083 */ 00084 State get_state(); 00085 00086 /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread. 00087 @param signals wait until all specified signal flags set or 0 for any single signal flag. 00088 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). 00089 @return event flag information or error code. 00090 */ 00091 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever); 00092 00093 /** Wait for a specified time period in millisec: 00094 @param millisec time delay value 00095 @return status code that indicates the execution status of the function. 00096 */ 00097 static osStatus wait(uint32_t millisec); 00098 00099 /** Pass control to next thread that is in state READY. 00100 @return status code that indicates the execution status of the function. 00101 */ 00102 static osStatus yield(); 00103 00104 /** Get the thread id of the current running thread. 00105 @return thread ID for reference by other functions or NULL in case of error. 00106 */ 00107 static osThreadId gettid(); 00108 00109 virtual ~Thread(); 00110 00111 private: 00112 osThreadId _tid; 00113 osThreadDef_t _thread_def; 00114 bool _dynamic_stack; 00115 }; 00116 00117 } 00118 #endif
Generated on Wed Jul 13 2022 18:32:39 by
