0
|
1 /*
|
|
2 SDL - Simple DirectMedia Layer
|
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 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@devolution.com
|
|
21 */
|
|
22
|
|
23 #ifdef SAVE_RCSID
|
|
24 static char rcsid =
|
|
25 "@(#) $Id$";
|
|
26 #endif
|
|
27
|
|
28 /* IRIX thread management routines for SDL */
|
|
29
|
|
30 #include <stdlib.h>
|
|
31 #include <errno.h>
|
|
32 #include <signal.h>
|
|
33 #include <sys/types.h>
|
|
34 #include <sys/wait.h>
|
|
35 #include <sys/prctl.h>
|
|
36
|
|
37 #include "SDL_error.h"
|
|
38 #include "SDL_thread.h"
|
|
39 #include "SDL_systhread.h"
|
|
40
|
|
41
|
|
42 static int sig_list[] = {
|
|
43 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCLD, SIGWINCH,
|
|
44 SIGVTALRM, SIGPROF, 0
|
|
45 };
|
|
46
|
|
47
|
|
48 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
|
|
49 {
|
|
50 /* Create the thread and go! */
|
|
51 if ( sproc(SDL_RunThread, PR_SALL, args) < 0 ) {
|
|
52 SDL_SetError("Not enough resources to create thread");
|
|
53 return(-1);
|
|
54 }
|
|
55 return(0);
|
|
56 }
|
|
57
|
|
58 void SDL_SYS_SetupThread(void)
|
|
59 {
|
|
60 int i;
|
|
61 sigset_t mask;
|
|
62
|
|
63 /* Mask asynchronous signals for this thread */
|
|
64 sigemptyset(&mask);
|
|
65 for ( i=0; sig_list[i]; ++i ) {
|
|
66 sigaddset(&mask, sig_list[i]);
|
|
67 }
|
|
68 sigprocmask(SIG_BLOCK, &mask, NULL);
|
|
69 }
|
|
70
|
|
71 /* WARNING: This may not work for systems with 64-bit pid_t */
|
|
72 Uint32 SDL_ThreadID(void)
|
|
73 {
|
|
74 return((Uint32)getpid());
|
|
75 }
|
|
76
|
|
77 /* WARNING: This may not work for systems with 64-bit pid_t */
|
|
78 void SDL_WaitThread(SDL_Thread *thread, int *status)
|
|
79 {
|
|
80 errno = 0;
|
|
81 while ( errno != ECHILD ) {
|
|
82 waitpid(thread->handle, NULL, 0);
|
|
83 }
|
|
84 }
|
|
85
|
|
86 /* WARNING: This may not work for systems with 64-bit pid_t */
|
|
87 void SDL_KillThread(SDL_Thread *thread)
|
|
88 {
|
|
89 kill(thread->handle, SIGKILL);
|
|
90 }
|
|
91
|