src/thread/amigaos/SDL_systhread.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 16 Feb 2006 10:11:48 +0000
changeset 1361 19418e4422cb
parent 1358 c71e05b4dc2e
child 1402 d910939febfa
permissions -rw-r--r--
New configure-based build system. Still work in progress, but much improved
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 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     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /* BeOS thread management routines for SDL */
    24 
    25 #include "SDL_mutex.h"
    26 #include "SDL_thread.h"
    27 #include "../SDL_thread_c.h"
    28 #include "../SDL_systhread.h"
    29 #include "mydebug.h"
    30 
    31 typedef struct {
    32 	int (*func)(void *);
    33 	void *data;
    34 	SDL_Thread *info;
    35 	struct Task *wait;
    36 } thread_args;
    37 
    38 #ifndef MORPHOS
    39 
    40 #if defined(__SASC) && !defined(__PPC__) 
    41 __saveds __asm Uint32 RunThread(register __a0 char *args )
    42 #elif defined(__PPC__)
    43 Uint32 RunThread(char *args)
    44 #else
    45 Uint32 __saveds RunThread(char *args __asm("a0") )
    46 #endif
    47 {
    48 	#ifdef STORMC4_WOS
    49 	thread_args *data=(thread_args *)args;
    50 	#else
    51 	thread_args *data=(thread_args *)atol(args);
    52 	#endif
    53 
    54 	struct Task *Father;
    55 
    56 	D(bug("Received data: %lx\n",data));
    57 	Father=data->wait;
    58 
    59 	SDL_RunThread(data);
    60 
    61 	Signal(Father,SIGBREAKF_CTRL_F);
    62 	D(bug("Thread with data %lx ended\n",data));
    63 	return(0);
    64 }
    65 
    66 #else
    67 
    68 #include <emul/emulinterface.h>
    69 
    70 Uint32 RunTheThread(void)
    71 {
    72 	thread_args *data=(thread_args *)atol((char *)REG_A0);
    73 	struct Task *Father;
    74 
    75 	D(bug("Received data: %lx\n",data));
    76 	Father=data->wait;
    77 
    78 	SDL_RunThread(data);
    79 
    80 	Signal(Father,SIGBREAKF_CTRL_F);
    81 	D(bug("Thread with data %lx ended\n",data));
    82 	return(0);
    83 }
    84 
    85 struct EmulLibEntry RunThreadStruct=
    86 {
    87 	TRAP_LIB,
    88 	0,
    89 	(ULONG)RunTheThread
    90 };
    91 
    92 void *RunThread=&RunThreadStruct;
    93 #endif
    94 
    95 
    96 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
    97 {
    98 	/* Create the thread and go! */
    99 	char buffer[20];
   100 
   101 	D(bug("Sending %lx to the new thread...\n",args));
   102 
   103 	if(args)
   104 		SDL_snprintf(buffer, SDL_arraysize(buffer),"%ld",args);
   105 
   106 	#ifdef STORMC4_WOS
   107 	thread->handle=CreateTaskPPCTags(TASKATTR_CODE,	RunThread,
   108 					TASKATTR_NAME,	"SDL subtask",
   109 					TASKATTR_STACKSIZE, 100000,
   110 					(args ? TASKATTR_R3 : TAG_IGNORE), args,
   111 					TASKATTR_INHERITR2, TRUE,
   112 					TAG_DONE);
   113 	#else
   114 	thread->handle=(struct Task *)CreateNewProcTags(NP_Output,Output(),
   115 					NP_Name,(ULONG)"SDL subtask",
   116 					NP_CloseOutput, FALSE,
   117 					NP_StackSize,20000,
   118 					NP_Entry,(ULONG)RunThread,
   119 					args ? NP_Arguments : TAG_IGNORE,(ULONG)buffer,
   120 					TAG_DONE);
   121 	#endif
   122 
   123 	if(!thread->handle)
   124 	{
   125 		SDL_SetError("Not enough resources to create thread");
   126 		return(-1);
   127 	}
   128 
   129 	return(0);
   130 }
   131 
   132 void SDL_SYS_SetupThread(void)
   133 {
   134 }
   135 
   136 Uint32 SDL_ThreadID(void)
   137 {
   138 	return((Uint32)FindTask(NULL));
   139 }
   140 
   141 void SDL_SYS_WaitThread(SDL_Thread *thread)
   142 {
   143 	SetSignal(0L,SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C);
   144 	Wait(SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C);
   145 }
   146 
   147 void SDL_SYS_KillThread(SDL_Thread *thread)
   148 {
   149 	Signal((struct Task *)thread->handle,SIGBREAKF_CTRL_C);
   150 }