2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2011-02-11 22:37:15 -08:00
|
|
|
Copyright (C) 1997-2011 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* BeOS thread management routines for SDL */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <be/kernel/OS.h>
|
|
|
|
|
|
|
|
#include "SDL_mutex.h"
|
|
|
|
#include "SDL_thread.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../SDL_thread_c.h"
|
|
|
|
#include "../SDL_systhread.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int sig_list[] = {
|
2006-07-10 21:04:37 +00:00
|
|
|
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_MaskSignals(sigset_t * omask)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
sigset_t mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sigemptyset(&mask);
|
|
|
|
for (i = 0; sig_list[i]; ++i) {
|
|
|
|
sigaddset(&mask, sig_list[i]);
|
|
|
|
}
|
|
|
|
sigprocmask(SIG_BLOCK, &mask, omask);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SDL_UnmaskSignals(sigset_t * omask)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
sigprocmask(SIG_SETMASK, omask, NULL);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static int32
|
|
|
|
RunThread(void *data)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_RunThread(data);
|
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Create the thread and go! */
|
|
|
|
thread->handle = spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args);
|
|
|
|
if ((thread->handle == B_NO_MORE_THREADS) ||
|
|
|
|
(thread->handle == B_NO_MEMORY)) {
|
|
|
|
SDL_SetError("Not enough resources to create thread");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
resume_thread(thread->handle);
|
|
|
|
return (0);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SYS_SetupThread(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Mask asynchronous signals for this thread */
|
|
|
|
SDL_MaskSignals(NULL);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 04:48:11 +00:00
|
|
|
SDL_threadID
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_ThreadID(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2009-12-16 04:48:11 +00:00
|
|
|
return ((SDL_threadID) find_thread(NULL));
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 10:47:49 -07:00
|
|
|
int
|
|
|
|
SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority)
|
|
|
|
{
|
|
|
|
int32 new_priority = B_NORMAL_PRIORITY;
|
|
|
|
|
|
|
|
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
|
|
|
new_priority = B_LOW_PRIORITY;
|
|
|
|
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
|
|
|
new_priority = B_URGENT_DISPLAY_PRIORITY;
|
|
|
|
}
|
|
|
|
set_thread_priority(thread->handle, new_priority);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_SYS_WaitThread(SDL_Thread * thread)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
status_t the_status;
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
wait_for_thread(thread->handle, &the_status);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|