comparison src/thread/pthread/SDL_systhread.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
41 Uint32 riscos_main_thread = 0; /* Thread running events */ 41 Uint32 riscos_main_thread = 0; /* Thread running events */
42 #endif 42 #endif
43 43
44 44
45 static void * 45 static void *
46 RunThread (void *data) 46 RunThread(void *data)
47 { 47 {
48 SDL_RunThread (data); 48 SDL_RunThread(data);
49 pthread_exit ((void *) 0); 49 pthread_exit((void *) 0);
50 return ((void *) 0); /* Prevent compiler warning */ 50 return ((void *) 0); /* Prevent compiler warning */
51 } 51 }
52 52
53 int 53 int
54 SDL_SYS_CreateThread (SDL_Thread * thread, void *args) 54 SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
55 { 55 {
56 pthread_attr_t type; 56 pthread_attr_t type;
57 57
58 /* Set the thread attributes */ 58 /* Set the thread attributes */
59 if (pthread_attr_init (&type) != 0) { 59 if (pthread_attr_init(&type) != 0) {
60 SDL_SetError ("Couldn't initialize pthread attributes"); 60 SDL_SetError("Couldn't initialize pthread attributes");
61 return (-1); 61 return (-1);
62 } 62 }
63 pthread_attr_setdetachstate (&type, PTHREAD_CREATE_JOINABLE); 63 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
64 64
65 /* Create the thread and go! */ 65 /* Create the thread and go! */
66 if (pthread_create (&thread->handle, &type, RunThread, args) != 0) { 66 if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
67 SDL_SetError ("Not enough resources to create thread"); 67 SDL_SetError("Not enough resources to create thread");
68 return (-1); 68 return (-1);
69 } 69 }
70 #ifdef __RISCOS__ 70 #ifdef __RISCOS__
71 if (riscos_using_threads == 0) { 71 if (riscos_using_threads == 0) {
72 riscos_using_threads = 1; 72 riscos_using_threads = 1;
73 riscos_main_thread = SDL_ThreadID (); 73 riscos_main_thread = SDL_ThreadID();
74 } 74 }
75 #endif 75 #endif
76 76
77 return (0); 77 return (0);
78 } 78 }
79 79
80 void 80 void
81 SDL_SYS_SetupThread (void) 81 SDL_SYS_SetupThread(void)
82 { 82 {
83 int i; 83 int i;
84 sigset_t mask; 84 sigset_t mask;
85 85
86 /* Mask asynchronous signals for this thread */ 86 /* Mask asynchronous signals for this thread */
87 sigemptyset (&mask); 87 sigemptyset(&mask);
88 for (i = 0; sig_list[i]; ++i) { 88 for (i = 0; sig_list[i]; ++i) {
89 sigaddset (&mask, sig_list[i]); 89 sigaddset(&mask, sig_list[i]);
90 } 90 }
91 pthread_sigmask (SIG_BLOCK, &mask, 0); 91 pthread_sigmask(SIG_BLOCK, &mask, 0);
92 92
93 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS 93 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
94 /* Allow ourselves to be asynchronously cancelled */ 94 /* Allow ourselves to be asynchronously cancelled */
95 { 95 {
96 int oldstate; 96 int oldstate;
97 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); 97 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
98 } 98 }
99 #endif 99 #endif
100 } 100 }
101 101
102 /* 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 */
103 Uint32 103 Uint32
104 SDL_ThreadID (void) 104 SDL_ThreadID(void)
105 { 105 {
106 return ((Uint32) pthread_self ()); 106 return ((Uint32) pthread_self());
107 } 107 }
108 108
109 void 109 void
110 SDL_SYS_WaitThread (SDL_Thread * thread) 110 SDL_SYS_WaitThread(SDL_Thread * thread)
111 { 111 {
112 pthread_join (thread->handle, 0); 112 pthread_join(thread->handle, 0);
113 } 113 }
114 114
115 void 115 void
116 SDL_SYS_KillThread (SDL_Thread * thread) 116 SDL_SYS_KillThread(SDL_Thread * thread)
117 { 117 {
118 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS 118 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
119 pthread_cancel (thread->handle); 119 pthread_cancel(thread->handle);
120 #else 120 #else
121 #ifdef __FREEBSD__ 121 #ifdef __FREEBSD__
122 #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
123 #endif 123 #endif
124 pthread_kill (thread->handle, SIGKILL); 124 pthread_kill(thread->handle, SIGKILL);
125 #endif 125 #endif
126 } 126 }
127 127
128 /* vi: set ts=4 sw=4 expandtab: */ 128 /* vi: set ts=4 sw=4 expandtab: */