src/thread/pthread/SDL_systhread.c
changeset 1895 c121d94672cb
parent 1459 1e8582152d44
child 2779 4436464c4f51
     1.1 --- a/src/thread/pthread/SDL_systhread.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/thread/pthread/SDL_systhread.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -30,91 +30,99 @@
     1.4  
     1.5  /* List of signals to mask in the subthreads */
     1.6  static int sig_list[] = {
     1.7 -	SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
     1.8 -	SIGVTALRM, SIGPROF, 0
     1.9 +    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
    1.10 +    SIGVTALRM, SIGPROF, 0
    1.11  };
    1.12  
    1.13  #ifdef __RISCOS__
    1.14  /* RISC OS needs to know the main thread for
    1.15   * it's timer and event processing. */
    1.16  int riscos_using_threads = 0;
    1.17 -Uint32 riscos_main_thread = 0; /* Thread running events */
    1.18 +Uint32 riscos_main_thread = 0;  /* Thread running events */
    1.19  #endif
    1.20 - 
    1.21  
    1.22 -static void *RunThread(void *data)
    1.23 +
    1.24 +static void *
    1.25 +RunThread(void *data)
    1.26  {
    1.27 -	SDL_RunThread(data);
    1.28 -	pthread_exit((void*)0);
    1.29 -	return((void *)0);		/* Prevent compiler warning */
    1.30 +    SDL_RunThread(data);
    1.31 +    pthread_exit((void *) 0);
    1.32 +    return ((void *) 0);        /* Prevent compiler warning */
    1.33  }
    1.34  
    1.35 -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
    1.36 +int
    1.37 +SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
    1.38  {
    1.39 -	pthread_attr_t type;
    1.40 +    pthread_attr_t type;
    1.41  
    1.42 -	/* Set the thread attributes */
    1.43 -	if ( pthread_attr_init(&type) != 0 ) {
    1.44 -		SDL_SetError("Couldn't initialize pthread attributes");
    1.45 -		return(-1);
    1.46 -	}
    1.47 -	pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
    1.48 +    /* Set the thread attributes */
    1.49 +    if (pthread_attr_init(&type) != 0) {
    1.50 +        SDL_SetError("Couldn't initialize pthread attributes");
    1.51 +        return (-1);
    1.52 +    }
    1.53 +    pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
    1.54  
    1.55 -	/* Create the thread and go! */
    1.56 -	if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) {
    1.57 -		SDL_SetError("Not enough resources to create thread");
    1.58 -		return(-1);
    1.59 -	}
    1.60 -
    1.61 +    /* Create the thread and go! */
    1.62 +    if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
    1.63 +        SDL_SetError("Not enough resources to create thread");
    1.64 +        return (-1);
    1.65 +    }
    1.66  #ifdef __RISCOS__
    1.67 -	if (riscos_using_threads == 0) {
    1.68 -		riscos_using_threads = 1;
    1.69 -		riscos_main_thread = SDL_ThreadID();
    1.70 -	}
    1.71 +    if (riscos_using_threads == 0) {
    1.72 +        riscos_using_threads = 1;
    1.73 +        riscos_main_thread = SDL_ThreadID();
    1.74 +    }
    1.75  #endif
    1.76  
    1.77 -	return(0);
    1.78 +    return (0);
    1.79  }
    1.80  
    1.81 -void SDL_SYS_SetupThread(void)
    1.82 +void
    1.83 +SDL_SYS_SetupThread(void)
    1.84  {
    1.85 -	int i;
    1.86 -	sigset_t mask;
    1.87 +    int i;
    1.88 +    sigset_t mask;
    1.89  
    1.90 -	/* Mask asynchronous signals for this thread */
    1.91 -	sigemptyset(&mask);
    1.92 -	for ( i=0; sig_list[i]; ++i ) {
    1.93 -		sigaddset(&mask, sig_list[i]);
    1.94 -	}
    1.95 -	pthread_sigmask(SIG_BLOCK, &mask, 0);
    1.96 +    /* Mask asynchronous signals for this thread */
    1.97 +    sigemptyset(&mask);
    1.98 +    for (i = 0; sig_list[i]; ++i) {
    1.99 +        sigaddset(&mask, sig_list[i]);
   1.100 +    }
   1.101 +    pthread_sigmask(SIG_BLOCK, &mask, 0);
   1.102  
   1.103  #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
   1.104 -	/* Allow ourselves to be asynchronously cancelled */
   1.105 -	{ int oldstate;
   1.106 -		pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
   1.107 -	}
   1.108 +    /* Allow ourselves to be asynchronously cancelled */
   1.109 +    {
   1.110 +        int oldstate;
   1.111 +        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
   1.112 +    }
   1.113  #endif
   1.114  }
   1.115  
   1.116  /* WARNING:  This may not work for systems with 64-bit pid_t */
   1.117 -Uint32 SDL_ThreadID(void)
   1.118 +Uint32
   1.119 +SDL_ThreadID(void)
   1.120  {
   1.121 -	return((Uint32)pthread_self());
   1.122 +    return ((Uint32) pthread_self());
   1.123  }
   1.124  
   1.125 -void SDL_SYS_WaitThread(SDL_Thread *thread)
   1.126 +void
   1.127 +SDL_SYS_WaitThread(SDL_Thread * thread)
   1.128  {
   1.129 -	pthread_join(thread->handle, 0);
   1.130 +    pthread_join(thread->handle, 0);
   1.131  }
   1.132  
   1.133 -void SDL_SYS_KillThread(SDL_Thread *thread)
   1.134 +void
   1.135 +SDL_SYS_KillThread(SDL_Thread * thread)
   1.136  {
   1.137  #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
   1.138 -	pthread_cancel(thread->handle);
   1.139 +    pthread_cancel(thread->handle);
   1.140  #else
   1.141  #ifdef __FREEBSD__
   1.142  #warning For some reason, this doesnt actually kill a thread - FreeBSD 3.2
   1.143  #endif
   1.144 -	pthread_kill(thread->handle, SIGKILL);
   1.145 +    pthread_kill(thread->handle, SIGKILL);
   1.146  #endif
   1.147  }
   1.148 +
   1.149 +/* vi: set ts=4 sw=4 expandtab: */