Stub code for platforms without functional pthreads.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 25 Jul 2002 17:13:03 +0000
changeset 390 6649d6caecf2
parent 389 b35668cd8b3e
child 391 3111260eb4b4
Stub code for platforms without functional pthreads.
configure.in
platform/unix.c
--- a/configure.in	Thu Jul 25 16:58:00 2002 +0000
+++ b/configure.in	Thu Jul 25 17:13:03 2002 +0000
@@ -195,6 +195,17 @@
 fi
 
 
+dnl determine if we should use the stubbed pthread code.
+AC_ARG_ENABLE(pthreads,
+[  --enable-pthreads          include POSIX threads support [default=yes]],
+              , enable_pthreads=yes)
+if test x$enable_pthreads = xyes; then
+  AC_CHECK_HEADER(pthread.h, have_pthread_hdr=yes)
+  if test x$have_pthread_hdr != xyes; then
+    enable_pthreads=no
+  fi
+fi
+
 dnl determine if we should use the stubbed CD-ROM detection code.
 AC_ARG_ENABLE(cdrom,
 [  --enable-cdrom             include CD-ROM support [default=yes]],
@@ -218,10 +229,14 @@
   fi
 fi
 
+have_non_posix_threads=no
+
 dnl AC_CHECK_HEADER(be/kernel/OS.h, this_is_beos=yes)
 AC_MSG_CHECKING([if this is BeOS])
 if test x$build_os = xbeos; then
   this_is_beos=yes
+  enable_pthreads=no
+  have_non_posix_threads=yes
   LIBS="$LIBS -lroot -lbe"
 else
   this_is_beos=no
@@ -233,6 +248,8 @@
 if test x$build_os = xcygwin; then
   this_is_cygwin=yes
   CFLAGS="$CFLAGS -DWIN32"
+  enable_pthreads=no
+  have_non_posix_threads=yes
 else
   this_is_cygwin=no
 fi
@@ -281,7 +298,7 @@
   if test x$x = xatheos; then
     this_is_atheos=yes
     enable_cdrom=no
-    LDFLAGS="$LDFLAGS -lpthread"
+    enable_pthreads=no
   fi
 
   AC_MSG_RESULT([$this_is_atheos])
@@ -292,11 +309,26 @@
   AC_DEFINE([PHYSFS_NO_CDROM_SUPPORT], 1, [define if we have no CD support])
   AC_MSG_WARN([***])
   AC_MSG_WARN([*** There is no CD-ROM support in this build!])
-  AC_MSG_WARN([*** PhysicsFS will just pretend there are no discs!])
-  AC_MSG_WARN([*** Is this what you really wanted?])
+  AC_MSG_WARN([*** PhysicsFS will just pretend there are no discs.])
+  AC_MSG_WARN([*** This may be fine, depending on how PhysicsFS is used,])
+  AC_MSG_WARN([***   but is this what you REALLY wanted?])
+  AC_MSG_WARN([*** (Maybe fix configure.in, or write a platform driver?)])
   AC_MSG_WARN([***])
 fi
 
+if test x$enable_pthreads != xyes; then
+  AC_DEFINE([PHYSFS_NO_PTHREADS_SUPPORT], 1, [define if we have no POSIX threads support])
+  if test x$have_non_posix_threads != xyes; then
+    AC_MSG_WARN([***])
+    AC_MSG_WARN([*** There is no thread support in this build!])
+    AC_MSG_WARN([*** PhysicsFS will NOT be reentrant!])
+    AC_MSG_WARN([*** This may be fine, depending on how PhysicsFS is used,])
+    AC_MSG_WARN([***   but is this what you REALLY wanted?])
+    AC_MSG_WARN([*** (Maybe fix configure.in, or write a platform driver?)])
+    AC_MSG_WARN([***])
+  fi
+fi
+
 
 # Checks for header files.
 AC_HEADER_STDC
--- a/platform/unix.c	Thu Jul 25 16:58:00 2002 +0000
+++ b/platform/unix.c	Thu Jul 25 17:13:03 2002 +0000
@@ -17,7 +17,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include <pthread.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <pwd.h>
@@ -28,6 +27,10 @@
 #include <errno.h>
 #include <sys/mount.h>
 
+#if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
+#include <pthread.h>
+#endif
+
 #ifdef PHYSFS_HAVE_SYS_UCRED_H
 #  ifdef PHYSFS_HAVE_MNTENT_H
 #    undef PHYSFS_HAVE_MNTENT_H /* don't do both... */
@@ -256,12 +259,6 @@
 } /* __PHYSFS_platformCalcBaseDir */
 
 
-PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
-{
-    return((PHYSFS_uint64) pthread_self());
-} /* __PHYSFS_platformGetThreadID */
-
-
 /* Much like my college days, try to sleep for 10 milliseconds at a time... */
 void __PHYSFS_platformTimeslice(void)
 {
@@ -283,6 +280,22 @@
 } /* __PHYSFS_platformRealPath */
 
 
+#if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
+
+PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) { return(0x0001); }
+void *__PHYSFS_platformCreateMutex(void) { return((void *) 0x0001); }
+void __PHYSFS_platformDestroyMutex(void *mutex) {}
+int __PHYSFS_platformGrabMutex(void *mutex) { return(1); }
+void __PHYSFS_platformReleaseMutex(void *mutex) {}
+
+#else
+
+PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
+{
+    return((PHYSFS_uint64) pthread_self());
+} /* __PHYSFS_platformGetThreadID */
+
+
 void *__PHYSFS_platformCreateMutex(void)
 {
     int rc;
@@ -317,6 +330,9 @@
     pthread_mutex_unlock((pthread_mutex_t *) mutex);
 } /* __PHYSFS_platformReleaseMutex */
 
+#endif /* !PHYSFS_NO_PTHREADS_SUPPORT */
+
+
 #endif /* !defined __BEOS__ && !defined WIN32 */
 
 /* end of unix.c ... */