2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
33 #include "SDL_thread.h"
34 #include "../SDL_thread_c.h"
35 #include "../SDL_systhread.h"
37 /* List of signals to mask in the subthreads */
38 static int sig_list[] = {
39 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
43 static void *RunThread(void *data)
47 return((void *)0); /* Prevent compiler warning */
50 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
54 /* Create a new attribute */
55 type = pth_attr_new();
57 SDL_SetError("Couldn't initialize pth attributes");
60 pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE);
62 /* Create the thread and go! */
63 thread->handle = pth_spawn(type, RunThread, args);
64 if ( thread->handle == NULL ) {
65 SDL_SetError("Not enough resources to create thread");
71 void SDL_SYS_SetupThread(void)
77 /* Mask asynchronous signals for this thread */
79 for ( i=0; sig_list[i]; ++i ) {
80 sigaddset(&mask, sig_list[i]);
82 pth_sigmask(SIG_BLOCK, &mask, 0);
84 /* Allow ourselves to be asynchronously cancelled */
85 pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
88 /* WARNING: This may not work for systems with 64-bit pid_t */
89 Uint32 SDL_ThreadID(void)
91 return((Uint32)pth_self());
94 void SDL_SYS_WaitThread(SDL_Thread *thread)
96 pth_join(thread->handle, NULL);
99 void SDL_SYS_KillThread(SDL_Thread *thread)
101 pth_cancel(thread->handle);
102 pth_join(thread->handle, NULL);