EtcPal  0.3.0
ETC Platform Abstraction Layer (EtcPal)
View other versions:
thread.h
1 /******************************************************************************
2  * Copyright 2020 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;
131  unsigned int stack_size;
133  const char* thread_name;
151 
153 #define ETCPAL_THREAD_SET_DEFAULT_PARAMS(threadparamsptr) \
154  do \
155  { \
156  (threadparamsptr)->priority = ETCPAL_THREAD_DEFAULT_PRIORITY; \
157  (threadparamsptr)->stack_size = ETCPAL_THREAD_DEFAULT_STACK; \
158  (threadparamsptr)->thread_name = ETCPAL_THREAD_DEFAULT_NAME; \
159  (threadparamsptr)->platform_data = NULL; \
160  } while (0)
161 
170 #define ETCPAL_THREAD_PARAMS_INIT_VALUES \
171  ETCPAL_THREAD_DEFAULT_PRIORITY, ETCPAL_THREAD_DEFAULT_STACK, ETCPAL_THREAD_DEFAULT_NAME, NULL
172 
181 #define ETCPAL_THREAD_PARAMS_INIT \
182  { \
183  ETCPAL_THREAD_PARAMS_INIT_VALUES \
184  }
185 
187  const EtcPalThreadParams* params,
188  void (*thread_fn)(void*),
189  void* thread_arg);
193 
194 #if !defined(etcpal_thread_sleep) || DOXYGEN
195 void etcpal_thread_sleep(unsigned int sleep_ms);
196 #endif
197 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #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.
void etcpal_thread_sleep(unsigned int sleep_ms)
Provides a platform-neutral sleep.
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:149
unsigned int stack_size
The stack size of the thread.
Definition: thread.h:131
const char * thread_name
A name for the thread, maximum length ETCPAL_THREAD_NAME_MAX_LENGTH.
Definition: thread.h:133