comparison src/thread/pthread/SDL_systhread.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 1e8582152d44
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
28 #include "../SDL_thread_c.h" 28 #include "../SDL_thread_c.h"
29 #include "../SDL_systhread.h" 29 #include "../SDL_systhread.h"
30 30
31 /* List of signals to mask in the subthreads */ 31 /* List of signals to mask in the subthreads */
32 static int sig_list[] = { 32 static int sig_list[] = {
33 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, 33 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
34 SIGVTALRM, SIGPROF, 0 34 SIGVTALRM, SIGPROF, 0
35 }; 35 };
36 36
37 #ifdef __RISCOS__ 37 #ifdef __RISCOS__
38 /* RISC OS needs to know the main thread for 38 /* RISC OS needs to know the main thread for
39 * it's timer and event processing. */ 39 * it's timer and event processing. */
40 int riscos_using_threads = 0; 40 int riscos_using_threads = 0;
41 Uint32 riscos_main_thread = 0; /* Thread running events */ 41 Uint32 riscos_main_thread = 0; /* Thread running events */
42 #endif 42 #endif
43
44 43
45 static void *RunThread(void *data) 44
45 static void *
46 RunThread (void *data)
46 { 47 {
47 SDL_RunThread(data); 48 SDL_RunThread (data);
48 pthread_exit((void*)0); 49 pthread_exit ((void *) 0);
49 return((void *)0); /* Prevent compiler warning */ 50 return ((void *) 0); /* Prevent compiler warning */
50 } 51 }
51 52
52 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) 53 int
54 SDL_SYS_CreateThread (SDL_Thread * thread, void *args)
53 { 55 {
54 pthread_attr_t type; 56 pthread_attr_t type;
55 57
56 /* Set the thread attributes */ 58 /* Set the thread attributes */
57 if ( pthread_attr_init(&type) != 0 ) { 59 if (pthread_attr_init (&type) != 0) {
58 SDL_SetError("Couldn't initialize pthread attributes"); 60 SDL_SetError ("Couldn't initialize pthread attributes");
59 return(-1); 61 return (-1);
60 } 62 }
61 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); 63 pthread_attr_setdetachstate (&type, PTHREAD_CREATE_JOINABLE);
62 64
63 /* Create the thread and go! */ 65 /* Create the thread and go! */
64 if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) { 66 if (pthread_create (&thread->handle, &type, RunThread, args) != 0) {
65 SDL_SetError("Not enough resources to create thread"); 67 SDL_SetError ("Not enough resources to create thread");
66 return(-1); 68 return (-1);
67 } 69 }
68
69 #ifdef __RISCOS__ 70 #ifdef __RISCOS__
70 if (riscos_using_threads == 0) { 71 if (riscos_using_threads == 0) {
71 riscos_using_threads = 1; 72 riscos_using_threads = 1;
72 riscos_main_thread = SDL_ThreadID(); 73 riscos_main_thread = SDL_ThreadID ();
73 } 74 }
74 #endif 75 #endif
75 76
76 return(0); 77 return (0);
77 } 78 }
78 79
79 void SDL_SYS_SetupThread(void) 80 void
81 SDL_SYS_SetupThread (void)
80 { 82 {
81 int i; 83 int i;
82 sigset_t mask; 84 sigset_t mask;
83 85
84 /* Mask asynchronous signals for this thread */ 86 /* Mask asynchronous signals for this thread */
85 sigemptyset(&mask); 87 sigemptyset (&mask);
86 for ( i=0; sig_list[i]; ++i ) { 88 for (i = 0; sig_list[i]; ++i) {
87 sigaddset(&mask, sig_list[i]); 89 sigaddset (&mask, sig_list[i]);
88 } 90 }
89 pthread_sigmask(SIG_BLOCK, &mask, 0); 91 pthread_sigmask (SIG_BLOCK, &mask, 0);
90 92
91 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS 93 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
92 /* Allow ourselves to be asynchronously cancelled */ 94 /* Allow ourselves to be asynchronously cancelled */
93 { int oldstate; 95 {
94 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); 96 int oldstate;
95 } 97 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
98 }
96 #endif 99 #endif
97 } 100 }
98 101
99 /* WARNING: This may not work for systems with 64-bit pid_t */ 102 /* WARNING: This may not work for systems with 64-bit pid_t */
100 Uint32 SDL_ThreadID(void) 103 Uint32
104 SDL_ThreadID (void)
101 { 105 {
102 return((Uint32)pthread_self()); 106 return ((Uint32) pthread_self ());
103 } 107 }
104 108
105 void SDL_SYS_WaitThread(SDL_Thread *thread) 109 void
110 SDL_SYS_WaitThread (SDL_Thread * thread)
106 { 111 {
107 pthread_join(thread->handle, 0); 112 pthread_join (thread->handle, 0);
108 } 113 }
109 114
110 void SDL_SYS_KillThread(SDL_Thread *thread) 115 void
116 SDL_SYS_KillThread (SDL_Thread * thread)
111 { 117 {
112 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS 118 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
113 pthread_cancel(thread->handle); 119 pthread_cancel (thread->handle);
114 #else 120 #else
115 #ifdef __FREEBSD__ 121 #ifdef __FREEBSD__
116 #warning For some reason, this doesnt actually kill a thread - FreeBSD 3.2 122 #warning For some reason, this doesnt actually kill a thread - FreeBSD 3.2
117 #endif 123 #endif
118 pthread_kill(thread->handle, SIGKILL); 124 pthread_kill (thread->handle, SIGKILL);
119 #endif 125 #endif
120 } 126 }
127
128 /* vi: set ts=4 sw=4 expandtab: */