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

Latest commit

 

History

History
115 lines (94 loc) · 2.71 KB

SDL_systhread.c

File metadata and controls

115 lines (94 loc) · 2.71 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 12, 2011
Feb 12, 2011
3
Copyright (C) 1997-2011 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
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
Apr 26, 2001
Apr 26, 2001
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.
Apr 26, 2001
Apr 26, 2001
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.
Apr 26, 2001
Apr 26, 2001
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
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
28
29
30
31
/* BeOS thread management routines for SDL */
#include <stdio.h>
#include <signal.h>
#include <be/kernel/OS.h>
#include "SDL_mutex.h"
#include "SDL_thread.h"
Feb 16, 2006
Feb 16, 2006
32
33
#include "../SDL_thread_c.h"
#include "../SDL_systhread.h"
Apr 26, 2001
Apr 26, 2001
34
35
36
static int sig_list[] = {
Jul 10, 2006
Jul 10, 2006
37
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
Apr 26, 2001
Apr 26, 2001
38
39
};
Jul 10, 2006
Jul 10, 2006
40
41
void
SDL_MaskSignals(sigset_t * omask)
Apr 26, 2001
Apr 26, 2001
42
{
Jul 10, 2006
Jul 10, 2006
43
44
45
46
47
48
49
50
sigset_t mask;
int i;
sigemptyset(&mask);
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
sigprocmask(SIG_BLOCK, &mask, omask);
Apr 26, 2001
Apr 26, 2001
51
}
Jul 10, 2006
Jul 10, 2006
52
53
54
void
SDL_UnmaskSignals(sigset_t * omask)
Apr 26, 2001
Apr 26, 2001
55
{
Jul 10, 2006
Jul 10, 2006
56
sigprocmask(SIG_SETMASK, omask, NULL);
Apr 26, 2001
Apr 26, 2001
57
58
}
Jul 10, 2006
Jul 10, 2006
59
60
static int32
RunThread(void *data)
Apr 26, 2001
Apr 26, 2001
61
{
Jul 10, 2006
Jul 10, 2006
62
63
SDL_RunThread(data);
return (0);
Apr 26, 2001
Apr 26, 2001
64
65
}
Jul 10, 2006
Jul 10, 2006
66
67
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
Apr 26, 2001
Apr 26, 2001
68
{
Jul 10, 2006
Jul 10, 2006
69
70
71
72
73
74
75
76
77
/* Create the thread and go! */
thread->handle = spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args);
if ((thread->handle == B_NO_MORE_THREADS) ||
(thread->handle == B_NO_MEMORY)) {
SDL_SetError("Not enough resources to create thread");
return (-1);
}
resume_thread(thread->handle);
return (0);
Apr 26, 2001
Apr 26, 2001
78
79
}
Jul 10, 2006
Jul 10, 2006
80
81
void
SDL_SYS_SetupThread(void)
Apr 26, 2001
Apr 26, 2001
82
{
Jul 10, 2006
Jul 10, 2006
83
84
/* Mask asynchronous signals for this thread */
SDL_MaskSignals(NULL);
Apr 26, 2001
Apr 26, 2001
85
86
}
Dec 16, 2009
Dec 16, 2009
87
SDL_threadID
Jul 10, 2006
Jul 10, 2006
88
SDL_ThreadID(void)
Apr 26, 2001
Apr 26, 2001
89
{
Dec 16, 2009
Dec 16, 2009
90
return ((SDL_threadID) find_thread(NULL));
Apr 26, 2001
Apr 26, 2001
91
92
}
Mar 25, 2011
Mar 25, 2011
93
94
95
96
97
98
99
100
101
102
103
104
105
106
int
SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority)
{
int32 new_priority = B_NORMAL_PRIORITY;
if (priority == SDL_THREAD_PRIORITY_LOW) {
new_priority = B_LOW_PRIORITY;
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
new_priority = B_URGENT_DISPLAY_PRIORITY;
}
set_thread_priority(thread->handle, new_priority);
return 0;
}
Jul 10, 2006
Jul 10, 2006
107
108
void
SDL_SYS_WaitThread(SDL_Thread * thread)
Apr 26, 2001
Apr 26, 2001
109
{
Jul 10, 2006
Jul 10, 2006
110
status_t the_status;
Apr 26, 2001
Apr 26, 2001
111
Jul 10, 2006
Jul 10, 2006
112
wait_for_thread(thread->handle, &the_status);
Apr 26, 2001
Apr 26, 2001
113
114
}
Jul 10, 2006
Jul 10, 2006
115
/* vi: set ts=4 sw=4 expandtab: */