Thread.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2009, 2020 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  * https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  * Ian Craggs - initial implementation
15  * Ian Craggs, Allan Stockdill-Mander - async client updates
16  * Ian Craggs - fix for bug #420851
17  * Ian Craggs - change MacOS semaphore implementation
18  *******************************************************************************/
19 
20 #if !defined(THREAD_H)
21 #define THREAD_H
22 
23 #include "MQTTExportDeclarations.h"
24 
25 #include "MQTTClient.h"
26 
27 #include "mutex_type.h" /* Needed for mutex_type */
28 
29 #if defined(_WIN32) || defined(_WIN64)
30  #include <windows.h>
31  #define thread_type HANDLE
32  #define thread_id_type DWORD
33  #define thread_return_type DWORD
34  #define thread_fn LPTHREAD_START_ROUTINE
35  #define cond_type HANDLE
36  #define sem_type HANDLE
37  #undef ETIMEDOUT
38  #define ETIMEDOUT WSAETIMEDOUT
39 #else
40  #include <pthread.h>
41 
42  #define thread_type pthread_t
43  #define thread_id_type pthread_t
44  #define thread_return_type void*
45  typedef thread_return_type (*thread_fn)(void*);
46  typedef struct { pthread_cond_t cond; pthread_mutex_t mutex; } cond_type_struct;
48  #if defined(OSX)
49  #include <dispatch/dispatch.h>
50  typedef dispatch_semaphore_t sem_type;
51  #else
52  #include <semaphore.h>
53  typedef sem_t *sem_type;
54  #endif
55 
58  int Thread_wait_cond(cond_type condvar, int timeout);
60 #endif
61 
63 
68 
70 
72 int Thread_wait_sem(sem_type sem, int timeout);
73 int Thread_check_sem(sem_type sem);
74 int Thread_post_sem(sem_type sem);
76 
77 
78 #endif
int Thread_post_sem(sem_type sem)
Definition: Thread.c:313
#define LIBMQTT_API
sem_type Thread_create_sem(int *)
Definition: Thread.c:190
static int cond(LexState *ls)
Definition: lparser.c:1396
thread_return_type(* thread_fn)(void *)
Definition: Thread.h:45
LIBMQTT_API int Thread_unlock_mutex(mutex_type)
Definition: Thread.c:133
int Thread_wait_sem(sem_type sem, int timeout)
Definition: Thread.c:230
#define mutex_type
Definition: mutex_type.h:22
LIBMQTT_API thread_id_type Thread_getid()
Definition: Thread.c:176
int Thread_destroy_sem(sem_type sem)
Definition: Thread.c:341
cond_type Thread_create_cond(int *)
Definition: Thread.c:365
LIBMQTT_API int Thread_lock_mutex(mutex_type)
Definition: Thread.c:112
cond_type_struct * cond_type
Definition: Thread.h:47
#define thread_type
Definition: Thread.h:42
pthread_mutex_t mutex
Definition: Thread.h:46
#define thread_return_type
Definition: Thread.h:44
sem_t * sem_type
Definition: Thread.h:53
#define thread_id_type
Definition: Thread.h:43
int Thread_destroy_cond(cond_type)
Definition: Thread.c:444
int Thread_signal_cond(cond_type)
Definition: Thread.c:399
int Thread_check_sem(sem_type sem)
Definition: Thread.c:292
LIBMQTT_API thread_type Thread_start(thread_fn, void *)
Definition: Thread.c:60
LIBMQTT_API mutex_type Thread_create_mutex(int *)
Definition: Thread.c:88
int Thread_wait_cond(cond_type condvar, int timeout)
Definition: Thread.c:416
int Thread_destroy_mutex(mutex_type)
Definition: Thread.c:156


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48