1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /** 17 ************************************************************************ 18 * @file M4OSA_Thread.h 19 * @ingroup OSAL 20 * @brief thread API 21 ************************************************************************ 22 */ 23 24 25 #ifndef M4OSA_THREAD_H 26 #define M4OSA_THREAD_H 27 28 #include "M4OSA_Types.h" 29 #include "M4OSA_Error.h" 30 #include "M4OSA_OptionID.h" 31 32 33 /* Definition of common error codes */ 34 #define M4ERR_THREAD_NOT_STARTED M4OSA_ERR_CREATE(M4_ERR,M4OSA_THREAD,0x000001) 35 36 37 typedef enum 38 { 39 M4OSA_kThreadOpened = 0x100, 40 M4OSA_kThreadStarting = 0x200, 41 M4OSA_kThreadRunning = 0x300, 42 M4OSA_kThreadStopping = 0x400, 43 M4OSA_kThreadClosed = 0x500 44 } M4OSA_ThreadState; 45 46 47 48 typedef enum 49 { 50 M4OSA_kThreadHighestPriority = 0x000, 51 M4OSA_kThreadHighPriority = 0x100, 52 M4OSA_kThreadNormalPriority = 0x200, 53 M4OSA_kThreadLowPriority = 0x300, 54 M4OSA_kThreadLowestPriority = 0x400 55 } M4OSA_ThreadPriorityLevel; 56 57 58 59 typedef enum 60 { 61 M4OSA_ThreadStarted 62 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x01), 63 64 M4OSA_ThreadStopped 65 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x02), 66 67 M4OSA_ThreadPriority 68 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x03), 69 70 M4OSA_ThreadName 71 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x04), 72 73 M4OSA_ThreadStackSize 74 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x05), 75 76 M4OSA_ThreadUserData 77 = M4OSA_OPTION_ID_CREATE(M4_READ|M4_WRITE, M4OSA_THREAD, 0x06) 78 79 } M4OSA_ThreadOptionID; 80 81 82 83 typedef M4OSA_ERR (*M4OSA_ThreadDoIt)(M4OSA_Void*); 84 typedef M4OSA_Void (*M4OSA_ThreadCallBack)(M4OSA_Context, M4OSA_Void*); 85 86 #ifdef __cplusplus 87 extern "C" 88 { 89 #endif 90 91 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncOpen( M4OSA_Context* context, 92 M4OSA_ThreadDoIt func ); 93 94 95 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncStart( M4OSA_Context context, 96 M4OSA_Void* param ); 97 98 99 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncStop( M4OSA_Context context ); 100 101 102 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncClose( M4OSA_Context context ); 103 104 105 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncGetState( M4OSA_Context context, 106 M4OSA_ThreadState* state ); 107 108 109 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSleep( M4OSA_UInt32 time ); 110 111 112 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncSetOption(M4OSA_Context context, 113 M4OSA_ThreadOptionID option, 114 M4OSA_DataOption value ); 115 116 117 M4OSAL_REALTIME_EXPORT_TYPE M4OSA_ERR M4OSA_threadSyncGetOption(M4OSA_Context context, 118 M4OSA_ThreadOptionID option, 119 M4OSA_DataOption* value ); 120 121 #ifdef __cplusplus 122 } 123 #endif 124 125 126 #endif /*M4OSA_THREAD_H*/ 127 128