comparison include/SDL_thread.h @ 1330:450721ad5436

It's now possible to build SDL without any C runtime at all on Windows, using Visual C++ 2005
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Feb 2006 08:28:51 +0000
parents c9b51268668f
children 67114343400d
comparison
equal deleted inserted replaced
1329:bc67bbf87818 1330:450721ad5436
43 /* The SDL thread structure, defined in SDL_thread.c */ 43 /* The SDL thread structure, defined in SDL_thread.c */
44 struct SDL_Thread; 44 struct SDL_Thread;
45 typedef struct SDL_Thread SDL_Thread; 45 typedef struct SDL_Thread SDL_Thread;
46 46
47 /* Create a thread */ 47 /* Create a thread */
48 #ifdef __OS2__ 48 #if defined(_WIN32) || defined(__OS2__)
49 /* 49 /*
50 We compile SDL into a DLL on OS/2. This means, that it's the DLL which 50 We compile SDL into a DLL on OS/2. This means, that it's the DLL which
51 creates a new thread for the calling process with the SDL_CreateThread() 51 creates a new thread for the calling process with the SDL_CreateThread()
52 API. There is a problem with this, that only the RTL of the SDL.DLL will 52 API. There is a problem with this, that only the RTL of the SDL.DLL will
53 be initialized for those threads, and not the RTL of the calling application! 53 be initialized for those threads, and not the RTL of the calling application!
54 To solve this, we make a little hack here. 54 To solve this, we make a little hack here.
55 We'll always use the caller's _beginthread() and _endthread() APIs to 55 We'll always use the caller's _beginthread() and _endthread() APIs to
56 start a new thread. This way, it it's the SDL.DLL which uses this API, 56 start a new thread. This way, if it's the SDL.DLL which uses this API,
57 then the RTL of SDL.DLL will be used to create the new thread, and if it's 57 then the RTL of SDL.DLL will be used to create the new thread, and if it's
58 the application, then the RTL of the application will be used. 58 the application, then the RTL of the application will be used.
59 So, in short: 59 So, in short:
60 Always use the _beginthread() and _endthread() of the calling runtime library! 60 Always use the _beginthread() and _endthread() of the calling runtime library!
61 */ 61 */
62
63 #ifdef __WATCOMC__
64 #include <process.h> // This has _beginthread() and _endthread() defined! 62 #include <process.h> // This has _beginthread() and _endthread() defined!
65 #endif
66 #ifdef __EMX__ 63 #ifdef __EMX__
67 #include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used! 64 #include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used!
68 #endif 65 #endif
69 66
70 typedef Uint32 SDLCALL (*pfnSDL_CurrentBeginThread)(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam); 67 #ifdef __OS2__
71 typedef void SDLCALL (*pfnSDL_CurrentEndThread)(void); 68 typedef int (__cdecl *pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg);
69 typedef void (__cdecl *pfnSDL_CurrentEndThread)(void);
70 #else
71 #ifdef __GNUC__
72 #include <stdint.h>
73 #endif
74 typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
75 unsigned (__stdcall *func)(void *), void *arg,
76 unsigned, unsigned *threadID);
77 typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
78 #endif
72 79
73 extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread_Core(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); 80 extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
74 81
75 // Disable warnings about unreferenced symbol! 82 #ifdef __OS2__
76 #pragma disable_message (202) 83 #define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
77 static Uint32 SDLCALL SDL_CurrentBeginThread(void (*pfnThreadFn)(void *), Uint32 uiStackSize, void *pParam) 84 #elif defined(_WIN32_WCE)
78 { 85 #define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
79 return _beginthread(pfnThreadFn, NULL, uiStackSize, pParam); 86 #else
80 } 87 #define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
81 88 #endif
82 static void SDLCALL SDL_CurrentEndThread(void)
83 {
84 _endthread();
85 }
86
87 #define SDL_CreateThread(fn, data) SDL_CreateThread_Core(fn, data, SDL_CurrentBeginThread, SDL_CurrentEndThread)
88
89 #else 89 #else
90 extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data); 90 extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);
91 #endif 91 #endif
92 92
93 /* Get the 32-bit thread identifier for the current thread */ 93 /* Get the 32-bit thread identifier for the current thread */