This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_systhread.c
157 lines (127 loc) · 3.33 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 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
11
12
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
13
Lesser General Public License for more details.
14
15
16
17
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
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
22
#include "SDL_config.h"
23
24
25
26
/* RISC OS version based on pthreads linux source */
#include "SDL_thread.h"
27
#include "../SDL_systhread.h"
28
29
#if SDL_THREADS_DISABLED
30
31
32
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
33
{
34
35
36
SDL_SetError
("Threads have not been compiled into this version of the library");
return (-1);
37
38
}
39
40
void
SDL_SYS_SetupThread(void)
41
{
42
return;
43
44
}
45
46
Uint32
SDL_ThreadID(void)
47
{
48
return (0);
49
50
}
51
52
void
SDL_SYS_WaitThread(SDL_Thread * thread)
53
{
54
return;
55
56
}
57
58
void
SDL_SYS_KillThread(SDL_Thread * thread)
59
{
60
return;
61
62
63
64
65
66
67
68
}
#else
#include <signal.h>
/* List of signals to mask in the subthreads */
static int sig_list[] = {
69
70
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
SIGVTALRM, SIGPROF, 0
71
72
73
74
75
};
#include <pthread.h>
int riscos_using_threads = 0;
76
Uint32 riscos_main_thread = 0; /* Thread running events */
77
78
79
static void *
RunThread(void *data)
80
{
81
82
83
SDL_RunThread(data);
pthread_exit((void *) 0);
return ((void *) 0); /* Prevent compiler warning */
84
85
}
86
87
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
88
{
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
pthread_attr_t type;
/* Set the thread attributes */
if (pthread_attr_init(&type) != 0) {
SDL_SetError("Couldn't initialize pthread attributes");
return (-1);
}
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
/* Create the thread and go! */
if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
SDL_SetError("Not enough resources to create thread");
return (-1);
}
if (riscos_using_threads == 0) {
riscos_using_threads = 1;
riscos_main_thread = SDL_ThreadID();
}
return (0);
110
111
}
112
113
void
SDL_SYS_SetupThread(void)
114
{
115
116
117
118
119
120
121
122
123
124
int i;
sigset_t mask;
/* Mask asynchronous signals for this thread */
sigemptyset(&mask);
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
pthread_sigmask(SIG_BLOCK, &mask, 0);
125
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
126
127
128
129
130
/* Allow ourselves to be asynchronously cancelled */
{
int oldstate;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
}
131
132
133
#endif
}
134
135
Uint32
SDL_ThreadID(void)
136
{
137
return ((Uint32) pthread_self());
138
139
}
140
141
void
SDL_SYS_WaitThread(SDL_Thread * thread)
142
{
143
pthread_join(thread->handle, 0);
144
145
}
146
147
void
SDL_SYS_KillThread(SDL_Thread * thread)
148
149
{
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
150
pthread_cancel(thread->handle);
151
#else
152
pthread_kill(thread->handle, SIGKILL);
153
154
155
156
#endif
}
#endif
157
/* vi: set ts=4 sw=4 expandtab: */