Mercurial > sdl-ios-xcode
comparison src/thread/riscos/SDL_systhread.c @ 955:d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
From: "alan buckley"
Subject: Modification for RISC OS version of SDL
Ive attached a zip file with the changes to this email, it contains the
following:
The file sdldiff.txt is the output from cvs diff u. .
The directory thread/riscos contains all the new files to support threading.
Readme.riscos is a new readme file to add.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 17 Sep 2004 13:20:10 +0000 |
parents | |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
954:3acd16ea0180 | 955:d74fbf56f2f6 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2004 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 /* RISC OS version based on pthreads linux source */ | |
24 | |
25 #ifdef SAVE_RCSID | |
26 static char rcsid = | |
27 "@(#) $Id$"; | |
28 #endif | |
29 | |
30 #include "SDL_error.h" | |
31 #include "SDL_thread.h" | |
32 #include "SDL_systhread.h" | |
33 | |
34 #ifdef DISABLE_THREADS | |
35 | |
36 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | |
37 { | |
38 SDL_SetError("Threads have not been compiled into this version of the library"); | |
39 return(-1); | |
40 } | |
41 | |
42 void SDL_SYS_SetupThread(void) | |
43 { | |
44 return; | |
45 } | |
46 | |
47 Uint32 SDL_ThreadID(void) | |
48 { | |
49 return(0); | |
50 } | |
51 | |
52 void SDL_SYS_WaitThread(SDL_Thread *thread) | |
53 { | |
54 return; | |
55 } | |
56 | |
57 void SDL_SYS_KillThread(SDL_Thread *thread) | |
58 { | |
59 return; | |
60 } | |
61 | |
62 #else | |
63 | |
64 #include <signal.h> | |
65 | |
66 /* List of signals to mask in the subthreads */ | |
67 static int sig_list[] = { | |
68 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, | |
69 SIGVTALRM, SIGPROF, 0 | |
70 }; | |
71 | |
72 #include <pthread.h> | |
73 | |
74 int riscos_using_threads = 0; | |
75 Uint32 riscos_main_thread = 0; /* Thread running events */ | |
76 | |
77 static void *RunThread(void *data) | |
78 { | |
79 SDL_RunThread(data); | |
80 pthread_exit((void*)0); | |
81 return((void *)0); /* Prevent compiler warning */ | |
82 } | |
83 | |
84 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | |
85 { | |
86 pthread_attr_t type; | |
87 | |
88 /* Set the thread attributes */ | |
89 if ( pthread_attr_init(&type) != 0 ) { | |
90 SDL_SetError("Couldn't initialize pthread attributes"); | |
91 return(-1); | |
92 } | |
93 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); | |
94 | |
95 /* Create the thread and go! */ | |
96 if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) { | |
97 SDL_SetError("Not enough resources to create thread"); | |
98 return(-1); | |
99 } | |
100 | |
101 if (riscos_using_threads == 0) | |
102 { | |
103 riscos_using_threads = 1; | |
104 riscos_main_thread = SDL_ThreadID(); | |
105 } | |
106 | |
107 return(0); | |
108 } | |
109 | |
110 void SDL_SYS_SetupThread(void) | |
111 { | |
112 int i; | |
113 sigset_t mask; | |
114 | |
115 /* Mask asynchronous signals for this thread */ | |
116 sigemptyset(&mask); | |
117 for ( i=0; sig_list[i]; ++i ) { | |
118 sigaddset(&mask, sig_list[i]); | |
119 } | |
120 pthread_sigmask(SIG_BLOCK, &mask, 0); | |
121 | |
122 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | |
123 /* Allow ourselves to be asynchronously cancelled */ | |
124 { int oldstate; | |
125 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); | |
126 } | |
127 #endif | |
128 } | |
129 | |
130 Uint32 SDL_ThreadID(void) | |
131 { | |
132 return((Uint32)pthread_self()); | |
133 } | |
134 | |
135 void SDL_SYS_WaitThread(SDL_Thread *thread) | |
136 { | |
137 pthread_join(thread->handle, 0); | |
138 } | |
139 | |
140 void SDL_SYS_KillThread(SDL_Thread *thread) | |
141 { | |
142 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | |
143 pthread_cancel(thread->handle); | |
144 #else | |
145 pthread_kill(thread->handle, SIGKILL); | |
146 #endif | |
147 } | |
148 | |
149 #endif |