spBase
Loading...
Searching...
No Matches
spThread.h
Go to the documentation of this file.
1
4#ifndef __SPTHREAD_H
5#define __SPTHREAD_H
6
7#include <sp/spDefs.h>
8
9#if defined(_WIN32) && !defined(HAVE_PTHREAD)
10#if defined(USE_MOTIF) || defined(GTK)
11#undef Status
12#define INT32 wINT32
13#define boolean wboolean
14#endif
15#include <windows.h>
16#if defined(_MSC_VER)
17#include <process.h>
18#define HAVE_BEGINTHREADEX
19#endif /* defined(_MSC_VER) */
20#if defined(USE_MOTIF) || defined(USE_GTK)
21#define Status int
22#undef INT32
23#undef boolean
24#endif
25#elif defined(MACOS) && !defined(MACOSX)
26#include <Threads.h>
27#elif defined(MACOSX) || defined(HAVE_PTHREAD)
28#include <pthread.h>
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
38 /*----@addtogroup spThreadGroup----*/
39
40#define SP_THREAD_PRIORITY_TIME_CRITICAL 15
41#define SP_THREAD_PRIORITY_HIGHEST 2
42#define SP_THREAD_PRIORITY_ABOVE_NORMAL 1
43#define SP_THREAD_PRIORITY_NORMAL 0
44#define SP_THREAD_PRIORITY_BELOW_NORMAL (-1)
45#define SP_THREAD_PRIORITY_LOWEST (-2)
46#define SP_THREAD_PRIORITY_IDLE (-15)
48#define SP_THREAD_EXIT_SUCCESS 0
49#define SP_THREAD_EXIT_FAILURE -2
50#define SP_THREAD_EXIT_CANCELED -1
51
52#define SP_EVENT_TIMEOUT_INFINITE -1
53#define SP_EVENT_WAIT_FAILED -1
54#define SP_EVENT_WAIT_SIGNALED 0
55#define SP_EVENT_WAIT_TIMEOUT 1
56#define SP_EVENT_WAIT_ABANDONED 2
58typedef enum {
59 SP_THREAD_LEVEL_LOW = 0,
60 SP_THREAD_LEVEL_BELOW_MIDDLE = 25,
61 SP_THREAD_LEVEL_MIDDLE = 50,
62 SP_THREAD_LEVEL_ABOVE_MIDDLE = 75,
63 SP_THREAD_LEVEL_HIGH = 100,
64} spThreadLevel;
65
66 /*----@addtogroup spThreadGroup----*/
67
68#if defined(_WIN32) && !defined(HAVE_PTHREAD)
69#if defined(HAVE_BEGINTHREADEX)
71#define spThreadReturn unsigned __stdcall
73typedef unsigned (__stdcall *spThreadFunc)(void *data);
74#else
76#define spThreadReturn DWORD WINAPI
78typedef DWORD (WINAPI *spThreadFunc)(void *data);
79#endif
80
81#define SP_THREAD_RETURN_SUCCESS 0
82#define SP_THREAD_RETURN_FAILURE 1
83
85#define spThreadId DWORD
86
87#else
89#define spThreadReturn void *
90typedef spThreadReturn (*spThreadFunc)(void *data);
91
92#define SP_THREAD_RETURN_SUCCESS (void *)0
93#define SP_THREAD_RETURN_FAILURE (void *)1
94
95#if defined(MACOS) && !defined(MACOSX)
97#define spThreadId ThreadID
98#else
100#define spThreadId pthread_t
101#endif
102
103#endif
104
116
118typedef void (*spCommandThreadCallback)(spCommandThreadStatus status, long data, void *user_data);
119
120
121#if defined(MACOS)
122#pragma import on
123extern int spGetNumCoopThreadMac(void);
124#endif
125
127extern void *spCreateThread(long stacksize, int priority, spThreadFunc func, void *data);
129extern void spDestroyThread(void *handle);
132extern void spExitThread(long status);
134extern void spYieldThread(void);
136extern long spWaitThread(void *handle);
137
139extern spThreadId spGetThreadId(void *handle);
141extern spThreadId spGetCurrentThreadId(void);
143extern spBool spEqThreadId(spThreadId id1, spThreadId id2);
144
146extern void *spCreateMutex(const char *name);
148extern void spDestroyMutex(void *handle);
150extern spBool spLockMutex(void *handle);
152extern spBool spUnlockMutex(void *handle);
154extern spBool spWaitMutex(void *handle);
155
157extern void *spCreateEvent(spBool manual_reset, spBool initial_signal);
159extern spBool spDestroyEvent(void *handle);
161extern int spWaitEventTimeout(void *handle, long timeout_ms);
163extern spBool spWaitEvent(void *handle);
165extern spBool spSetEvent(void *handle);
167extern spBool spResetEvent(void *handle);
169extern spBool spPulseEvent(void *handle);
170
171extern spBool spIsThreadLevelVariable(void);
172extern spBool spIsLowLevelThreadUsed(void);
173extern spBool spSetThreadLevel(spThreadLevel level);
174extern spThreadLevel spGetThreadLevel(void);
175
183extern spBool spCreateCommandThread(const char *command, spCommandThreadCallback func, void *data);
184
185#if defined(MACOS)
186#pragma import off
187#endif
188
189 /*----@addtogroup spThreadGroup----*/
190
191#ifdef __cplusplus
192} /* Close scope of 'extern "C"' declaration */
193#endif
194
195#endif /* __SPTHREAD_H */
int spBool
Definition spDefs.h:248
void * spCreateThread(long stacksize, int priority, spThreadFunc func, void *data)
void * spCreateEvent(spBool manual_reset, spBool initial_signal)
long spWaitThread(void *handle)
spBool spLockMutex(void *handle)
spThreadId spGetCurrentThreadId(void)
void(* spCommandThreadCallback)(spCommandThreadStatus status, long data, void *user_data)
Definition spThread.h:118
spBool spPulseEvent(void *handle)
void * spCreateMutex(const char *name)
spBool spDestroyEvent(void *handle)
spBool spUnlockMutex(void *handle)
spCommandThreadStatus
Definition spThread.h:109
void spDestroyMutex(void *handle)
spBool spWaitEvent(void *handle)
void spExitThread(long status)
int spWaitEventTimeout(void *handle, long timeout_ms)
spBool spEqThreadId(spThreadId id1, spThreadId id2)
spBool spWaitMutex(void *handle)
spBool spSetEvent(void *handle)
void spYieldThread(void)
spBool spCreateCommandThread(const char *command, spCommandThreadCallback func, void *data)
spThreadId spGetThreadId(void *handle)
spBool spResetEvent(void *handle)
void spDestroyThread(void *handle)
@ SP_COMMAND_THREAD_COMMAND_FINISHED
Definition spThread.h:112
@ SP_COMMAND_THREAD_STARTED
Definition spThread.h:110
@ SP_COMMAND_THREAD_FINISHED
Definition spThread.h:111
@ SP_COMMAND_THREAD_COMMAND_FAILED
Definition spThread.h:113
@ SP_COMMAND_THREAD_COMMAND_WAIT_FAILED
Definition spThread.h:114