include/SDL_thread.h
changeset 1190 173c063d4f55
parent 930 02759105b989
child 1312 c9b51268668f
     1.1 --- a/include/SDL_thread.h	Wed Nov 23 07:23:48 2005 +0000
     1.2 +++ b/include/SDL_thread.h	Wed Nov 23 07:29:56 2005 +0000
     1.3 @@ -50,7 +50,50 @@
     1.4  typedef struct SDL_Thread SDL_Thread;
     1.5  
     1.6  /* Create a thread */
     1.7 +#ifdef __OS2__
     1.8 +/*
     1.9 +   We compile SDL into a DLL on OS/2. This means, that it's the DLL which
    1.10 +   creates a new thread for the calling process with the SDL_CreateThread()
    1.11 +   API. There is a problem with this, that only the RTL of the SDL.DLL will
    1.12 +   be initialized for those threads, and not the RTL of the calling application!
    1.13 +   To solve this, we make a little hack here.
    1.14 +   We'll always use the caller's _beginthread() and _endthread() APIs to
    1.15 +   start a new thread. This way, it it's the SDL.DLL which uses this API,
    1.16 +   then the RTL of SDL.DLL will be used to create the new thread, and if it's
    1.17 +   the application, then the RTL of the application will be used.
    1.18 +   So, in short:
    1.19 +   Always use the _beginthread() and _endthread() of the calling runtime library!
    1.20 +*/
    1.21 +
    1.22 +#ifdef __WATCOMC__
    1.23 +#include <process.h> // This has _beginthread() and _endthread() defined!
    1.24 +#endif
    1.25 +#ifdef __EMX__
    1.26 +#include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used!
    1.27 +#endif
    1.28 +
    1.29 +typedef Uint32 SDLCALL (*pfnSDL_CurrentBeginThread)(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam);
    1.30 +typedef void   SDLCALL (*pfnSDL_CurrentEndThread)(void);
    1.31 +
    1.32 +extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread_Core(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
    1.33 +
    1.34 +// Disable warnings about unreferenced symbol!
    1.35 +#pragma disable_message (202)
    1.36 +static Uint32 SDLCALL SDL_CurrentBeginThread(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam)
    1.37 +{
    1.38 +  return _beginthread(pfnThreadFn, NULL, uiStackSize, pParam);
    1.39 +}
    1.40 +
    1.41 +static void   SDLCALL SDL_CurrentEndThread(void)
    1.42 +{
    1.43 +  _endthread();
    1.44 +}
    1.45 +
    1.46 +#define SDL_CreateThread(fn, data) SDL_CreateThread_Core(fn, data, SDL_CurrentBeginThread, SDL_CurrentEndThread)
    1.47 +
    1.48 +#else
    1.49  extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);
    1.50 +#endif
    1.51  
    1.52  /* Get the 32-bit thread identifier for the current thread */
    1.53  extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);