src/thread/beos/SDL_systhread.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 16 Dec 2009 04:48:11 +0000
changeset 3578 0d1b16ee0bca
parent 2859 99210400e8b9
child 3697 f7b03b6838cb
permissions -rw-r--r--
Fixed bug #741

The thread ID is an unsigned long so it can hold pthread_t so people can do naughty things with it.

I'm going to be adding additional useful thread API functions, but this should prevent crashes in people's existing code on 64-bit architectures.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     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.
     9 
    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.
    14 
    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
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* BeOS thread management routines for SDL */
    25 
    26 #include <stdio.h>
    27 #include <signal.h>
    28 #include <be/kernel/OS.h>
    29 
    30 #include "SDL_mutex.h"
    31 #include "SDL_thread.h"
    32 #include "../SDL_thread_c.h"
    33 #include "../SDL_systhread.h"
    34 
    35 
    36 static int sig_list[] = {
    37     SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
    38 };
    39 
    40 void
    41 SDL_MaskSignals(sigset_t * omask)
    42 {
    43     sigset_t mask;
    44     int i;
    45 
    46     sigemptyset(&mask);
    47     for (i = 0; sig_list[i]; ++i) {
    48         sigaddset(&mask, sig_list[i]);
    49     }
    50     sigprocmask(SIG_BLOCK, &mask, omask);
    51 }
    52 
    53 void
    54 SDL_UnmaskSignals(sigset_t * omask)
    55 {
    56     sigprocmask(SIG_SETMASK, omask, NULL);
    57 }
    58 
    59 static int32
    60 RunThread(void *data)
    61 {
    62     SDL_RunThread(data);
    63     return (0);
    64 }
    65 
    66 int
    67 SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
    68 {
    69     /* Create the thread and go! */
    70     thread->handle = spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args);
    71     if ((thread->handle == B_NO_MORE_THREADS) ||
    72         (thread->handle == B_NO_MEMORY)) {
    73         SDL_SetError("Not enough resources to create thread");
    74         return (-1);
    75     }
    76     resume_thread(thread->handle);
    77     return (0);
    78 }
    79 
    80 void
    81 SDL_SYS_SetupThread(void)
    82 {
    83     /* Mask asynchronous signals for this thread */
    84     SDL_MaskSignals(NULL);
    85 }
    86 
    87 SDL_threadID
    88 SDL_ThreadID(void)
    89 {
    90     return ((SDL_threadID) find_thread(NULL));
    91 }
    92 
    93 void
    94 SDL_SYS_WaitThread(SDL_Thread * thread)
    95 {
    96     status_t the_status;
    97 
    98     wait_for_thread(thread->handle, &the_status);
    99 }
   100 
   101 /* vi: set ts=4 sw=4 expandtab: */