2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
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.
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.
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
28 /* BeOS thread management routines for SDL */
30 #include "SDL_error.h"
31 #include "SDL_mutex.h"
32 #include "SDL_thread.h"
33 #include "SDL_thread_c.h"
34 #include "SDL_systhread.h"
53 #if defined(__SASC) && !defined(__PPC__)
54 __saveds __asm Uint32
RunThread(register __a0
char *args
)
55 #elif defined(__PPC__) || defined(__AROS__)
56 Uint32
RunThread(char *args
)
57 #elif !defined(SHARED_LIB)
58 Uint32 __saveds
RunThread(char *args
__asm("a0") )
60 Uint32
RunThread(char *args
__asm("a0") )
67 thread_args
*data
=(thread_args
*)args
;
69 thread_args
*data
=(thread_args
*)atol(args
);
72 #else /* SHARED_LIB */
74 register APTR base
__asm("a6");
78 while(*args
>= '0' && *args
<= '9')
79 temp
= (temp
* 10) + (*args
++ - '0');
81 data
=(thread_args
*)temp
;
86 D(bug("Library base: %lx\n",base
));
89 D(bug("Received data: %lx, father:%lx\n", data
, data
->wait
));
93 D(bug("Thread exited, signaling father (%lx)...\n",Father
));
94 Signal(Father
,SIGBREAKF_CTRL_F
);
95 D(bug("Thread with data %lx ended\n",data
));
99 #else /* Morphos code */
101 #include <emul/emulinterface.h>
103 Uint32
RunTheThread(void)
105 thread_args
*data
=(thread_args
*)atol((char *)REG_A0
);
108 D(bug("Received data: %lx\n",data
));
113 Signal(Father
,SIGBREAKF_CTRL_F
);
114 D(bug("Thread with data %lx ended\n",data
));
118 struct EmulLibEntry RunThreadStruct
=
125 void *RunThread
=&RunThreadStruct
;
129 int SDL_SYS_CreateThread(SDL_Thread
*thread
, void *args
)
131 /* Create the thread and go! */
135 struct TagItem tags
[6];
139 extern void *myLibPtr
;
141 ((thread_args
*)args
)->LibBase
= myLibPtr
;
142 D(bug("CreateThread: librarybase %lx\n",myLibPtr
));
145 D(bug("Sending %lx to the new thread...\n",args
));
147 sprintf(buffer
,"%ld",args
);
151 tags
[0].ti_Tag
= TASKATTR_CODE
; tags
[0].ti_Data
= (ULONG
)RunThread
;
152 tags
[1].ti_Tag
= TASKATTR_NAME
; tags
[1].ti_Data
= (ULONG
)"SDL subtask";
153 tags
[2].ti_Tag
= TASKATTR_STACKSIZE
; tags
[2].ti_Data
= 100000;
154 tags
[3].ti_Tag
= (args
? TASKATTR_R3
: TAG_IGNORE
); tags
[3].ti_Data
= (ULONG
)args
;
155 tags
[4].ti_Tag
= TASKATTR_INHERITR2
; tags
[4].ti_Data
= TRUE
;
156 tags
[5].ti_Tag
= TAG_DONE
; tags
[5].ti_Data
= 0;
158 thread
->handle
=CreateTaskPPC(tags
);
160 thread
->handle
=(struct Task
*)CreateNewProcTags(
163 NP_Name
, (ULONG
)"SDL subtask",
164 NP_CloseOutput
, FALSE
,
165 NP_CloseInput
, FALSE
,
167 NP_Entry
, (ULONG
)RunThread
,
168 NP_Arguments
, (ULONG
)buffer
,
174 SDL_SetError("Not enough resources to create thread");
181 void SDL_SYS_SetupThread(void)
185 Uint32
SDL_ThreadID(void)
187 return((Uint32
)FindTask(NULL
));
190 void SDL_SYS_WaitThread(SDL_Thread
*thread
)
192 SetSignal(0L,SIGBREAKF_CTRL_F
|SIGBREAKF_CTRL_C
);
193 Wait(SIGBREAKF_CTRL_F
|SIGBREAKF_CTRL_C
);
196 void SDL_SYS_KillThread(SDL_Thread
*thread
)
198 Signal((struct Task
*)thread
->handle
,SIGBREAKF_CTRL_C
);