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