lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_thread.h
1 /******************************************************************************
2  * Copyright 2018 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 lwpa. For more information, go to:
17  * https://github.com/ETCLabs/lwpa
18  ******************************************************************************/
19 
20 #ifndef _LWPA_THREAD_H_
21 #define _LWPA_THREAD_H_
22 
23 #include <winsock2.h>
24 #include <windows.h>
25 #include <process.h>
26 
27 #include "lwpa_common.h"
28 #include "lwpa_bool.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 typedef struct LwpaThreadParams
35 {
36  unsigned int thread_priority;
37  unsigned int stack_size;
38  char *thread_name;
39  void *platform_data;
41 
42 /* Windows has no additional platform data and thus platform_data in the struct
43  * above is ignored. */
44 
45 #define LWPA_THREAD_DEFAULT_PRIORITY THREAD_PRIORITY_NORMAL
46 #define LWPA_THREAD_DEFAULT_STACK 0
47 #define LWPA_THREAD_DEFAULT_NAME "lwpa_thread"
48 
49 #define LWPA_THREAD_NAME_MAX_LENGTH 32
50 
51 typedef struct
52 {
53  void (*fn)(void *);
54  void *arg;
55  HANDLE tid;
56  char name[LWPA_THREAD_NAME_MAX_LENGTH];
58 
59 bool lwpa_thread_create(lwpa_thread_t *id, const LwpaThreadParams *params, void (*thread_fn)(void *), void *thread_arg);
60 bool lwpa_thread_stop(lwpa_thread_t *id, int wait_ms);
61 #define lwpa_thread_sleep(sleep_ms) Sleep(sleep_ms)
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif /* LWPA_THREAD_H_ */
UNDEFINED lwpa_thread_t
The thread identifier.
Definition: lwpa_thread.dox:53
struct LwpaThreadParams LwpaThreadParams
A set of parameters for an lwpa_thread.
bool lwpa_thread_create(lwpa_thread_t *id, const LwpaThreadParams *params, void(*thread_fn)(void *), void *thread_arg)
Create a new thread.
Definition: lwpa_thread.c:35
bool lwpa_thread_stop(lwpa_thread_t *id, int wait_ms)
Stop a thread.
Definition: lwpa_thread.c:54
#define LWPA_THREAD_NAME_MAX_LENGTH
The maximum length of an lwpa_thread name C-string.
Definition: lwpa_thread.dox:47
A set of parameters for an lwpa_thread.
Definition: lwpa_thread.dox:18
unsigned int thread_priority
The priority of the thread.
Definition: lwpa_thread.dox:21
void * platform_data
Pointer to a platform-specific parameter structure.
Definition: lwpa_thread.dox:28
unsigned int stack_size
The stack size of the thread.
Definition: lwpa_thread.dox:24
char * thread_name
A name for the thread, maximum length LWPA_THREAD_NAME_MAX_LENGTH.
Definition: lwpa_thread.dox:26
Definition: lwpa_thread.h:46