Mercurial > sdl-ios-xcode
diff include/SDL_thread.h @ 1190:173c063d4f55
OS/2 port!
This was mostly, if not entirely, written by "Doodle" and "Caetano":
doodle@scenergy.dfmk.hu
daniel@caetano.eng.br
--ryan.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 23 Nov 2005 07:29:56 +0000 |
parents | 02759105b989 |
children | c9b51268668f |
line wrap: on
line diff
--- a/include/SDL_thread.h Wed Nov 23 07:23:48 2005 +0000 +++ b/include/SDL_thread.h Wed Nov 23 07:29:56 2005 +0000 @@ -50,7 +50,50 @@ typedef struct SDL_Thread SDL_Thread; /* Create a thread */ +#ifdef __OS2__ +/* + 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 + start a new thread. This way, it 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! +*/ + +#ifdef __WATCOMC__ +#include <process.h> // This has _beginthread() and _endthread() defined! +#endif +#ifdef __EMX__ +#include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used! +#endif + +typedef Uint32 SDLCALL (*pfnSDL_CurrentBeginThread)(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam); +typedef void SDLCALL (*pfnSDL_CurrentEndThread)(void); + +extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread_Core(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); + +// Disable warnings about unreferenced symbol! +#pragma disable_message (202) +static Uint32 SDLCALL SDL_CurrentBeginThread(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam) +{ + return _beginthread(pfnThreadFn, NULL, uiStackSize, pParam); +} + +static void SDLCALL SDL_CurrentEndThread(void) +{ + _endthread(); +} + +#define SDL_CreateThread(fn, data) SDL_CreateThread_Core(fn, data, SDL_CurrentBeginThread, SDL_CurrentEndThread) + +#else extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data); +#endif /* Get the 32-bit thread identifier for the current thread */ extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);