forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CWThread.h
140 lines (112 loc) · 5.7 KB
/
CWThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************************
* Copyright (c) 2006-7 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* This program is free software; you can redistribute it and/or modify it under the terms *
* of the GNU General Public License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with this *
* program; if not, write to the: *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
* MA 02111-1307, USA. *
* *
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi ([email protected]) *
* Del Moro Andrea ([email protected]) *
* Giovannini Federica ([email protected]) *
* Massimo Vellucci ([email protected]) *
* Mauro Bisson ([email protected]) *
*******************************************************************************************/
#ifndef __CAPWAP_CWThread_HEADER__
#define __CAPWAP_CWThread_HEADER__
#include "CWErrorHandling.h"
#include <pthread.h>
#include <limits.h>
#include <semaphore.h>
#include <time.h>
#include "timerlib.h"
#ifdef MACOSX
/* Mac OS X */
#define CW_USE_NAMED_SEMAPHORES
#include <unistd.h>
typedef struct {
sem_t *semPtr;
} CWThreadSem;
#include <sys/types.h>
#include <sys/un.h>
#define max(a,b) ( (a) > (b) ? (a) : (b) )
#else
typedef sem_t CWThreadSem;
#endif
#ifdef HAVE_SEM_TIMEDWAIT
typedef CWThreadSem CWThreadTimedSem;
#else
typedef int CWThreadTimedSem[2]; /* pair of Unix Domain Socket */
#endif
typedef pthread_t CWThread;
typedef pthread_mutex_t CWThreadMutex;
typedef pthread_cond_t CWThreadCondition;
typedef pthread_key_t CWThreadSpecific;
typedef pthread_once_t CWThreadOnce;
typedef void* (*CW_THREAD_FUNCTION)(void*);
typedef int CWThreadId;
typedef int CWTimerID;
typedef void *CWTimerArg;
#define CW_THREAD_RETURN_TYPE void*
#define CWThreadSigMask(how, set, old_set) pthread_sigmask(how, set, old_set)
#define CWThreadIsEqual(t1, t2) pthread_equal(t1,t2)
#define CWThreadSelf() pthread_self()
#define CWThreadKill(t1, signal) pthread_kill(t1,signal)
#define CWThreadSendSignal CWThreadKill
#define CW_THREAD_ONCE_INIT PTHREAD_ONCE_INIT
#define CWThreadCallOnce pthread_once
__inline__ sem_t *CWThreadGetSemT(CWThreadSem *semPtr);
CWBool CWThreadInitLib(void);
CWBool CWCreateThread(CWThread *newThread,
CW_THREAD_FUNCTION threadFunc,
void *arg);
CWBool CWCreateThreadCondition(CWThreadCondition *theCondition);
void CWDestroyThreadCondition(CWThreadCondition *theCondition);
CWBool CWWaitThreadCondition(CWThreadCondition *theCondition,
CWThreadMutex *theMutex);
CWBool CWWaitThreadConditionTimeout(CWThreadCondition *theCondition,
CWThreadMutex *theMutex,
struct timespec *pTimeout);
void CWSignalThreadCondition(CWThreadCondition *theCondition);
CWBool CWCreateThreadMutex(CWThreadMutex *theMutex);
void CWDestroyThreadMutex(CWThreadMutex *theMutex);
CWBool CWThreadMutexLock(CWThreadMutex *theMutex);
CWBool CWThreadMutexTryLock(CWThreadMutex *theMutex);
void CWThreadMutexUnlock(CWThreadMutex *theMutex);
CWBool CWThreadCreateSem(CWThreadSem *semPtr, int value);
void CWThreadDestroySem(CWThreadSem *semPtr);
CWBool CWThreadSemWait(CWThreadSem *semPtr);
CWBool CWThreadSemPost(CWThreadSem *semPtr);
CWBool CWThreadSemGetValue(CWThreadSem *semPtr, int *valuePtr);
CWBool CWThreadCreateSpecific(CWThreadSpecific *specPtr,
void (*destructor)(void *));
void CWThreadDestroySpecific(CWThreadSpecific *specPtr);
void *CWThreadGetSpecific(CWThreadSpecific *specPtr);
CWBool CWThreadSetSpecific(CWThreadSpecific *specPtr, void *valPtr);
void CWExitThread(void);
//void *CWThreadManageTimers(void *arg);
CWBool CWTimerCancel(CWTimerID *idPtr);
CWBool CWTimerRequest(int sec,
CWThread *threadPtr,
CWTimerID *idPtr,
int signalToRaise);
void CWThreadSetSignals(int how, int num, ...);
CWBool CWThreadCreateTimedSem(CWThreadTimedSem *semPtr, int value);
CWBool CWThreadTimedSemIsZero(CWThreadTimedSem *semPtr);
CWBool CWThreadTimedSemSetValue(CWThreadTimedSem *semPtr, int value);
void CWThreadDestroyTimedSem(CWThreadTimedSem *semPtr);
CWBool CWThreadTimedSemWait(CWThreadTimedSem *semPtr, time_t sec, time_t nsec);
CWBool CWThreadTimedSemPost(CWThreadTimedSem *semPtr);
#endif