KDDI Fx0 hackathon
/
MurataTypeYD_Websocket_Sample_full
Websocket_Sample for MurataTypeYD
mbed-rtos/rtos/Thread.h@1:b5ac0f971f43, 2015-03-12 (annotated)
- Committer:
- komoritan
- Date:
- Thu Mar 12 12:15:46 2015 +0000
- Revision:
- 1:b5ac0f971f43
- Parent:
- 0:14bd24b5a77f
Fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 0:14bd24b5a77f | 1 | /* mbed Microcontroller Library |
komoritan | 0:14bd24b5a77f | 2 | * Copyright (c) 2006-2012 ARM Limited |
komoritan | 0:14bd24b5a77f | 3 | * |
komoritan | 0:14bd24b5a77f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
komoritan | 0:14bd24b5a77f | 5 | * of this software and associated documentation files (the "Software"), to deal |
komoritan | 0:14bd24b5a77f | 6 | * in the Software without restriction, including without limitation the rights |
komoritan | 0:14bd24b5a77f | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
komoritan | 0:14bd24b5a77f | 8 | * copies of the Software, and to permit persons to whom the Software is |
komoritan | 0:14bd24b5a77f | 9 | * furnished to do so, subject to the following conditions: |
komoritan | 0:14bd24b5a77f | 10 | * |
komoritan | 0:14bd24b5a77f | 11 | * The above copyright notice and this permission notice shall be included in |
komoritan | 0:14bd24b5a77f | 12 | * all copies or substantial portions of the Software. |
komoritan | 0:14bd24b5a77f | 13 | * |
komoritan | 0:14bd24b5a77f | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
komoritan | 0:14bd24b5a77f | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
komoritan | 0:14bd24b5a77f | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
komoritan | 0:14bd24b5a77f | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
komoritan | 0:14bd24b5a77f | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
komoritan | 0:14bd24b5a77f | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
komoritan | 0:14bd24b5a77f | 20 | * SOFTWARE. |
komoritan | 0:14bd24b5a77f | 21 | */ |
komoritan | 0:14bd24b5a77f | 22 | #ifndef THREAD_H |
komoritan | 0:14bd24b5a77f | 23 | #define THREAD_H |
komoritan | 0:14bd24b5a77f | 24 | |
komoritan | 0:14bd24b5a77f | 25 | #include <stdint.h> |
komoritan | 0:14bd24b5a77f | 26 | #include "cmsis_os.h" |
komoritan | 0:14bd24b5a77f | 27 | |
komoritan | 0:14bd24b5a77f | 28 | namespace rtos { |
komoritan | 0:14bd24b5a77f | 29 | |
komoritan | 0:14bd24b5a77f | 30 | /** The Thread class allow defining, creating, and controlling thread functions in the system. */ |
komoritan | 0:14bd24b5a77f | 31 | class Thread { |
komoritan | 0:14bd24b5a77f | 32 | public: |
komoritan | 0:14bd24b5a77f | 33 | /** Create a new thread, and start it executing the specified function. |
komoritan | 0:14bd24b5a77f | 34 | @param task function to be executed by this thread. |
komoritan | 0:14bd24b5a77f | 35 | @param argument pointer that is passed to the thread function as start argument. (default: NULL). |
komoritan | 0:14bd24b5a77f | 36 | @param priority initial priority of the thread function. (default: osPriorityNormal). |
komoritan | 0:14bd24b5a77f | 37 | @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
komoritan | 0:14bd24b5a77f | 38 | @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). |
komoritan | 0:14bd24b5a77f | 39 | */ |
komoritan | 0:14bd24b5a77f | 40 | Thread(void (*task)(void const *argument), void *argument=NULL, |
komoritan | 0:14bd24b5a77f | 41 | osPriority priority=osPriorityNormal, |
komoritan | 0:14bd24b5a77f | 42 | uint32_t stack_size=DEFAULT_STACK_SIZE, |
komoritan | 0:14bd24b5a77f | 43 | unsigned char *stack_pointer=NULL); |
komoritan | 0:14bd24b5a77f | 44 | |
komoritan | 0:14bd24b5a77f | 45 | /** Terminate execution of a thread and remove it from Active Threads |
komoritan | 0:14bd24b5a77f | 46 | @return status code that indicates the execution status of the function. |
komoritan | 0:14bd24b5a77f | 47 | */ |
komoritan | 0:14bd24b5a77f | 48 | osStatus terminate(); |
komoritan | 0:14bd24b5a77f | 49 | |
komoritan | 0:14bd24b5a77f | 50 | /** Set priority of an active thread |
komoritan | 0:14bd24b5a77f | 51 | @param priority new priority value for the thread function. |
komoritan | 0:14bd24b5a77f | 52 | @return status code that indicates the execution status of the function. |
komoritan | 0:14bd24b5a77f | 53 | */ |
komoritan | 0:14bd24b5a77f | 54 | osStatus set_priority(osPriority priority); |
komoritan | 0:14bd24b5a77f | 55 | |
komoritan | 0:14bd24b5a77f | 56 | /** Get priority of an active thread |
komoritan | 0:14bd24b5a77f | 57 | @return current priority value of the thread function. |
komoritan | 0:14bd24b5a77f | 58 | */ |
komoritan | 0:14bd24b5a77f | 59 | osPriority get_priority(); |
komoritan | 0:14bd24b5a77f | 60 | |
komoritan | 0:14bd24b5a77f | 61 | /** Set the specified Signal Flags of an active thread. |
komoritan | 0:14bd24b5a77f | 62 | @param signals specifies the signal flags of the thread that should be set. |
komoritan | 0:14bd24b5a77f | 63 | @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. |
komoritan | 0:14bd24b5a77f | 64 | */ |
komoritan | 0:14bd24b5a77f | 65 | int32_t signal_set(int32_t signals); |
komoritan | 0:14bd24b5a77f | 66 | |
komoritan | 0:14bd24b5a77f | 67 | /** State of the Thread */ |
komoritan | 0:14bd24b5a77f | 68 | enum State { |
komoritan | 0:14bd24b5a77f | 69 | Inactive, /**< Not created or terminated */ |
komoritan | 0:14bd24b5a77f | 70 | Ready, /**< Ready to run */ |
komoritan | 0:14bd24b5a77f | 71 | Running, /**< Running */ |
komoritan | 0:14bd24b5a77f | 72 | WaitingDelay, /**< Waiting for a delay to occur */ |
komoritan | 0:14bd24b5a77f | 73 | WaitingInterval, /**< Waiting for an interval to occur */ |
komoritan | 0:14bd24b5a77f | 74 | WaitingOr, /**< Waiting for one event in a set to occur */ |
komoritan | 0:14bd24b5a77f | 75 | WaitingAnd, /**< Waiting for multiple events in a set to occur */ |
komoritan | 0:14bd24b5a77f | 76 | WaitingSemaphore, /**< Waiting for a semaphore event to occur */ |
komoritan | 0:14bd24b5a77f | 77 | WaitingMailbox, /**< Waiting for a mailbox event to occur */ |
komoritan | 0:14bd24b5a77f | 78 | WaitingMutex, /**< Waiting for a mutex event to occur */ |
komoritan | 0:14bd24b5a77f | 79 | }; |
komoritan | 0:14bd24b5a77f | 80 | |
komoritan | 0:14bd24b5a77f | 81 | /** State of this Thread |
komoritan | 0:14bd24b5a77f | 82 | @return the State of this Thread |
komoritan | 0:14bd24b5a77f | 83 | */ |
komoritan | 0:14bd24b5a77f | 84 | State get_state(); |
komoritan | 0:14bd24b5a77f | 85 | |
komoritan | 0:14bd24b5a77f | 86 | /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread. |
komoritan | 0:14bd24b5a77f | 87 | @param signals wait until all specified signal flags set or 0 for any single signal flag. |
komoritan | 0:14bd24b5a77f | 88 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
komoritan | 0:14bd24b5a77f | 89 | @return event flag information or error code. |
komoritan | 0:14bd24b5a77f | 90 | */ |
komoritan | 0:14bd24b5a77f | 91 | static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever); |
komoritan | 0:14bd24b5a77f | 92 | |
komoritan | 0:14bd24b5a77f | 93 | /** Wait for a specified time period in millisec: |
komoritan | 0:14bd24b5a77f | 94 | @param millisec time delay value |
komoritan | 0:14bd24b5a77f | 95 | @return status code that indicates the execution status of the function. |
komoritan | 0:14bd24b5a77f | 96 | */ |
komoritan | 0:14bd24b5a77f | 97 | static osStatus wait(uint32_t millisec); |
komoritan | 0:14bd24b5a77f | 98 | |
komoritan | 0:14bd24b5a77f | 99 | /** Pass control to next thread that is in state READY. |
komoritan | 0:14bd24b5a77f | 100 | @return status code that indicates the execution status of the function. |
komoritan | 0:14bd24b5a77f | 101 | */ |
komoritan | 0:14bd24b5a77f | 102 | static osStatus yield(); |
komoritan | 0:14bd24b5a77f | 103 | |
komoritan | 0:14bd24b5a77f | 104 | /** Get the thread id of the current running thread. |
komoritan | 0:14bd24b5a77f | 105 | @return thread ID for reference by other functions or NULL in case of error. |
komoritan | 0:14bd24b5a77f | 106 | */ |
komoritan | 0:14bd24b5a77f | 107 | static osThreadId gettid(); |
komoritan | 0:14bd24b5a77f | 108 | |
komoritan | 0:14bd24b5a77f | 109 | virtual ~Thread(); |
komoritan | 0:14bd24b5a77f | 110 | |
komoritan | 0:14bd24b5a77f | 111 | private: |
komoritan | 0:14bd24b5a77f | 112 | osThreadId _tid; |
komoritan | 0:14bd24b5a77f | 113 | osThreadDef_t _thread_def; |
komoritan | 0:14bd24b5a77f | 114 | bool _dynamic_stack; |
komoritan | 0:14bd24b5a77f | 115 | }; |
komoritan | 0:14bd24b5a77f | 116 | |
komoritan | 0:14bd24b5a77f | 117 | } |
komoritan | 0:14bd24b5a77f | 118 | #endif |