Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
194 lines (163 loc) · 6.19 KB

SDL_thread.h

File metadata and controls

194 lines (163 loc) · 6.19 KB
 
Jun 22, 2011
Jun 22, 2011
1
2
/*
Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
Jun 22, 2011
Jun 22, 2011
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
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _SDL_thread_h
#define _SDL_thread_h
/**
* \file SDL_thread.h
*
* Header for the SDL thread management routines.
*/
#include "SDL_stdinc.h"
#include "SDL_error.h"
/* Thread synchronization primitives */
#include "SDL_mutex.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* The SDL thread structure, defined in SDL_thread.c */
struct SDL_Thread;
typedef struct SDL_Thread SDL_Thread;
/* The SDL thread ID */
typedef unsigned long SDL_threadID;
/* The SDL thread priority
*
* Note: On many systems you require special privileges to set high priority.
*/
typedef enum {
SDL_THREAD_PRIORITY_LOW,
SDL_THREAD_PRIORITY_NORMAL,
SDL_THREAD_PRIORITY_HIGH
} SDL_ThreadPriority;
/* The function passed to SDL_CreateThread()
It is passed a void* user context parameter and returns an int.
*/
typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
#if defined(__WIN32__) && !defined(HAVE_LIBC)
/**
* \file SDL_thread.h
*
* We compile SDL into a DLL. This means, that it's the DLL which
* creates a new thread for the calling process with the SDL_CreateThread()
* API. There is a problem with this, that only the RTL of the SDL.DLL will
* be initialized for those threads, and not the RTL of the calling
* application!
*
* To solve this, we make a little hack here.
*
* We'll always use the caller's _beginthread() and _endthread() APIs to
* start a new thread. This way, if it's the SDL.DLL which uses this API,
* then the RTL of SDL.DLL will be used to create the new thread, and if it's
* the application, then the RTL of the application will be used.
*
* So, in short:
* Always use the _beginthread() and _endthread() of the calling runtime
* library!
*/
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
#ifndef _WIN32_WCE
#include <process.h> /* This has _beginthread() and _endthread() defined! */
#endif
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *
func) (void
*),
void *arg, unsigned,
unsigned *threadID);
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
/**
* Create a thread.
*/
extern DECLSPEC SDL_Thread *SDLCALL
Oct 2, 2011
Oct 2, 2011
105
SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
Jun 22, 2011
Jun 22, 2011
106
107
108
109
110
111
112
113
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread);
#if defined(_WIN32_WCE)
/**
* Create a thread.
*/
Oct 2, 2011
Oct 2, 2011
114
#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, NULL, NULL)
Jun 22, 2011
Jun 22, 2011
115
116
117
118
119
120
#else
/**
* Create a thread.
*/
Oct 2, 2011
Oct 2, 2011
121
#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, _beginthreadex, _endthreadex)
Jun 22, 2011
Jun 22, 2011
122
123
124
125
126
127
#endif
#else
/**
* Create a thread.
Oct 2, 2011
Oct 2, 2011
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
*
* Thread naming is a little complicated: Most systems have very small
* limits for the string length (BeOS has 32 bytes, Linux currently has 16,
* Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
* have to see what happens with your system's debugger. The name should be
* UTF-8 (but using the naming limits of C identifiers is a better bet).
* There are no requirements for thread naming conventions, so long as the
* string is null-terminated UTF-8, but these guidelines are helpful in
* choosing a name:
*
* http://stackoverflow.com/questions/149932/naming-conventions-for-threads
*
* If a system imposes requirements, SDL will try to munge the string for
* it (truncate, etc), but the original string contents will be available
* from SDL_GetThreadName().
Jun 22, 2011
Jun 22, 2011
143
144
*/
extern DECLSPEC SDL_Thread *SDLCALL
Oct 2, 2011
Oct 2, 2011
145
SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
Jun 22, 2011
Jun 22, 2011
146
147
148
#endif
Oct 2, 2011
Oct 2, 2011
149
150
151
152
153
154
155
156
157
/**
* Get the thread name, as it was specified in SDL_CreateThread().
* This function returns a pointer to a UTF-8 string that names the
* specified thread, or NULL if it doesn't have a name. This is internal
* memory, not to be free()'d by the caller, and remains valid until the
* specified thread is cleaned up by SDL_WaitThread().
*/
extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
Jun 22, 2011
Jun 22, 2011
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* Get the thread identifier for the current thread.
*/
extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
/**
* Get the thread identifier for the specified thread.
*
* Equivalent to SDL_ThreadID() if the specified thread is NULL.
*/
extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
/**
* Set the priority for the current thread
*/
extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
/**
* Wait for a thread to finish.
*
* The return code for the thread function is placed in the area
* pointed to by \c status, if \c status is not NULL.
*/
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_thread_h */
/* vi: set ts=4 sw=4 expandtab: */