EtcPal  HEAD (unstable)
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
129 typedef struct EtcPalThreadParams
130 {
132  unsigned int priority;
141  unsigned int stack_size;
143  const char* thread_name;
161 
163 #define ETCPAL_THREAD_SET_DEFAULT_PARAMS(threadparamsptr) \
164  do \
165  { \
166  (threadparamsptr)->priority = ETCPAL_THREAD_DEFAULT_PRIORITY; \
167  (threadparamsptr)->stack_size = ETCPAL_THREAD_DEFAULT_STACK; \
168  (threadparamsptr)->thread_name = ETCPAL_THREAD_DEFAULT_NAME; \
169  (threadparamsptr)->platform_data = NULL; \
170  } while (0)
171 
180 #define ETCPAL_THREAD_PARAMS_INIT_VALUES \
181  ETCPAL_THREAD_DEFAULT_PRIORITY, ETCPAL_THREAD_DEFAULT_STACK, ETCPAL_THREAD_DEFAULT_NAME, NULL
182 
191 #define ETCPAL_THREAD_PARAMS_INIT \
192  { \
193  ETCPAL_THREAD_PARAMS_INIT_VALUES \
194  }
195 
197  const EtcPalThreadParams* params,
198  void (*thread_fn)(void*),
199  void* thread_arg);
200 etcpal_error_t etcpal_thread_sleep(unsigned int sleep_ms);
205 
206 #if !defined(etcpal_thread_get_current_os_handle) || DOXYGEN
208 
213 #endif
214 #ifdef __cplusplus
215 }
216 #endif
217 #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.
etcpal_error_t etcpal_thread_sleep(unsigned int sleep_ms)
Provides a platform-neutral sleep.
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.
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:130
unsigned int priority
The priority of the thread.
Definition: thread.h:132
void * platform_data
Pointer to a platform-specific parameter structure.
Definition: thread.h:159
unsigned int stack_size
The stack size of the thread in bytes.
Definition: thread.h:141
const char * thread_name
A name for the thread, maximum length ETCPAL_THREAD_NAME_MAX_LENGTH.
Definition: thread.h:143