comparison src/thread/os2/SDL_systhread.c @ 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
children c9b51268668f
comparison
equal deleted inserted replaced
1189:c96b326b90ba 1190:173c063d4f55
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 /* OS/2 thread management routines for SDL */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <process.h>
33 #define INCL_DOSERRORS
34 #define INCL_DOSPROCESS
35 #include <os2.h>
36
37 #include "SDL_error.h"
38 #include "SDL_thread.h"
39 #include "SDL_systhread.h"
40
41 typedef struct ThreadStartParms
42 {
43 void *args;
44 pfnSDL_CurrentEndThread pfnCurrentEndThread;
45 } tThreadStartParms, *pThreadStartParms;
46
47 static void threadfunc(void *pparm)
48 {
49 pThreadStartParms pThreadParms = pparm;
50 pfnSDL_CurrentEndThread pfnCurrentEndThread = NULL;
51
52 // Call the thread function!
53 SDL_RunThread(pThreadParms->args);
54
55 // Get the current endthread we have to use!
56 if (pThreadParms)
57 {
58 pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread;
59 free(pThreadParms);
60 }
61 // Call endthread!
62 if (pfnCurrentEndThread)
63 (*pfnCurrentEndThread)();
64 }
65
66 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
67 {
68 pThreadStartParms pThreadParms = malloc(sizeof(tThreadStartParms));
69 if (!pThreadParms)
70 {
71 SDL_SetError("Not enough memory to create thread");
72 return(-1);
73 }
74
75 // Save the function which we will have to call to clear the RTL of calling app!
76 pThreadParms->pfnCurrentEndThread = pfnEndThread;
77 // Also save the real parameters we have to pass to thread function
78 pThreadParms->args = args;
79 // Start the thread using the runtime library of calling app!
80 thread->threadid = thread->handle = (*pfnBeginThread)(threadfunc, 512*1024, pThreadParms);
81 if (thread->threadid<=0)
82 {
83 SDL_SetError("Not enough resources to create thread");
84 return(-1);
85 }
86 return(0);
87 }
88
89 void SDL_SYS_SetupThread(void)
90 {
91 return;
92 }
93
94 DECLSPEC Uint32 SDLCALL SDL_ThreadID(void)
95 {
96 PTIB tib;
97 DosGetInfoBlocks(&tib, NULL);
98 return((Uint32) (tib->tib_ptib2->tib2_ultid));
99 }
100
101 void SDL_SYS_WaitThread(SDL_Thread *thread)
102 {
103 TID tid = thread->handle;
104 DosWaitThread(&tid, DCWW_WAIT);
105 }
106
107 /* WARNING: This function is really a last resort.
108 * Threads should be signaled and then exit by themselves.
109 * TerminateThread() doesn't perform stack and DLL cleanup.
110 */
111 void SDL_SYS_KillThread(SDL_Thread *thread)
112 {
113 DosKillThread(thread->handle);
114 }