diff --git a/CMakeLists.txt b/CMakeLists.txt index 489421f27..a66a1ad24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1012,6 +1012,8 @@ elseif(BEOS) set(HAVE_VIDEO_OPENGL TRUE) endif(VIDEO_OPENGL) endif(SDL_VIDEO) + + CheckPTHREAD() endif() # Dummies diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake index fe763785c..f71ad906e 100644 --- a/cmake/sdlchecks.cmake +++ b/cmake/sdlchecks.cmake @@ -638,6 +638,9 @@ macro(CheckPTHREAD) elseif(HPUX) set(PTHREAD_CFLAGS "-D_REENTRANT") set(PTHREAD_LDFLAGS "-L/usr/lib -pthread") + elseif(BEOS) + set(PTHREAD_CFLAGS "-D_REENTRANT") + set(PTHREAD_LDFLAGS "") else() set(PTHREAD_CFLAGS "-D_REENTRANT") set(PTHREAD_LDFLAGS "-lpthread") diff --git a/configure b/configure index ba2489430..a441a3e13 100755 --- a/configure +++ b/configure @@ -21006,6 +21006,10 @@ fi pthread_cflags="-D_REENTRANT" pthread_lib="-L/usr/lib -lpthread" ;; + *-*-haiku*) + pthread_cflags="-D_REENTRANT" + pthread_lib="" + ;; *) pthread_cflags="-D_REENTRANT" pthread_lib="-lpthread" @@ -22394,7 +22398,9 @@ fi SDL_LIBS="-lcygwin $SDL_LIBS" fi ;; - *-*-beos* | *-*-haiku*) + + + *-*-haiku*) ARCH=beos ac_default_prefix=/boot/common CheckDummyVideo @@ -22402,6 +22408,7 @@ fi CheckDummyAudio CheckBWINDOW CheckBeGL + CheckPTHREAD # Set up files for the audio library if test x$enable_audio = xyes; then @@ -22418,16 +22425,6 @@ $as_echo "#define SDL_JOYSTICK_BEOS 1" >>confdefs.h SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc" have_joystick=yes fi - # Set up files for the thread library - if test x$enable_threads = xyes; then - -$as_echo "#define SDL_THREAD_BEOS 1" >>confdefs.h - - SOURCES="$SOURCES $srcdir/src/thread/beos/*.c" - SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_sysmutex.c" - SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_syscond.c" - have_threads=yes - fi # Set up files for the timer library if test x$enable_timers = xyes; then diff --git a/configure.in b/configure.in index 5c56f0080..87513fe92 100644 --- a/configure.in +++ b/configure.in @@ -1940,6 +1940,10 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]) pthread_cflags="-D_REENTRANT" pthread_lib="-L/usr/lib -lpthread" ;; + *-*-haiku*) + pthread_cflags="-D_REENTRANT" + pthread_lib="" + ;; *) pthread_cflags="-D_REENTRANT" pthread_lib="-lpthread" @@ -2613,7 +2617,11 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau SDL_LIBS="-lcygwin $SDL_LIBS" fi ;; - *-*-beos* | *-*-haiku*) + + dnl BeOS support removed after SDL 2.0.1. Haiku still works. --ryan. + dnl *-*-beos*) + + *-*-haiku*) ARCH=beos ac_default_prefix=/boot/common CheckDummyVideo @@ -2621,6 +2629,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau CheckDummyAudio CheckBWINDOW CheckBeGL + CheckPTHREAD # Set up files for the audio library if test x$enable_audio = xyes; then AC_DEFINE(SDL_AUDIO_DRIVER_BEOSAUDIO, 1, [ ]) @@ -2633,14 +2642,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc" have_joystick=yes fi - # Set up files for the thread library - if test x$enable_threads = xyes; then - AC_DEFINE(SDL_THREAD_BEOS, 1, [ ]) - SOURCES="$SOURCES $srcdir/src/thread/beos/*.c" - SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_sysmutex.c" - SOURCES="$SOURCES $srcdir/src/thread/generic/SDL_syscond.c" - have_threads=yes - fi # Set up files for the timer library if test x$enable_timers = xyes; then AC_DEFINE(SDL_TIMER_BEOS, 1, [ ]) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 66107e49e..2f1137643 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -237,7 +237,6 @@ #cmakedefine SDL_LOADSO_WINDOWS @SDL_LOADSO_WINDOWS@ /* Enable various threading systems */ -#cmakedefine SDL_THREAD_BEOS @SDL_THREAD_BEOS@ #cmakedefine SDL_THREAD_PTHREAD @SDL_THREAD_PTHREAD@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX@ #cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP@ diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index b2daf6fa3..5f41e1bbb 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -240,7 +240,6 @@ #undef SDL_LOADSO_WINDOWS /* Enable various threading systems */ -#undef SDL_THREAD_BEOS #undef SDL_THREAD_PTHREAD #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX #undef SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP diff --git a/src/audio/baudio/SDL_beaudio.cc b/src/audio/baudio/SDL_beaudio.cc index e2edf85fb..86fb78153 100644 --- a/src/audio/baudio/SDL_beaudio.cc +++ b/src/audio/baudio/SDL_beaudio.cc @@ -25,6 +25,7 @@ /* Allow access to the audio stream on BeOS */ #include +#include #include "../../main/beos/SDL_BeApp.h" @@ -85,6 +86,31 @@ BEOSAUDIO_CloseDevice(_THIS) } } + +static const int sig_list[] = { + SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0 +}; + +static inline void +MaskSignals(sigset_t * omask) +{ + sigset_t mask; + int i; + + sigemptyset(&mask); + for (i = 0; sig_list[i]; ++i) { + sigaddset(&mask, sig_list[i]); + } + sigprocmask(SIG_BLOCK, &mask, omask); +} + +static inline void +UnmaskSignals(sigset_t * omask) +{ + sigprocmask(SIG_SETMASK, omask, NULL); +} + + static int BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) { @@ -162,10 +188,10 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) /* Subscribe to the audio stream (creates a new thread) */ sigset_t omask; - SDL_MaskSignals(&omask); + MaskSignals(&omask); _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound, NULL, _this); - SDL_UnmaskSignals(&omask); + UnmaskSignals(&omask); if (_this->hidden->audio_obj->Start() == B_NO_ERROR) { _this->hidden->audio_obj->SetHasData(true); diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index c7b063e07..4fe925494 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -28,10 +28,6 @@ /* Need the definitions of SYS_ThreadHandle */ #if SDL_THREADS_DISABLED #include "generic/SDL_systhread_c.h" -#elif SDL_THREAD_BEOS -#include "beos/SDL_systhread_c.h" -#elif SDL_THREAD_EPOC -#include "epoc/SDL_systhread_c.h" #elif SDL_THREAD_PTHREAD #include "pthread/SDL_systhread_c.h" #elif SDL_THREAD_WINDOWS diff --git a/src/thread/beos/SDL_syssem.c b/src/thread/beos/SDL_syssem.c deleted file mode 100644 index 9661f9012..000000000 --- a/src/thread/beos/SDL_syssem.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifdef SDL_THREAD_BEOS - -/* Semaphores in the BeOS environment */ - -#include - -#include "SDL_thread.h" - - -struct SDL_semaphore -{ - sem_id id; -}; - -/* Create a counting semaphore */ -SDL_sem * -SDL_CreateSemaphore(Uint32 initial_value) -{ - SDL_sem *sem; - - sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); - if (sem) { - sem->id = create_sem(initial_value, "SDL semaphore"); - if (sem->id < B_NO_ERROR) { - SDL_SetError("create_sem() failed"); - SDL_free(sem); - sem = NULL; - } - } else { - SDL_OutOfMemory(); - } - return (sem); -} - -/* Free the semaphore */ -void -SDL_DestroySemaphore(SDL_sem * sem) -{ - if (sem) { - if (sem->id >= B_NO_ERROR) { - delete_sem(sem->id); - } - SDL_free(sem); - } -} - -int -SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) -{ - int32 val; - int retval; - - if (!sem) { - return SDL_SetError("Passed a NULL semaphore"); - } - - tryagain: - if (timeout == SDL_MUTEX_MAXWAIT) { - val = acquire_sem(sem->id); - } else { - timeout *= 1000; /* BeOS uses a timeout in microseconds */ - val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout); - } - switch (val) { - case B_INTERRUPTED: - goto tryagain; - case B_NO_ERROR: - retval = 0; - break; - case B_TIMED_OUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case B_WOULD_BLOCK: - retval = SDL_MUTEX_TIMEDOUT; - break; - default: - retval = SDL_SetError("acquire_sem() failed"); - break; - } - - return retval; -} - -int -SDL_SemTryWait(SDL_sem * sem) -{ - return SDL_SemWaitTimeout(sem, 0); -} - -int -SDL_SemWait(SDL_sem * sem) -{ - return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); -} - -/* Returns the current count of the semaphore */ -Uint32 -SDL_SemValue(SDL_sem * sem) -{ - int32 count; - Uint32 value; - - value = 0; - if (sem) { - get_sem_count(sem->id, &count); - if (count > 0) { - value = (Uint32) count; - } - } - return value; -} - -/* Atomically increases the semaphore's count (not blocking) */ -int -SDL_SemPost(SDL_sem * sem) -{ - if (!sem) { - return SDL_SetError("Passed a NULL semaphore"); - } - - if (release_sem(sem->id) != B_NO_ERROR) { - return SDL_SetError("release_sem() failed"); - } - return 0; -} - -#endif /* SDL_THREAD_BEOS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_systhread.c b/src/thread/beos/SDL_systhread.c deleted file mode 100644 index 11646f974..000000000 --- a/src/thread/beos/SDL_systhread.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#ifdef SDL_THREAD_BEOS - -/* BeOS thread management routines for SDL */ - -#include -#include -#include - -#include "SDL_mutex.h" -#include "SDL_thread.h" -#include "../SDL_thread_c.h" -#include "../SDL_systhread.h" - - -static int sig_list[] = { - SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0 -}; - -void -SDL_MaskSignals(sigset_t * omask) -{ - sigset_t mask; - int i; - - sigemptyset(&mask); - for (i = 0; sig_list[i]; ++i) { - sigaddset(&mask, sig_list[i]); - } - sigprocmask(SIG_BLOCK, &mask, omask); -} - -void -SDL_UnmaskSignals(sigset_t * omask) -{ - sigprocmask(SIG_SETMASK, omask, NULL); -} - -static int32 -RunThread(void *data) -{ - SDL_RunThread(data); - return (0); -} - -int -SDL_SYS_CreateThread(SDL_Thread * thread, void *args) -{ - /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */ - const char *threadname = thread->name ? thread->name : "SDL Thread"; - char name[B_OS_NAME_LENGTH]; - SDL_snprintf(name, sizeof (name), "%s", threadname); - name[sizeof (name) - 1] = '\0'; - - /* Create the thread and go! */ - thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args); - if ((thread->handle == B_NO_MORE_THREADS) || - (thread->handle == B_NO_MEMORY)) { - return SDL_SetError("Not enough resources to create thread"); - } - resume_thread(thread->handle); - return (0); -} - -void -SDL_SYS_SetupThread(const char *name) -{ - /* We set the thread name during SDL_SYS_CreateThread(). */ - /* Mask asynchronous signals for this thread */ - SDL_MaskSignals(NULL); -} - -SDL_threadID -SDL_ThreadID(void) -{ - return ((SDL_threadID) find_thread(NULL)); -} - -int -SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) -{ - int32 value; - - if (priority == SDL_THREAD_PRIORITY_LOW) { - value = B_LOW_PRIORITY; - } else if (priority == SDL_THREAD_PRIORITY_HIGH) { - value = B_URGENT_DISPLAY_PRIORITY; - } else { - value = B_NORMAL_PRIORITY; - } - set_thread_priority(find_thread(NULL), value); - return 0; -} - -void -SDL_SYS_WaitThread(SDL_Thread * thread) -{ - status_t the_status; - - wait_for_thread(thread->handle, &the_status); -} - -#endif /* SDL_THREAD_BEOS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_systhread_c.h b/src/thread/beos/SDL_systhread_c.h deleted file mode 100644 index a350ab594..000000000 --- a/src/thread/beos/SDL_systhread_c.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_config.h" - -#include -#include - -typedef thread_id SYS_ThreadHandle; - -/* Functions needed to work with system threads in other portions of SDL */ -extern void SDL_MaskSignals(sigset_t * omask); -extern void SDL_UnmaskSignals(sigset_t * omask); - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/beos/SDL_systls.c b/src/thread/beos/SDL_systls.c deleted file mode 100644 index 8e941289a..000000000 --- a/src/thread/beos/SDL_systls.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2013 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "SDL_config.h" -#include "SDL_thread.h" -#include "../SDL_thread_c.h" - -#if SDL_THREAD_BEOS - -#include - - -static int32 thread_local_storage = B_NO_MEMORY; -static SDL_bool generic_local_storage = SDL_FALSE; - -SDL_TLSData * -SDL_SYS_GetTLSData() -{ - if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) { - static SDL_SpinLock lock; - SDL_AtomicLock(&lock); - if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) { - int32 storage = tls_allocate(); - if (storage != B_NO_MEMORY) { - SDL_MemoryBarrierRelease(); - thread_local_storage = storage; - } else { - generic_local_storage = SDL_TRUE; - } - } - SDL_AtomicUnlock(&lock); - } - if (generic_local_storage) { - return SDL_Generic_GetTLSData(); - } - SDL_MemoryBarrierAcquire(); - return (SDL_TLSData *)tls_get(thread_local_storage); -} - -int -SDL_SYS_SetTLSData(SDL_TLSData *data) -{ - if (generic_local_storage) { - return SDL_Generic_SetTLSData(data); - } - tls_set(thread_local_storage, data); - return 0; -} - -#endif /* SDL_THREAD_BEOS */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index c967ca7f3..f9eaef273 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -51,6 +51,10 @@ #include "../../core/android/SDL_android.h" #endif +#ifdef __HAIKU__ +#include +#endif + #include "SDL_assert.h" /* List of signals to mask in the subthreads */ @@ -59,7 +63,6 @@ static const int sig_list[] = { SIGVTALRM, SIGPROF, 0 }; - static void * RunThread(void *data) { @@ -129,6 +132,12 @@ SDL_SYS_SetupThread(const char *name) pthread_setname_np(pthread_self(), name); #elif HAVE_PTHREAD_SET_NAME_NP pthread_set_name_np(pthread_self(), name); + #elif defined(__HAIKU__) + /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */ + char namebuf[B_OS_NAME_LENGTH]; + SDL_snprintf(namebuf, sizeof (namebuf), "%s", name); + namebuf[sizeof (namebuf) - 1] = '\0'; + rename_thread(find_thread(NULL), namebuf); #endif }