src/thread/beos/SDL_systhread.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 252 e8157fcb3114
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 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@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* BeOS thread management routines for SDL */
slouken@0
    29
slouken@0
    30
#include <stdio.h>
slouken@0
    31
#include <signal.h>
slouken@0
    32
#include <be/kernel/OS.h>
slouken@0
    33
slouken@0
    34
#include "SDL_error.h"
slouken@0
    35
#include "SDL_mutex.h"
slouken@0
    36
#include "SDL_thread.h"
slouken@0
    37
#include "SDL_thread_c.h"
slouken@0
    38
#include "SDL_systhread.h"
slouken@0
    39
slouken@0
    40
slouken@0
    41
static int sig_list[] = {
slouken@0
    42
	SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
slouken@0
    43
};
slouken@0
    44
slouken@0
    45
void SDL_MaskSignals(sigset_t *omask)
slouken@0
    46
{
slouken@0
    47
	sigset_t mask;
slouken@0
    48
	int i;
slouken@0
    49
slouken@0
    50
	sigemptyset(&mask);
slouken@0
    51
	for ( i=0; sig_list[i]; ++i ) {
slouken@0
    52
		sigaddset(&mask, sig_list[i]);
slouken@0
    53
	}
slouken@0
    54
	sigprocmask(SIG_BLOCK, &mask, omask);
slouken@0
    55
}
slouken@0
    56
void SDL_UnmaskSignals(sigset_t *omask)
slouken@0
    57
{
slouken@0
    58
	sigprocmask(SIG_SETMASK, omask, NULL);
slouken@0
    59
}
slouken@0
    60
slouken@0
    61
static int32 RunThread(void *data)
slouken@0
    62
{
slouken@0
    63
	SDL_RunThread(data);
slouken@0
    64
	return(0);
slouken@0
    65
}
slouken@0
    66
slouken@0
    67
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
slouken@0
    68
{
slouken@0
    69
	/* Create the thread and go! */
slouken@0
    70
	thread->handle=spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args);
slouken@0
    71
	if ( (thread->handle == B_NO_MORE_THREADS) ||
slouken@0
    72
	     (thread->handle == B_NO_MEMORY) ) {
slouken@0
    73
		SDL_SetError("Not enough resources to create thread");
slouken@0
    74
		return(-1);
slouken@0
    75
	}
slouken@0
    76
	resume_thread(thread->handle);
slouken@0
    77
	return(0);
slouken@0
    78
}
slouken@0
    79
slouken@0
    80
void SDL_SYS_SetupThread(void)
slouken@0
    81
{
slouken@0
    82
	/* Mask asynchronous signals for this thread */
slouken@0
    83
	SDL_MaskSignals(NULL);
slouken@0
    84
}
slouken@0
    85
slouken@0
    86
Uint32 SDL_ThreadID(void)
slouken@0
    87
{
slouken@0
    88
	return((Uint32)find_thread(NULL));
slouken@0
    89
}
slouken@0
    90
slouken@0
    91
void SDL_SYS_WaitThread(SDL_Thread *thread)
slouken@0
    92
{
slouken@0
    93
	status_t the_status;
slouken@0
    94
slouken@0
    95
	wait_for_thread(thread->handle, &the_status);
slouken@0
    96
}
slouken@0
    97
slouken@0
    98
void SDL_SYS_KillThread(SDL_Thread *thread)
slouken@0
    99
{
slouken@0
   100
	kill_thread(thread->handle);
slouken@0
   101
}