Started BeOS removal: merged BeOS thread and pthread code.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 13 Nov 2013 22:35:26 -0500
changeset 79775272ae8fccd7
parent 7976 e8f93c2ebda3
child 7978 70ac84e49797
Started BeOS removal: merged BeOS thread and pthread code.

Haiku uses most of the standard pthread API, with a few #ifdefs where we
still need to fallback onto the old BeOS APIs.

BeOS, however, does not support pthreads (or maybe doesn't support it well),
so I'm unplugging support for the platform with this changeset. Be Inc went
out of business in 2001.
CMakeLists.txt
cmake/sdlchecks.cmake
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/audio/baudio/SDL_beaudio.cc
src/thread/SDL_thread_c.h
src/thread/beos/SDL_syssem.c
src/thread/beos/SDL_systhread.c
src/thread/beos/SDL_systhread_c.h
src/thread/beos/SDL_systls.c
src/thread/pthread/SDL_systhread.c
     1.1 --- a/CMakeLists.txt	Wed Nov 13 21:50:59 2013 -0800
     1.2 +++ b/CMakeLists.txt	Wed Nov 13 22:35:26 2013 -0500
     1.3 @@ -1012,6 +1012,8 @@
     1.4        set(HAVE_VIDEO_OPENGL TRUE)
     1.5      endif(VIDEO_OPENGL)
     1.6    endif(SDL_VIDEO)
     1.7 +
     1.8 +  CheckPTHREAD()
     1.9  endif()
    1.10  
    1.11  # Dummies
     2.1 --- a/cmake/sdlchecks.cmake	Wed Nov 13 21:50:59 2013 -0800
     2.2 +++ b/cmake/sdlchecks.cmake	Wed Nov 13 22:35:26 2013 -0500
     2.3 @@ -638,6 +638,9 @@
     2.4      elseif(HPUX)
     2.5        set(PTHREAD_CFLAGS "-D_REENTRANT")
     2.6        set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
     2.7 +    elseif(BEOS)
     2.8 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
     2.9 +      set(PTHREAD_LDFLAGS "")
    2.10      else()
    2.11        set(PTHREAD_CFLAGS "-D_REENTRANT")
    2.12        set(PTHREAD_LDFLAGS "-lpthread")
     3.1 --- a/configure	Wed Nov 13 21:50:59 2013 -0800
     3.2 +++ b/configure	Wed Nov 13 22:35:26 2013 -0500
     3.3 @@ -21006,6 +21006,10 @@
     3.4              pthread_cflags="-D_REENTRANT"
     3.5              pthread_lib="-L/usr/lib -lpthread"
     3.6              ;;
     3.7 +        *-*-haiku*)
     3.8 +            pthread_cflags="-D_REENTRANT"
     3.9 +            pthread_lib=""
    3.10 +            ;;
    3.11          *)
    3.12              pthread_cflags="-D_REENTRANT"
    3.13              pthread_lib="-lpthread"
    3.14 @@ -22394,7 +22398,9 @@
    3.15              SDL_LIBS="-lcygwin $SDL_LIBS"
    3.16          fi
    3.17          ;;
    3.18 -    *-*-beos* | *-*-haiku*)
    3.19 +
    3.20 +
    3.21 +    *-*-haiku*)
    3.22          ARCH=beos
    3.23          ac_default_prefix=/boot/common
    3.24          CheckDummyVideo
    3.25 @@ -22402,6 +22408,7 @@
    3.26          CheckDummyAudio
    3.27          CheckBWINDOW
    3.28          CheckBeGL
    3.29 +        CheckPTHREAD
    3.30          # Set up files for the audio library
    3.31          if test x$enable_audio = xyes; then
    3.32  
    3.33 @@ -22418,16 +22425,6 @@
    3.34              SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
    3.35              have_joystick=yes
    3.36          fi
    3.37 -        # Set up files for the thread library
    3.38 -        if test x$enable_threads = xyes; then
    3.39 -
    3.40 -$as_echo "#define SDL_THREAD_BEOS 1" >>confdefs.h
    3.41 -
    3.42 -            SOURCES="$SOURCES $srcdir/src/thread/beos/*.c"
    3.43 -            SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_sysmutex.c"
    3.44 -            SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_syscond.c"
    3.45 -            have_threads=yes
    3.46 -        fi
    3.47          # Set up files for the timer library
    3.48          if test x$enable_timers = xyes; then
    3.49  
     4.1 --- a/configure.in	Wed Nov 13 21:50:59 2013 -0800
     4.2 +++ b/configure.in	Wed Nov 13 22:35:26 2013 -0500
     4.3 @@ -1940,6 +1940,10 @@
     4.4              pthread_cflags="-D_REENTRANT"
     4.5              pthread_lib="-L/usr/lib -lpthread"
     4.6              ;;
     4.7 +        *-*-haiku*)
     4.8 +            pthread_cflags="-D_REENTRANT"
     4.9 +            pthread_lib=""
    4.10 +            ;;
    4.11          *)
    4.12              pthread_cflags="-D_REENTRANT"
    4.13              pthread_lib="-lpthread"
    4.14 @@ -2613,7 +2617,11 @@
    4.15              SDL_LIBS="-lcygwin $SDL_LIBS"
    4.16          fi
    4.17          ;;
    4.18 -    *-*-beos* | *-*-haiku*)
    4.19 +
    4.20 +    dnl BeOS support removed after SDL 2.0.1. Haiku still works.  --ryan.
    4.21 +    dnl *-*-beos*)
    4.22 +
    4.23 +    *-*-haiku*)
    4.24          ARCH=beos
    4.25          ac_default_prefix=/boot/common
    4.26          CheckDummyVideo
    4.27 @@ -2621,6 +2629,7 @@
    4.28          CheckDummyAudio
    4.29          CheckBWINDOW
    4.30          CheckBeGL
    4.31 +        CheckPTHREAD
    4.32          # Set up files for the audio library
    4.33          if test x$enable_audio = xyes; then
    4.34              AC_DEFINE(SDL_AUDIO_DRIVER_BEOSAUDIO, 1, [ ])
    4.35 @@ -2633,14 +2642,6 @@
    4.36              SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
    4.37              have_joystick=yes
    4.38          fi
    4.39 -        # Set up files for the thread library
    4.40 -        if test x$enable_threads = xyes; then
    4.41 -            AC_DEFINE(SDL_THREAD_BEOS, 1, [ ])
    4.42 -            SOURCES="$SOURCES $srcdir/src/thread/beos/*.c"
    4.43 -            SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_sysmutex.c"
    4.44 -            SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_syscond.c"
    4.45 -            have_threads=yes
    4.46 -        fi
    4.47          # Set up files for the timer library
    4.48          if test x$enable_timers = xyes; then
    4.49              AC_DEFINE(SDL_TIMER_BEOS, 1, [ ])
     5.1 --- a/include/SDL_config.h.cmake	Wed Nov 13 21:50:59 2013 -0800
     5.2 +++ b/include/SDL_config.h.cmake	Wed Nov 13 22:35:26 2013 -0500
     5.3 @@ -237,7 +237,6 @@
     5.4  #cmakedefine SDL_LOADSO_WINDOWS @SDL_LOADSO_WINDOWS@
     5.5  
     5.6  /* Enable various threading systems */
     5.7 -#cmakedefine SDL_THREAD_BEOS @SDL_THREAD_BEOS@
     5.8  #cmakedefine SDL_THREAD_PTHREAD @SDL_THREAD_PTHREAD@
     5.9  #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX@
    5.10  #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP@
     6.1 --- a/include/SDL_config.h.in	Wed Nov 13 21:50:59 2013 -0800
     6.2 +++ b/include/SDL_config.h.in	Wed Nov 13 22:35:26 2013 -0500
     6.3 @@ -240,7 +240,6 @@
     6.4  #undef SDL_LOADSO_WINDOWS
     6.5  
     6.6  /* Enable various threading systems */
     6.7 -#undef SDL_THREAD_BEOS
     6.8  #undef SDL_THREAD_PTHREAD
     6.9  #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
    6.10  #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
     7.1 --- a/src/audio/baudio/SDL_beaudio.cc	Wed Nov 13 21:50:59 2013 -0800
     7.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Wed Nov 13 22:35:26 2013 -0500
     7.3 @@ -25,6 +25,7 @@
     7.4  /* Allow access to the audio stream on BeOS */
     7.5  
     7.6  #include <SoundPlayer.h>
     7.7 +#include <signal.h>
     7.8  
     7.9  #include "../../main/beos/SDL_BeApp.h"
    7.10  
    7.11 @@ -85,6 +86,31 @@
    7.12      }
    7.13  }
    7.14  
    7.15 +
    7.16 +static const int sig_list[] = {
    7.17 +    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
    7.18 +};
    7.19 +
    7.20 +static inline void
    7.21 +MaskSignals(sigset_t * omask)
    7.22 +{
    7.23 +    sigset_t mask;
    7.24 +    int i;
    7.25 +
    7.26 +    sigemptyset(&mask);
    7.27 +    for (i = 0; sig_list[i]; ++i) {
    7.28 +        sigaddset(&mask, sig_list[i]);
    7.29 +    }
    7.30 +    sigprocmask(SIG_BLOCK, &mask, omask);
    7.31 +}
    7.32 +
    7.33 +static inline void
    7.34 +UnmaskSignals(sigset_t * omask)
    7.35 +{
    7.36 +    sigprocmask(SIG_SETMASK, omask, NULL);
    7.37 +}
    7.38 +
    7.39 +
    7.40  static int
    7.41  BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
    7.42  {
    7.43 @@ -162,10 +188,10 @@
    7.44  
    7.45      /* Subscribe to the audio stream (creates a new thread) */
    7.46      sigset_t omask;
    7.47 -    SDL_MaskSignals(&omask);
    7.48 +    MaskSignals(&omask);
    7.49      _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
    7.50                                                  FillSound, NULL, _this);
    7.51 -    SDL_UnmaskSignals(&omask);
    7.52 +    UnmaskSignals(&omask);
    7.53  
    7.54      if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
    7.55          _this->hidden->audio_obj->SetHasData(true);
     8.1 --- a/src/thread/SDL_thread_c.h	Wed Nov 13 21:50:59 2013 -0800
     8.2 +++ b/src/thread/SDL_thread_c.h	Wed Nov 13 22:35:26 2013 -0500
     8.3 @@ -28,10 +28,6 @@
     8.4  /* Need the definitions of SYS_ThreadHandle */
     8.5  #if SDL_THREADS_DISABLED
     8.6  #include "generic/SDL_systhread_c.h"
     8.7 -#elif SDL_THREAD_BEOS
     8.8 -#include "beos/SDL_systhread_c.h"
     8.9 -#elif SDL_THREAD_EPOC
    8.10 -#include "epoc/SDL_systhread_c.h"
    8.11  #elif SDL_THREAD_PTHREAD
    8.12  #include "pthread/SDL_systhread_c.h"
    8.13  #elif SDL_THREAD_WINDOWS
     9.1 --- a/src/thread/beos/SDL_syssem.c	Wed Nov 13 21:50:59 2013 -0800
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,151 +0,0 @@
     9.4 -/*
     9.5 -  Simple DirectMedia Layer
     9.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     9.7 -
     9.8 -  This software is provided 'as-is', without any express or implied
     9.9 -  warranty.  In no event will the authors be held liable for any damages
    9.10 -  arising from the use of this software.
    9.11 -
    9.12 -  Permission is granted to anyone to use this software for any purpose,
    9.13 -  including commercial applications, and to alter it and redistribute it
    9.14 -  freely, subject to the following restrictions:
    9.15 -
    9.16 -  1. The origin of this software must not be misrepresented; you must not
    9.17 -     claim that you wrote the original software. If you use this software
    9.18 -     in a product, an acknowledgment in the product documentation would be
    9.19 -     appreciated but is not required.
    9.20 -  2. Altered source versions must be plainly marked as such, and must not be
    9.21 -     misrepresented as being the original software.
    9.22 -  3. This notice may not be removed or altered from any source distribution.
    9.23 -*/
    9.24 -#include "SDL_config.h"
    9.25 -
    9.26 -#ifdef SDL_THREAD_BEOS
    9.27 -
    9.28 -/* Semaphores in the BeOS environment */
    9.29 -
    9.30 -#include <be/kernel/OS.h>
    9.31 -
    9.32 -#include "SDL_thread.h"
    9.33 -
    9.34 -
    9.35 -struct SDL_semaphore
    9.36 -{
    9.37 -    sem_id id;
    9.38 -};
    9.39 -
    9.40 -/* Create a counting semaphore */
    9.41 -SDL_sem *
    9.42 -SDL_CreateSemaphore(Uint32 initial_value)
    9.43 -{
    9.44 -    SDL_sem *sem;
    9.45 -
    9.46 -    sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
    9.47 -    if (sem) {
    9.48 -        sem->id = create_sem(initial_value, "SDL semaphore");
    9.49 -        if (sem->id < B_NO_ERROR) {
    9.50 -            SDL_SetError("create_sem() failed");
    9.51 -            SDL_free(sem);
    9.52 -            sem = NULL;
    9.53 -        }
    9.54 -    } else {
    9.55 -        SDL_OutOfMemory();
    9.56 -    }
    9.57 -    return (sem);
    9.58 -}
    9.59 -
    9.60 -/* Free the semaphore */
    9.61 -void
    9.62 -SDL_DestroySemaphore(SDL_sem * sem)
    9.63 -{
    9.64 -    if (sem) {
    9.65 -        if (sem->id >= B_NO_ERROR) {
    9.66 -            delete_sem(sem->id);
    9.67 -        }
    9.68 -        SDL_free(sem);
    9.69 -    }
    9.70 -}
    9.71 -
    9.72 -int
    9.73 -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
    9.74 -{
    9.75 -    int32 val;
    9.76 -    int retval;
    9.77 -
    9.78 -    if (!sem) {
    9.79 -        return SDL_SetError("Passed a NULL semaphore");
    9.80 -    }
    9.81 -
    9.82 -  tryagain:
    9.83 -    if (timeout == SDL_MUTEX_MAXWAIT) {
    9.84 -        val = acquire_sem(sem->id);
    9.85 -    } else {
    9.86 -        timeout *= 1000;        /* BeOS uses a timeout in microseconds */
    9.87 -        val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout);
    9.88 -    }
    9.89 -    switch (val) {
    9.90 -    case B_INTERRUPTED:
    9.91 -        goto tryagain;
    9.92 -    case B_NO_ERROR:
    9.93 -        retval = 0;
    9.94 -        break;
    9.95 -    case B_TIMED_OUT:
    9.96 -        retval = SDL_MUTEX_TIMEDOUT;
    9.97 -        break;
    9.98 -    case B_WOULD_BLOCK:
    9.99 -        retval = SDL_MUTEX_TIMEDOUT;
   9.100 -        break;
   9.101 -    default:
   9.102 -        retval = SDL_SetError("acquire_sem() failed");
   9.103 -        break;
   9.104 -    }
   9.105 -
   9.106 -    return retval;
   9.107 -}
   9.108 -
   9.109 -int
   9.110 -SDL_SemTryWait(SDL_sem * sem)
   9.111 -{
   9.112 -    return SDL_SemWaitTimeout(sem, 0);
   9.113 -}
   9.114 -
   9.115 -int
   9.116 -SDL_SemWait(SDL_sem * sem)
   9.117 -{
   9.118 -    return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
   9.119 -}
   9.120 -
   9.121 -/* Returns the current count of the semaphore */
   9.122 -Uint32
   9.123 -SDL_SemValue(SDL_sem * sem)
   9.124 -{
   9.125 -    int32 count;
   9.126 -    Uint32 value;
   9.127 -
   9.128 -    value = 0;
   9.129 -    if (sem) {
   9.130 -        get_sem_count(sem->id, &count);
   9.131 -        if (count > 0) {
   9.132 -            value = (Uint32) count;
   9.133 -        }
   9.134 -    }
   9.135 -    return value;
   9.136 -}
   9.137 -
   9.138 -/* Atomically increases the semaphore's count (not blocking) */
   9.139 -int
   9.140 -SDL_SemPost(SDL_sem * sem)
   9.141 -{
   9.142 -    if (!sem) {
   9.143 -        return SDL_SetError("Passed a NULL semaphore");
   9.144 -    }
   9.145 -
   9.146 -    if (release_sem(sem->id) != B_NO_ERROR) {
   9.147 -        return SDL_SetError("release_sem() failed");
   9.148 -    }
   9.149 -    return 0;
   9.150 -}
   9.151 -
   9.152 -#endif /* SDL_THREAD_BEOS */
   9.153 -
   9.154 -/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/thread/beos/SDL_systhread.c	Wed Nov 13 21:50:59 2013 -0800
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,126 +0,0 @@
    10.4 -/*
    10.5 -  Simple DirectMedia Layer
    10.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    10.7 -
    10.8 -  This software is provided 'as-is', without any express or implied
    10.9 -  warranty.  In no event will the authors be held liable for any damages
   10.10 -  arising from the use of this software.
   10.11 -
   10.12 -  Permission is granted to anyone to use this software for any purpose,
   10.13 -  including commercial applications, and to alter it and redistribute it
   10.14 -  freely, subject to the following restrictions:
   10.15 -
   10.16 -  1. The origin of this software must not be misrepresented; you must not
   10.17 -     claim that you wrote the original software. If you use this software
   10.18 -     in a product, an acknowledgment in the product documentation would be
   10.19 -     appreciated but is not required.
   10.20 -  2. Altered source versions must be plainly marked as such, and must not be
   10.21 -     misrepresented as being the original software.
   10.22 -  3. This notice may not be removed or altered from any source distribution.
   10.23 -*/
   10.24 -#include "SDL_config.h"
   10.25 -
   10.26 -#ifdef SDL_THREAD_BEOS
   10.27 -
   10.28 -/* BeOS thread management routines for SDL */
   10.29 -
   10.30 -#include <stdio.h>
   10.31 -#include <signal.h>
   10.32 -#include <be/kernel/OS.h>
   10.33 -
   10.34 -#include "SDL_mutex.h"
   10.35 -#include "SDL_thread.h"
   10.36 -#include "../SDL_thread_c.h"
   10.37 -#include "../SDL_systhread.h"
   10.38 -
   10.39 -
   10.40 -static int sig_list[] = {
   10.41 -    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
   10.42 -};
   10.43 -
   10.44 -void
   10.45 -SDL_MaskSignals(sigset_t * omask)
   10.46 -{
   10.47 -    sigset_t mask;
   10.48 -    int i;
   10.49 -
   10.50 -    sigemptyset(&mask);
   10.51 -    for (i = 0; sig_list[i]; ++i) {
   10.52 -        sigaddset(&mask, sig_list[i]);
   10.53 -    }
   10.54 -    sigprocmask(SIG_BLOCK, &mask, omask);
   10.55 -}
   10.56 -
   10.57 -void
   10.58 -SDL_UnmaskSignals(sigset_t * omask)
   10.59 -{
   10.60 -    sigprocmask(SIG_SETMASK, omask, NULL);
   10.61 -}
   10.62 -
   10.63 -static int32
   10.64 -RunThread(void *data)
   10.65 -{
   10.66 -    SDL_RunThread(data);
   10.67 -    return (0);
   10.68 -}
   10.69 -
   10.70 -int
   10.71 -SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
   10.72 -{
   10.73 -    /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
   10.74 -    const char *threadname = thread->name ? thread->name : "SDL Thread";
   10.75 -    char name[B_OS_NAME_LENGTH];
   10.76 -    SDL_snprintf(name, sizeof (name), "%s", threadname);
   10.77 -    name[sizeof (name) - 1] = '\0';
   10.78 -
   10.79 -    /* Create the thread and go! */
   10.80 -    thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
   10.81 -    if ((thread->handle == B_NO_MORE_THREADS) ||
   10.82 -        (thread->handle == B_NO_MEMORY)) {
   10.83 -        return SDL_SetError("Not enough resources to create thread");
   10.84 -    }
   10.85 -    resume_thread(thread->handle);
   10.86 -    return (0);
   10.87 -}
   10.88 -
   10.89 -void
   10.90 -SDL_SYS_SetupThread(const char *name)
   10.91 -{
   10.92 -    /* We set the thread name during SDL_SYS_CreateThread(). */
   10.93 -    /* Mask asynchronous signals for this thread */
   10.94 -    SDL_MaskSignals(NULL);
   10.95 -}
   10.96 -
   10.97 -SDL_threadID
   10.98 -SDL_ThreadID(void)
   10.99 -{
  10.100 -    return ((SDL_threadID) find_thread(NULL));
  10.101 -}
  10.102 -
  10.103 -int
  10.104 -SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
  10.105 -{
  10.106 -    int32 value;
  10.107 -
  10.108 -    if (priority == SDL_THREAD_PRIORITY_LOW) {
  10.109 -        value = B_LOW_PRIORITY;
  10.110 -    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
  10.111 -        value = B_URGENT_DISPLAY_PRIORITY;
  10.112 -    } else {
  10.113 -        value = B_NORMAL_PRIORITY;
  10.114 -    }
  10.115 -    set_thread_priority(find_thread(NULL), value);
  10.116 -    return 0;
  10.117 -}
  10.118 -
  10.119 -void
  10.120 -SDL_SYS_WaitThread(SDL_Thread * thread)
  10.121 -{
  10.122 -    status_t the_status;
  10.123 -
  10.124 -    wait_for_thread(thread->handle, &the_status);
  10.125 -}
  10.126 -
  10.127 -#endif /* SDL_THREAD_BEOS */
  10.128 -
  10.129 -/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/thread/beos/SDL_systhread_c.h	Wed Nov 13 21:50:59 2013 -0800
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,32 +0,0 @@
    11.4 -/*
    11.5 -  Simple DirectMedia Layer
    11.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    11.7 -
    11.8 -  This software is provided 'as-is', without any express or implied
    11.9 -  warranty.  In no event will the authors be held liable for any damages
   11.10 -  arising from the use of this software.
   11.11 -
   11.12 -  Permission is granted to anyone to use this software for any purpose,
   11.13 -  including commercial applications, and to alter it and redistribute it
   11.14 -  freely, subject to the following restrictions:
   11.15 -
   11.16 -  1. The origin of this software must not be misrepresented; you must not
   11.17 -     claim that you wrote the original software. If you use this software
   11.18 -     in a product, an acknowledgment in the product documentation would be
   11.19 -     appreciated but is not required.
   11.20 -  2. Altered source versions must be plainly marked as such, and must not be
   11.21 -     misrepresented as being the original software.
   11.22 -  3. This notice may not be removed or altered from any source distribution.
   11.23 -*/
   11.24 -#include "SDL_config.h"
   11.25 -
   11.26 -#include <signal.h>
   11.27 -#include <be/kernel/OS.h>
   11.28 -
   11.29 -typedef thread_id SYS_ThreadHandle;
   11.30 -
   11.31 -/* Functions needed to work with system threads in other portions of SDL */
   11.32 -extern void SDL_MaskSignals(sigset_t * omask);
   11.33 -extern void SDL_UnmaskSignals(sigset_t * omask);
   11.34 -
   11.35 -/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/thread/beos/SDL_systls.c	Wed Nov 13 21:50:59 2013 -0800
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,70 +0,0 @@
    12.4 -/*
    12.5 -  Simple DirectMedia Layer
    12.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    12.7 -
    12.8 -  This software is provided 'as-is', without any express or implied
    12.9 -  warranty.  In no event will the authors be held liable for any damages
   12.10 -  arising from the use of this software.
   12.11 -
   12.12 -  Permission is granted to anyone to use this software for any purpose,
   12.13 -  including commercial applications, and to alter it and redistribute it
   12.14 -  freely, subject to the following restrictions:
   12.15 -
   12.16 -  1. The origin of this software must not be misrepresented; you must not
   12.17 -     claim that you wrote the original software. If you use this software
   12.18 -     in a product, an acknowledgment in the product documentation would be
   12.19 -     appreciated but is not required.
   12.20 -  2. Altered source versions must be plainly marked as such, and must not be
   12.21 -     misrepresented as being the original software.
   12.22 -  3. This notice may not be removed or altered from any source distribution.
   12.23 -*/
   12.24 -
   12.25 -#include "SDL_config.h"
   12.26 -#include "SDL_thread.h"
   12.27 -#include "../SDL_thread_c.h"
   12.28 -
   12.29 -#if SDL_THREAD_BEOS
   12.30 -
   12.31 -#include <support/TLS.h>
   12.32 -
   12.33 -
   12.34 -static int32 thread_local_storage = B_NO_MEMORY;
   12.35 -static SDL_bool generic_local_storage = SDL_FALSE;
   12.36 -
   12.37 -SDL_TLSData *
   12.38 -SDL_SYS_GetTLSData()
   12.39 -{
   12.40 -    if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
   12.41 -        static SDL_SpinLock lock;
   12.42 -        SDL_AtomicLock(&lock);
   12.43 -        if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
   12.44 -            int32 storage = tls_allocate();
   12.45 -            if (storage != B_NO_MEMORY) {
   12.46 -                SDL_MemoryBarrierRelease();
   12.47 -                thread_local_storage = storage;
   12.48 -            } else {
   12.49 -                generic_local_storage = SDL_TRUE;
   12.50 -            }
   12.51 -        }
   12.52 -        SDL_AtomicUnlock(&lock);
   12.53 -    }
   12.54 -    if (generic_local_storage) {
   12.55 -        return SDL_Generic_GetTLSData();
   12.56 -    }
   12.57 -    SDL_MemoryBarrierAcquire();
   12.58 -    return (SDL_TLSData *)tls_get(thread_local_storage);
   12.59 -}
   12.60 -
   12.61 -int
   12.62 -SDL_SYS_SetTLSData(SDL_TLSData *data)
   12.63 -{
   12.64 -    if (generic_local_storage) {
   12.65 -        return SDL_Generic_SetTLSData(data);
   12.66 -    }
   12.67 -    tls_set(thread_local_storage, data);
   12.68 -    return 0;
   12.69 -}
   12.70 -
   12.71 -#endif /* SDL_THREAD_BEOS */
   12.72 -
   12.73 -/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/thread/pthread/SDL_systhread.c	Wed Nov 13 21:50:59 2013 -0800
    13.2 +++ b/src/thread/pthread/SDL_systhread.c	Wed Nov 13 22:35:26 2013 -0500
    13.3 @@ -51,6 +51,10 @@
    13.4  #include "../../core/android/SDL_android.h"
    13.5  #endif
    13.6  
    13.7 +#ifdef __HAIKU__
    13.8 +#include <be/kernel/OS.h>
    13.9 +#endif
   13.10 +
   13.11  #include "SDL_assert.h"
   13.12  
   13.13  /* List of signals to mask in the subthreads */
   13.14 @@ -59,7 +63,6 @@
   13.15      SIGVTALRM, SIGPROF, 0
   13.16  };
   13.17  
   13.18 -
   13.19  static void *
   13.20  RunThread(void *data)
   13.21  {
   13.22 @@ -129,6 +132,12 @@
   13.23              pthread_setname_np(pthread_self(), name);
   13.24          #elif HAVE_PTHREAD_SET_NAME_NP
   13.25              pthread_set_name_np(pthread_self(), name);
   13.26 +        #elif defined(__HAIKU__)
   13.27 +            /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
   13.28 +            char namebuf[B_OS_NAME_LENGTH];
   13.29 +            SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
   13.30 +            namebuf[sizeof (namebuf) - 1] = '\0';
   13.31 +            rename_thread(find_thread(NULL), namebuf);
   13.32          #endif
   13.33      }
   13.34