diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-21 15:18:31 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 21:01:26 -0500 |
commit | a855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch) | |
tree | 8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/sdl/src/thread/riscos/SDL_systhread.c | |
parent | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff) | |
download | rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip |
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL
for Rockbox.
Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/sdl/src/thread/riscos/SDL_systhread.c')
-rw-r--r-- | apps/plugins/sdl/src/thread/riscos/SDL_systhread.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/thread/riscos/SDL_systhread.c b/apps/plugins/sdl/src/thread/riscos/SDL_systhread.c new file mode 100644 index 0000000000..38fc333ae8 --- /dev/null +++ b/apps/plugins/sdl/src/thread/riscos/SDL_systhread.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
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. | ||
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 | Lesser General Public License for more details. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* RISC OS version based on pthreads linux source */ | ||
25 | |||
26 | #include "SDL_thread.h" | ||
27 | #include "../SDL_systhread.h" | ||
28 | |||
29 | #if SDL_THREADS_DISABLED | ||
30 | |||
31 | int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | ||
32 | { | ||
33 | SDL_SetError("Threads have not been compiled into this version of the library"); | ||
34 | return(-1); | ||
35 | } | ||
36 | |||
37 | void SDL_SYS_SetupThread(void) | ||
38 | { | ||
39 | return; | ||
40 | } | ||
41 | |||
42 | Uint32 SDL_ThreadID(void) | ||
43 | { | ||
44 | return(0); | ||
45 | } | ||
46 | |||
47 | void SDL_SYS_WaitThread(SDL_Thread *thread) | ||
48 | { | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | void SDL_SYS_KillThread(SDL_Thread *thread) | ||
53 | { | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | #else | ||
58 | |||
59 | #include <signal.h> | ||
60 | |||
61 | /* List of signals to mask in the subthreads */ | ||
62 | static int sig_list[] = { | ||
63 | SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, | ||
64 | SIGVTALRM, SIGPROF, 0 | ||
65 | }; | ||
66 | |||
67 | #include <pthread.h> | ||
68 | |||
69 | int riscos_using_threads = 0; | ||
70 | Uint32 riscos_main_thread = 0; /* Thread running events */ | ||
71 | |||
72 | static void *RunThread(void *data) | ||
73 | { | ||
74 | SDL_RunThread(data); | ||
75 | pthread_exit((void*)0); | ||
76 | return((void *)0); /* Prevent compiler warning */ | ||
77 | } | ||
78 | |||
79 | int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | ||
80 | { | ||
81 | pthread_attr_t type; | ||
82 | |||
83 | /* Set the thread attributes */ | ||
84 | if ( pthread_attr_init(&type) != 0 ) { | ||
85 | SDL_SetError("Couldn't initialize pthread attributes"); | ||
86 | return(-1); | ||
87 | } | ||
88 | pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); | ||
89 | |||
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"); | ||
93 | return(-1); | ||
94 | } | ||
95 | |||
96 | if (riscos_using_threads == 0) | ||
97 | { | ||
98 | riscos_using_threads = 1; | ||
99 | riscos_main_thread = SDL_ThreadID(); | ||
100 | } | ||
101 | |||
102 | return(0); | ||
103 | } | ||
104 | |||
105 | void SDL_SYS_SetupThread(void) | ||
106 | { | ||
107 | int i; | ||
108 | sigset_t mask; | ||
109 | |||
110 | /* Mask asynchronous signals for this thread */ | ||
111 | sigemptyset(&mask); | ||
112 | for ( i=0; sig_list[i]; ++i ) { | ||
113 | sigaddset(&mask, sig_list[i]); | ||
114 | } | ||
115 | pthread_sigmask(SIG_BLOCK, &mask, 0); | ||
116 | |||
117 | #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | ||
118 | /* Allow ourselves to be asynchronously cancelled */ | ||
119 | { int oldstate; | ||
120 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); | ||
121 | } | ||
122 | #endif | ||
123 | } | ||
124 | |||
125 | Uint32 SDL_ThreadID(void) | ||
126 | { | ||
127 | return((Uint32)pthread_self()); | ||
128 | } | ||
129 | |||
130 | void SDL_SYS_WaitThread(SDL_Thread *thread) | ||
131 | { | ||
132 | pthread_join(thread->handle, 0); | ||
133 | } | ||
134 | |||
135 | void SDL_SYS_KillThread(SDL_Thread *thread) | ||
136 | { | ||
137 | #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | ||
138 | pthread_cancel(thread->handle); | ||
139 | #else | ||
140 | pthread_kill(thread->handle, SIGKILL); | ||
141 | #endif | ||
142 | } | ||
143 | |||
144 | #endif | ||