2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
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.
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
22 #include "SDL_config.h"
24 /* RISC OS version based on pthreads linux source */
26 #include "SDL_thread.h"
27 #include "../SDL_systhread.h"
29 #if SDL_THREADS_DISABLED
31 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
33 SDL_SetError("Threads have not been compiled into this version of the library");
37 void SDL_SYS_SetupThread(void)
42 Uint32 SDL_ThreadID(void)
47 void SDL_SYS_WaitThread(SDL_Thread *thread)
52 void SDL_SYS_KillThread(SDL_Thread *thread)
61 /* List of signals to mask in the subthreads */
62 static int sig_list[] = {
63 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
69 int riscos_using_threads = 0;
70 Uint32 riscos_main_thread = 0; /* Thread running events */
72 static void *RunThread(void *data)
75 pthread_exit((void*)0);
76 return((void *)0); /* Prevent compiler warning */
79 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
83 /* Set the thread attributes */
84 if ( pthread_attr_init(&type) != 0 ) {
85 SDL_SetError("Couldn't initialize pthread attributes");
88 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
90 /* Create the thread and go! */
91 if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) {
92 SDL_SetError("Not enough resources to create thread");
96 if (riscos_using_threads == 0)
98 riscos_using_threads = 1;
99 riscos_main_thread = SDL_ThreadID();
105 void SDL_SYS_SetupThread(void)
110 /* Mask asynchronous signals for this thread */
112 for ( i=0; sig_list[i]; ++i ) {
113 sigaddset(&mask, sig_list[i]);
115 pthread_sigmask(SIG_BLOCK, &mask, 0);
117 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
118 /* Allow ourselves to be asynchronously cancelled */
120 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
125 Uint32 SDL_ThreadID(void)
127 return((Uint32)pthread_self());
130 void SDL_SYS_WaitThread(SDL_Thread *thread)
132 pthread_join(thread->handle, 0);
135 void SDL_SYS_KillThread(SDL_Thread *thread)
137 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
138 pthread_cancel(thread->handle);
140 pthread_kill(thread->handle, SIGKILL);