Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
157 lines (127 loc) · 3.33 KB

SDL_systhread.c

File metadata and controls

157 lines (127 loc) · 3.33 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
14
Feb 1, 2006
Feb 1, 2006
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
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
26
/* RISC OS version based on pthreads linux source */
#include "SDL_thread.h"
Feb 16, 2006
Feb 16, 2006
27
#include "../SDL_systhread.h"
28
Feb 16, 2006
Feb 16, 2006
29
#if SDL_THREADS_DISABLED
30
Jul 10, 2006
Jul 10, 2006
31
32
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
33
{
Jul 10, 2006
Jul 10, 2006
34
35
36
SDL_SetError
("Threads have not been compiled into this version of the library");
return (-1);
37
38
}
Jul 10, 2006
Jul 10, 2006
39
40
void
SDL_SYS_SetupThread(void)
41
{
Jul 10, 2006
Jul 10, 2006
42
return;
43
44
}
Jul 10, 2006
Jul 10, 2006
45
46
Uint32
SDL_ThreadID(void)
47
{
Jul 10, 2006
Jul 10, 2006
48
return (0);
49
50
}
Jul 10, 2006
Jul 10, 2006
51
52
void
SDL_SYS_WaitThread(SDL_Thread * thread)
53
{
Jul 10, 2006
Jul 10, 2006
54
return;
55
56
}
Jul 10, 2006
Jul 10, 2006
57
58
void
SDL_SYS_KillThread(SDL_Thread * thread)
59
{
Jul 10, 2006
Jul 10, 2006
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[] = {
Jul 10, 2006
Jul 10, 2006
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;
Jul 10, 2006
Jul 10, 2006
76
Uint32 riscos_main_thread = 0; /* Thread running events */
77
Jul 10, 2006
Jul 10, 2006
78
79
static void *
RunThread(void *data)
80
{
Jul 10, 2006
Jul 10, 2006
81
82
83
SDL_RunThread(data);
pthread_exit((void *) 0);
return ((void *) 0); /* Prevent compiler warning */
84
85
}
Jul 10, 2006
Jul 10, 2006
86
87
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
88
{
Jul 10, 2006
Jul 10, 2006
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
}
Jul 10, 2006
Jul 10, 2006
112
113
void
SDL_SYS_SetupThread(void)
114
{
Jul 10, 2006
Jul 10, 2006
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
Jul 10, 2006
Jul 10, 2006
126
127
128
129
130
/* Allow ourselves to be asynchronously cancelled */
{
int oldstate;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
}
131
132
133
#endif
}
Jul 10, 2006
Jul 10, 2006
134
135
Uint32
SDL_ThreadID(void)
136
{
Jul 10, 2006
Jul 10, 2006
137
return ((Uint32) pthread_self());
138
139
}
Jul 10, 2006
Jul 10, 2006
140
141
void
SDL_SYS_WaitThread(SDL_Thread * thread)
142
{
Jul 10, 2006
Jul 10, 2006
143
pthread_join(thread->handle, 0);
144
145
}
Jul 10, 2006
Jul 10, 2006
146
147
void
SDL_SYS_KillThread(SDL_Thread * thread)
148
149
{
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
Jul 10, 2006
Jul 10, 2006
150
pthread_cancel(thread->handle);
151
#else
Jul 10, 2006
Jul 10, 2006
152
pthread_kill(thread->handle, SIGKILL);
153
154
155
156
#endif
}
#endif
Jul 10, 2006
Jul 10, 2006
157
/* vi: set ts=4 sw=4 expandtab: */