comparison src/thread/pth/SDL_systhread.c @ 329:1d74ddc90cb2

Patrice's fixes for GNU Pthread support
author Sam Lantinga <slouken@libsdl.org>
date Mon, 01 Apr 2002 15:35:28 +0000
parents af42e7c4c860
children 283d348cb624
comparison
equal deleted inserted replaced
328:dc21fa30faa9 329:1d74ddc90cb2
23 #ifdef SAVE_RCSID 23 #ifdef SAVE_RCSID
24 static char rcsid = 24 static char rcsid =
25 "@(#) $Id$"; 25 "@(#) $Id$";
26 #endif 26 #endif
27 27
28 /* Pth thread management routines for SDL */ 28 /*
29 * GNU pth threads
30 *
31 * Patrice Mandin
32 */
29 33
30 #include "SDL_error.h" 34 #include "SDL_error.h"
31 #include "SDL_thread.h" 35 #include "SDL_thread.h"
32 #include "SDL_systhread.h" 36 #include "SDL_systhread.h"
33 37
49 53
50 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) 54 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
51 { 55 {
52 pth_attr_t type; 56 pth_attr_t type;
53 57
58 /* Create a new attribute */
54 type = pth_attr_new(); 59 type = pth_attr_new();
55 60 if ( type == NULL ) {
56 /* Set the thread attributes */
57 if ( pth_attr_init(type) != 0 ) {
58 SDL_SetError("Couldn't initialize pth attributes"); 61 SDL_SetError("Couldn't initialize pth attributes");
59 return(-1); 62 return(-1);
60 } 63 }
61 pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE); 64 pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE);
62 65
63 /* Create the thread and go! */ 66 /* Create the thread and go! */
64 if ( pth_spawn(type, RunThread, args) != 0 ) { 67 if ( pth_spawn(type, RunThread, args) == NULL ) {
65 SDL_SetError("Not enough resources to create thread"); 68 SDL_SetError("Not enough resources to create thread");
66 return(-1); 69 return(-1);
67 } 70 }
68 return(0); 71 return(0);
69 } 72 }
70 73
71 void SDL_SYS_SetupThread(void) 74 void SDL_SYS_SetupThread(void)
72 { 75 {
73 int i; 76 int i;
74 sigset_t mask; 77 sigset_t mask;
78 int oldstate;
75 79
76 /* Mask asynchronous signals for this thread */ 80 /* Mask asynchronous signals for this thread */
77 sigemptyset(&mask); 81 sigemptyset(&mask);
78 for ( i=0; sig_list[i]; ++i ) { 82 for ( i=0; sig_list[i]; ++i ) {
79 sigaddset(&mask, sig_list[i]); 83 sigaddset(&mask, sig_list[i]);
80 } 84 }
81 pth_sigmask(SIG_BLOCK, &mask, 0); 85 pth_sigmask(SIG_BLOCK, &mask, 0);
82 86
83 /* Allow ourselves to be asynchronously cancelled */ 87 /* Allow ourselves to be asynchronously cancelled */
84 { int oldstate; 88 pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
85 pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
86 }
87 } 89 }
88 90
89 /* WARNING: This may not work for systems with 64-bit pid_t */ 91 /* WARNING: This may not work for systems with 64-bit pid_t */
90 Uint32 SDL_ThreadID(void) 92 Uint32 SDL_ThreadID(void)
91 { 93 {