EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
thread.h
1 /******************************************************************************
2  * Copyright 2022 ETC Inc.
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  * This file is a part of EtcPal. For more information, go to:
17  * https://github.com/ETCLabs/EtcPal
18  ******************************************************************************/
19 
20 #ifndef ETCPAL_THREAD_H_
21 #define ETCPAL_THREAD_H_
22 
23 #include "etcpal/error.h"
24 #include "etcpal/os_thread.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
126 typedef struct EtcPalThreadParams
127 {
129  unsigned int priority;
138  unsigned int stack_size;
140  const char* thread_name;
158 
160 #define ETCPAL_THREAD_SET_DEFAULT_PARAMS(threadparamsptr) \
161  do \
162  { \
163  (threadparamsptr)->priority = ETCPAL_THREAD_DEFAULT_PRIORITY; \
164  (threadparamsptr)->stack_size = ETCPAL_THREAD_DEFAULT_STACK; \
165  (threadparamsptr)->thread_name = ETCPAL_THREAD_DEFAULT_NAME; \
166  (threadparamsptr)->platform_data = NULL; \
167  } while (0)
168 
177 #define ETCPAL_THREAD_PARAMS_INIT_VALUES \
178  ETCPAL_THREAD_DEFAULT_PRIORITY, ETCPAL_THREAD_DEFAULT_STACK, ETCPAL_THREAD_DEFAULT_NAME, NULL
179 
188 #define ETCPAL_THREAD_PARAMS_INIT \
189  { \
190  ETCPAL_THREAD_PARAMS_INIT_VALUES \
191  }
192 
194  const EtcPalThreadParams* params,
195  void (*thread_fn)(void*),
196  void* thread_arg);
201 
202 #if !defined(etcpal_thread_sleep) || DOXYGEN
203 void etcpal_thread_sleep(unsigned int sleep_ms);
204 #endif
205 
206 #if !defined(etcpal_thread_get_current_os_handle) || DOXYGEN
208 #endif
209 
214 #ifdef __cplusplus
215 }
216 #endif
217 
218 #endif /* ETCPAL_THREAD_H_ */
etcpal_error_t
A set of error codes that can be returned by library functions.
Definition: error.h:49
struct EtcPalThreadParams EtcPalThreadParams
A set of parameters for an etcpal_thread.
etcpal_error_t etcpal_thread_create(etcpal_thread_t *id, const EtcPalThreadParams *params, void(*thread_fn)(void *), void *thread_arg)
Create a new thread.
etcpal_error_t etcpal_thread_timed_join(etcpal_thread_t *id, int timeout_ms)
Wait for a thread to finish execution, giving up after a timeout.
PLATFORM_DEFINED etcpal_thread_t
The thread handle.
Definition: thread.dox:35
etcpal_error_t etcpal_thread_join(etcpal_thread_t *id)
Wait for a thread to finish execution.
etcpal_error_t etcpal_thread_terminate(etcpal_thread_t *id)
Forcefully kill a thread.
PLATFORM_DEFINED etcpal_thread_os_handle_t
The native OS handle type for threads on this platform.
Definition: thread.dox:42
etcpal_thread_os_handle_t etcpal_thread_get_current_os_handle(void)
Get the native OS handle of the currently executing thread.
void etcpal_thread_sleep(unsigned int sleep_ms)
Provides a platform-neutral sleep.
etcpal_thread_os_handle_t etcpal_thread_get_os_handle(etcpal_thread_t *id)
Get the native OS handle of an EtcPal thread.
A set of parameters for an etcpal_thread.
Definition: thread.h:127
unsigned int priority
The priority of the thread.
Definition: thread.h:129
void * platform_data
Pointer to a platform-specific parameter structure.
Definition: thread.h:156
unsigned int stack_size
The stack size of the thread in bytes.
Definition: thread.h:138
const char * thread_name
A name for the thread, maximum length ETCPAL_THREAD_NAME_MAX_LENGTH.
Definition: thread.h:140