Mercurial > sdl-ios-xcode
comparison src/thread/riscos/SDL_systhread.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | d910939febfa |
children | 4436464c4f51 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
26 #include "SDL_thread.h" | 26 #include "SDL_thread.h" |
27 #include "../SDL_systhread.h" | 27 #include "../SDL_systhread.h" |
28 | 28 |
29 #if SDL_THREADS_DISABLED | 29 #if SDL_THREADS_DISABLED |
30 | 30 |
31 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | 31 int |
32 SDL_SYS_CreateThread(SDL_Thread * thread, void *args) | |
32 { | 33 { |
33 SDL_SetError("Threads have not been compiled into this version of the library"); | 34 SDL_SetError |
34 return(-1); | 35 ("Threads have not been compiled into this version of the library"); |
36 return (-1); | |
35 } | 37 } |
36 | 38 |
37 void SDL_SYS_SetupThread(void) | 39 void |
40 SDL_SYS_SetupThread(void) | |
38 { | 41 { |
39 return; | 42 return; |
40 } | 43 } |
41 | 44 |
42 Uint32 SDL_ThreadID(void) | 45 Uint32 |
46 SDL_ThreadID(void) | |
43 { | 47 { |
44 return(0); | 48 return (0); |
45 } | 49 } |
46 | 50 |
47 void SDL_SYS_WaitThread(SDL_Thread *thread) | 51 void |
52 SDL_SYS_WaitThread(SDL_Thread * thread) | |
48 { | 53 { |
49 return; | 54 return; |
50 } | 55 } |
51 | 56 |
52 void SDL_SYS_KillThread(SDL_Thread *thread) | 57 void |
58 SDL_SYS_KillThread(SDL_Thread * thread) | |
53 { | 59 { |
54 return; | 60 return; |
55 } | 61 } |
56 | 62 |
57 #else | 63 #else |
58 | 64 |
59 #include <signal.h> | 65 #include <signal.h> |
60 | 66 |
61 /* List of signals to mask in the subthreads */ | 67 /* List of signals to mask in the subthreads */ |
62 static int sig_list[] = { | 68 static int sig_list[] = { |
63 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, | 69 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, |
64 SIGVTALRM, SIGPROF, 0 | 70 SIGVTALRM, SIGPROF, 0 |
65 }; | 71 }; |
66 | 72 |
67 #include <pthread.h> | 73 #include <pthread.h> |
68 | 74 |
69 int riscos_using_threads = 0; | 75 int riscos_using_threads = 0; |
70 Uint32 riscos_main_thread = 0; /* Thread running events */ | 76 Uint32 riscos_main_thread = 0; /* Thread running events */ |
71 | 77 |
72 static void *RunThread(void *data) | 78 static void * |
79 RunThread(void *data) | |
73 { | 80 { |
74 SDL_RunThread(data); | 81 SDL_RunThread(data); |
75 pthread_exit((void*)0); | 82 pthread_exit((void *) 0); |
76 return((void *)0); /* Prevent compiler warning */ | 83 return ((void *) 0); /* Prevent compiler warning */ |
77 } | 84 } |
78 | 85 |
79 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | 86 int |
87 SDL_SYS_CreateThread(SDL_Thread * thread, void *args) | |
80 { | 88 { |
81 pthread_attr_t type; | 89 pthread_attr_t type; |
82 | 90 |
83 /* Set the thread attributes */ | 91 /* Set the thread attributes */ |
84 if ( pthread_attr_init(&type) != 0 ) { | 92 if (pthread_attr_init(&type) != 0) { |
85 SDL_SetError("Couldn't initialize pthread attributes"); | 93 SDL_SetError("Couldn't initialize pthread attributes"); |
86 return(-1); | 94 return (-1); |
87 } | 95 } |
88 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); | 96 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); |
89 | 97 |
90 /* Create the thread and go! */ | 98 /* Create the thread and go! */ |
91 if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) { | 99 if (pthread_create(&thread->handle, &type, RunThread, args) != 0) { |
92 SDL_SetError("Not enough resources to create thread"); | 100 SDL_SetError("Not enough resources to create thread"); |
93 return(-1); | 101 return (-1); |
94 } | 102 } |
95 | 103 |
96 if (riscos_using_threads == 0) | 104 if (riscos_using_threads == 0) { |
97 { | 105 riscos_using_threads = 1; |
98 riscos_using_threads = 1; | 106 riscos_main_thread = SDL_ThreadID(); |
99 riscos_main_thread = SDL_ThreadID(); | 107 } |
100 } | 108 |
101 | 109 return (0); |
102 return(0); | |
103 } | 110 } |
104 | 111 |
105 void SDL_SYS_SetupThread(void) | 112 void |
113 SDL_SYS_SetupThread(void) | |
106 { | 114 { |
107 int i; | 115 int i; |
108 sigset_t mask; | 116 sigset_t mask; |
109 | 117 |
110 /* Mask asynchronous signals for this thread */ | 118 /* Mask asynchronous signals for this thread */ |
111 sigemptyset(&mask); | 119 sigemptyset(&mask); |
112 for ( i=0; sig_list[i]; ++i ) { | 120 for (i = 0; sig_list[i]; ++i) { |
113 sigaddset(&mask, sig_list[i]); | 121 sigaddset(&mask, sig_list[i]); |
114 } | 122 } |
115 pthread_sigmask(SIG_BLOCK, &mask, 0); | 123 pthread_sigmask(SIG_BLOCK, &mask, 0); |
116 | 124 |
117 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | 125 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS |
118 /* Allow ourselves to be asynchronously cancelled */ | 126 /* Allow ourselves to be asynchronously cancelled */ |
119 { int oldstate; | 127 { |
120 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); | 128 int oldstate; |
121 } | 129 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); |
130 } | |
122 #endif | 131 #endif |
123 } | 132 } |
124 | 133 |
125 Uint32 SDL_ThreadID(void) | 134 Uint32 |
135 SDL_ThreadID(void) | |
126 { | 136 { |
127 return((Uint32)pthread_self()); | 137 return ((Uint32) pthread_self()); |
128 } | 138 } |
129 | 139 |
130 void SDL_SYS_WaitThread(SDL_Thread *thread) | 140 void |
141 SDL_SYS_WaitThread(SDL_Thread * thread) | |
131 { | 142 { |
132 pthread_join(thread->handle, 0); | 143 pthread_join(thread->handle, 0); |
133 } | 144 } |
134 | 145 |
135 void SDL_SYS_KillThread(SDL_Thread *thread) | 146 void |
147 SDL_SYS_KillThread(SDL_Thread * thread) | |
136 { | 148 { |
137 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS | 149 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS |
138 pthread_cancel(thread->handle); | 150 pthread_cancel(thread->handle); |
139 #else | 151 #else |
140 pthread_kill(thread->handle, SIGKILL); | 152 pthread_kill(thread->handle, SIGKILL); |
141 #endif | 153 #endif |
142 } | 154 } |
143 | 155 |
144 #endif | 156 #endif |
157 /* vi: set ts=4 sw=4 expandtab: */ |