1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef THREAD_H 17 #define THREAD_H 18 19 #include "reactor.h" 20 #include <stdint.h> 21 #include <stdbool.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define THREAD_NAME_SIZE 16 28 #define MAX_STATIC_PRIORITY 20 29 #define MIN_STATIC_PRIORITY -20 30 31 typedef struct Thread Thread; 32 typedef void (*TaskFunc)(void *context); 33 34 /** 35 * @brief Perform instantiation of the Thread. 36 * 37 * @param name Thread name, length less or equal 16 bytes. 38 * @return Thread pointer. 39 * @since 6 40 */ 41 Thread *ThreadCreate(const char *name); 42 43 /** 44 * @brief Destroy instantiation of the Thread. 45 * 46 * @param thread Thread pointer. 47 * @since 6 48 */ 49 void ThreadDelete(Thread *thread); 50 51 /** 52 * @brief Post Task to Thread. 53 * 54 * @param thread Thread pointer. 55 * @param func TaskFunc. 56 * @param parameter TaskFunc's context. 57 * @since 6 58 */ 59 void ThreadPostTask(Thread *thread, TaskFunc func, void *context); 60 61 /** 62 * @brief Return whether current running thread is equal to thread in parameter. 63 * 64 * @param thread Thread pointer. 65 * @return Same return 0, not same return -1. 66 * @since 6 67 */ 68 int32_t ThreadIsSelf(const Thread *thread); 69 70 /** 71 * @brief Get Thread Reactor. 72 * 73 * @param thread Thread pointer. 74 * @return Reactor of thread 75 * @since 6 76 */ 77 Reactor *ThreadGetReactor(const Thread *thread); 78 79 #ifdef __cplusplus 80 } 81 #endif 82 83 #endif // THREAD_H