Added support for the GNU Pth thread lib (thanks Mandin!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Sep 2001 04:34:15 +0000
changeset 18534d316d5e744
parent 184 3142d2ac11db
child 186 2529d3d711e6
Added support for the GNU Pth thread lib (thanks Mandin!)
configure.in
docs.html
src/thread/Makefile.am
src/thread/pth/SDL_systhread.c
src/thread/pth/SDL_systhread_c.h
     1.1 --- a/configure.in	Fri Sep 14 04:33:01 2001 +0000
     1.2 +++ b/configure.in	Fri Sep 14 04:34:15 2001 +0000
     1.3 @@ -1131,6 +1131,33 @@
     1.4      AM_CONDITIONAL(USE_CLONE, test x$use_clone = xyes)
     1.5  }
     1.6  
     1.7 +dnl See if we can use GNU pth library for threads
     1.8 +CheckPTH()
     1.9 +{
    1.10 +    dnl Check for pth support
    1.11 +    AC_ARG_ENABLE(pth,
    1.12 +[  --enable-pth            use GNU pth library for multi-threading [default=yes]],
    1.13 +                  , enable_pth=yes)
    1.14 +    if test x$enable_threads = xyes -a x$enable_pth = xyes; then
    1.15 +        AC_PATH_PROG(PTH_CONFIG, pth-config, no)
    1.16 +        if test "$PTH_CONFIG" = "no"; then
    1.17 +            use_pth=no
    1.18 +        else
    1.19 +            PTH_CFLAGS=`$PTH_CONFIG --cflags`
    1.20 +            PTH_LIBS=`$PTH_CONFIG --libs`
    1.21 +            SDL_CFLAGS="$SDL_CFLAGS $PTH_CFLAGS"
    1.22 +            SDL_LIBS="$SDL_LIBS $PTH_LIBS"
    1.23 +            use_pth=yes
    1.24 +        fi
    1.25 +        AC_MSG_CHECKING(pth)
    1.26 +        if test "x$use_pth" = xyes; then
    1.27 +            AC_MSG_RESULT(yes)
    1.28 +        else
    1.29 +            AC_MSG_RESULT(no)
    1.30 +        fi
    1.31 +    fi
    1.32 +}
    1.33 +
    1.34  dnl Determine whether the compiler can produce Win32 executables
    1.35  CheckWIN32()
    1.36  {
     2.1 --- a/docs.html	Fri Sep 14 04:33:01 2001 +0000
     2.2 +++ b/docs.html	Fri Sep 14 04:34:15 2001 +0000
     2.3 @@ -16,6 +16,8 @@
     2.4  Major changes since SDL 1.0.0:
     2.5  </H2>
     2.6  <UL>
     2.7 +	<LI> 1.2.3: Added support for the GNU Pth thread lib (thanks Mandin!)
     2.8 +	<LI> 1.2.3: Added the Undo key for the Atari keyboard (thanks Mandin!)
     2.9  	<LI> 1.2.3: Fixed XVideo on GeForce by using last available adaptor
    2.10  	<LI> 1.2.3: Added CD-ROM support for BSD/OS (thanks Steven!)
    2.11  	<LI> 1.2.3: Added library version information to the Windows DLL
     3.1 --- a/src/thread/Makefile.am	Fri Sep 14 04:33:01 2001 +0000
     3.2 +++ b/src/thread/Makefile.am	Fri Sep 14 04:34:15 2001 +0000
     3.3 @@ -3,12 +3,13 @@
     3.4  
     3.5  noinst_LTLIBRARIES = libthread.la
     3.6  
     3.7 -ARCH_SUBDIRS = $(srcdir)/generic \
     3.8 -               $(srcdir)/amigaos \
     3.9 -               $(srcdir)/beos \
    3.10 -               $(srcdir)/epoc \
    3.11 -               $(srcdir)/irix \
    3.12 -               $(srcdir)/linux \
    3.13 +ARCH_SUBDIRS = $(srcdir)/generic	\
    3.14 +               $(srcdir)/amigaos	\
    3.15 +               $(srcdir)/beos		\
    3.16 +               $(srcdir)/epoc		\
    3.17 +               $(srcdir)/irix		\
    3.18 +               $(srcdir)/linux		\
    3.19 +               $(srcdir)/pth		\
    3.20                 $(srcdir)/win32
    3.21  
    3.22  # Older versions of Linux require an asm clone() implementation
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/thread/pth/SDL_systhread.c	Fri Sep 14 04:34:15 2001 +0000
     4.3 @@ -0,0 +1,102 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@devolution.com
    4.24 +*/
    4.25 +
    4.26 +#ifdef SAVE_RCSID
    4.27 +static char rcsid =
    4.28 + "@(#) $Id$";
    4.29 +#endif
    4.30 +
    4.31 +/* Pth thread management routines for SDL */
    4.32 +
    4.33 +#include "SDL_error.h"
    4.34 +#include "SDL_thread.h"
    4.35 +#include "SDL_systhread.h"
    4.36 +
    4.37 +#include <signal.h>
    4.38 +#include <pth.h>
    4.39 +
    4.40 +/* List of signals to mask in the subthreads */
    4.41 +static int sig_list[] = {
    4.42 +	SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
    4.43 +	SIGVTALRM, SIGPROF, 0
    4.44 +};
    4.45 +
    4.46 +static void *RunThread(void *data)
    4.47 +{
    4.48 +	SDL_RunThread(data);
    4.49 +	pth_exit((void*)0);
    4.50 +	return((void *)0);		/* Prevent compiler warning */
    4.51 +}
    4.52 +
    4.53 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
    4.54 +{
    4.55 +	pth_attr_t type;
    4.56 +
    4.57 +	/* Set the thread attributes */
    4.58 +	if ( pth_attr_init(&type) != 0 ) {
    4.59 +		SDL_SetError("Couldn't initialize pth attributes");
    4.60 +		return(-1);
    4.61 +	}
    4.62 +	pth_attr_set(&type, PTH_ATTR_JOINABLE, TRUE);
    4.63 +
    4.64 +	/* Create the thread and go! */
    4.65 +	if ( pth_spawn( &type, RunThread, args) != 0 ) {
    4.66 +		SDL_SetError("Not enough resources to create thread");
    4.67 +		return(-1);
    4.68 +	}
    4.69 +	return(0);
    4.70 +}
    4.71 +
    4.72 +void SDL_SYS_SetupThread(void)
    4.73 +{
    4.74 +	int i;
    4.75 +	sigset_t mask;
    4.76 +
    4.77 +	/* Mask asynchronous signals for this thread */
    4.78 +	sigemptyset(&mask);
    4.79 +	for ( i=0; sig_list[i]; ++i ) {
    4.80 +		sigaddset(&mask, sig_list[i]);
    4.81 +	}
    4.82 +	pth_sigmask(SIG_BLOCK, &mask, 0);
    4.83 +
    4.84 +	/* Allow ourselves to be asynchronously cancelled */
    4.85 +	{ int oldstate;
    4.86 +		pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
    4.87 +	}
    4.88 +}
    4.89 +
    4.90 +/* WARNING:  This may not work for systems with 64-bit pid_t */
    4.91 +Uint32 SDL_ThreadID(void)
    4.92 +{
    4.93 +	return((Uint32)pth_self());
    4.94 +}
    4.95 +
    4.96 +void SDL_SYS_WaitThread(SDL_Thread *thread)
    4.97 +{
    4.98 +	pth_join(thread->handle, 0);
    4.99 +}
   4.100 +
   4.101 +void SDL_SYS_KillThread(SDL_Thread *thread)
   4.102 +{
   4.103 +	pth_cancel(thread->handle);
   4.104 +	pth_join(thread->handle, NULL);
   4.105 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/thread/pth/SDL_systhread_c.h	Fri Sep 14 04:34:15 2001 +0000
     5.3 @@ -0,0 +1,25 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Library General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Library General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Library General Public
    5.19 +    License along with this library; if not, write to the Free
    5.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@devolution.com
    5.24 +*/
    5.25 +
    5.26 +#include <pth.h>
    5.27 +
    5.28 +typedef pth_t SYS_ThreadHandle;