2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2006-02-01 06:32:25 +00:00
|
|
|
Copyright (C) 1997-2006 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library 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
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:37:47 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SDL_thread_h
|
|
|
|
#define _SDL_thread_h
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/**
|
|
|
|
* \file SDL_thread.h
|
|
|
|
*
|
|
|
|
* Header for the SDL thread management routines
|
|
|
|
*/
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-10 03:19:02 +00:00
|
|
|
#include "SDL_stdinc.h"
|
2006-02-10 06:48:43 +00:00
|
|
|
#include "SDL_error.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Thread synchronization primitives */
|
|
|
|
#include "SDL_mutex.h"
|
|
|
|
|
|
|
|
#include "begin_code.h"
|
|
|
|
/* Set up for C function definitions, even when using C++ */
|
|
|
|
#ifdef __cplusplus
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-OFF* */
|
2001-04-26 16:45:43 +00:00
|
|
|
extern "C" {
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-ON* */
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The SDL thread structure, defined in SDL_thread.c */
|
|
|
|
struct SDL_Thread;
|
|
|
|
typedef struct SDL_Thread SDL_Thread;
|
|
|
|
|
|
|
|
/* Create a thread */
|
2006-03-06 07:42:36 +00:00
|
|
|
#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)
|
2005-11-23 07:29:56 +00:00
|
|
|
/*
|
|
|
|
We compile SDL into a DLL on OS/2. 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
|
2006-02-06 08:28:51 +00:00
|
|
|
start a new thread. This way, if it's the SDL.DLL which uses this API,
|
2005-11-23 07:29:56 +00:00
|
|
|
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!
|
|
|
|
*/
|
2006-03-06 07:42:36 +00:00
|
|
|
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
2006-03-04 08:24:35 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2006-07-10 21:04:37 +00:00
|
|
|
#include <process.h> /* This has _beginthread() and _endthread() defined! */
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#ifdef __OS2__
|
2006-07-10 21:04:37 +00:00
|
|
|
typedef int (*pfnSDL_CurrentBeginThread) (void (*func) (void *), void *,
|
|
|
|
unsigned, void *arg);
|
|
|
|
typedef void (*pfnSDL_CurrentEndThread) (void);
|
2006-03-06 06:00:45 +00:00
|
|
|
#elif __GNUC__
|
2006-07-10 21:04:37 +00:00
|
|
|
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
|
|
|
unsigned
|
|
|
|
(__stdcall *
|
|
|
|
func) (void *),
|
|
|
|
void *arg,
|
|
|
|
unsigned,
|
|
|
|
unsigned
|
|
|
|
*threadID);
|
|
|
|
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
2006-02-06 08:28:51 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
|
|
|
unsigned (__stdcall *
|
|
|
|
func) (void
|
|
|
|
*),
|
|
|
|
void *arg, unsigned,
|
|
|
|
unsigned *threadID);
|
|
|
|
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
2006-02-06 08:28:51 +00:00
|
|
|
#endif
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-10-28 16:48:03 +00:00
|
|
|
extern DECLSPEC SDL_Thread *SDLCALL
|
|
|
|
SDL_CreateThread(int (SDLCALL * f) (void *), void *data,
|
|
|
|
pfnSDL_CurrentBeginThread pfnBeginThread,
|
|
|
|
pfnSDL_CurrentEndThread pfnEndThread);
|
2005-11-23 07:29:56 +00:00
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#ifdef __OS2__
|
|
|
|
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
|
|
|
|
#elif defined(_WIN32_WCE)
|
|
|
|
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
|
|
|
|
#else
|
|
|
|
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
|
|
|
|
#endif
|
2005-11-23 07:29:56 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
extern DECLSPEC SDL_Thread *SDLCALL
|
|
|
|
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data);
|
2005-11-23 07:29:56 +00:00
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Get the 32-bit thread identifier for the current thread */
|
2002-04-11 14:35:16 +00:00
|
|
|
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Get the 32-bit thread identifier for the specified thread,
|
|
|
|
equivalent to SDL_ThreadID() if the specified thread is NULL.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread * thread);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Wait for a thread to finish.
|
|
|
|
The return code for the thread function is placed in the area
|
|
|
|
pointed to by 'status', if 'status' is not NULL.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Forcefully kill a thread without worrying about its state */
|
2006-07-10 21:04:37 +00:00
|
|
|
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread * thread);
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Ends C function definitions when using C++ */
|
|
|
|
#ifdef __cplusplus
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-OFF* */
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-ON* */
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
#include "close_code.h"
|
|
|
|
|
|
|
|
#endif /* _SDL_thread_h */
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|