[PATCH] fix tdb spinlocks on IRIX

James Peach jpeach at sgi.com
Tue Dec 9 07:00:44 GMT 2003


Hi all,

The following patch against CVS-HEAD implements tdb spinlocks for those
compiling Samba on IRIX with the MIPSPro compilers.

The current MIPS spinlock implementation uses gcc asm syntax. I've left this
alone for people building with gcc. I've also added configure and runtime
checks for the number of CPUs, so multiprocessor machines are detected
correctly (at least on IRIX).

I've recorded this in bugzilla as bug #865.

cheers

--
James Peach | jpeach at sgi.com 


Index: samba/source/configure.in
===================================================================
RCS file: /cvsroot/samba/source/configure.in,v
retrieving revision 1.300.2.192
diff -u -r1.300.2.192 configure.in
--- samba/source/configure.in	27 Nov 2003 05:11:14 -0000	1.300.2.192
+++ samba/source/configure.in	9 Dec 2003 05:56:22 -0000
@@ -1993,6 +1993,14 @@
     AC_DEFINE(SYSCONF_SC_NGROUPS_MAX,1,[Whether sysconf(_SC_NGROUPS_MAX) is available])
 fi
 
+AC_CACHE_CHECK([for sysconf(_SC_NPROC_ONLN)],samba_cv_SYSCONF_SC_NPROC_ONLN,[
+AC_TRY_RUN([#include <unistd.h>
+main() { exit(sysconf(_SC_NPROC_ONLN) == -1 ? 1 : 0); }],
+samba_cv_SYSCONF_SC_NPROC_ONLN=yes,samba_cv_SYSCONF_SC_NPROC_ONLN=no,samba_cv_SYSCONF_SC_NPROC_ONLN=cross)])
+if test x"$samba_cv_SYSCONF_SC_NPROC_ONLN" = x"yes"; then
+    AC_DEFINE(SYSCONF_SC_NPROC_ONLN,1,[Whether sysconf(_SC_NPROC_ONLN) is available])
+fi
+
 AC_CACHE_CHECK([for root],samba_cv_HAVE_ROOT,[
 AC_TRY_RUN([main() { exit(getuid() != 0); }],
            samba_cv_HAVE_ROOT=yes,samba_cv_HAVE_ROOT=no,samba_cv_HAVE_ROOT=cross)])
Index: samba/source/tdb/spinlock.c
===================================================================
RCS file: /cvsroot/samba/source/tdb/spinlock.c,v
retrieving revision 1.6.2.2
diff -u -r1.6.2.2 spinlock.c
--- samba/source/tdb/spinlock.c	18 Oct 2003 08:52:16 -0000	1.6.2.2
+++ samba/source/tdb/spinlock.c	9 Dec 2003 05:56:23 -0000
@@ -143,6 +143,47 @@
 	return (*lock != 1);
 }
 
+#elif defined(MIPS_SPINLOCKS) && defined(sgi) && (_COMPILER_VERSION >= 730)
+
+/* Implement spinlocks on IRIX using the MIPSPro atomic fetch operations. See
+ * sync(3) for the details of the intrinsic operations.
+ *
+ * "sgi" and "_COMPILER_VERSION" are always defined by MIPSPro.
+ */
+
+#if defined(STANDALONE)
+
+/* MIPSPro 7.3 has "__inline" as an extension, but not "inline. */
+#define inline __inline
+
+#endif /* STANDALONE */
+
+/* Returns 0 if the lock is acquired, EBUSY otherwise. */
+static inline int __spin_trylock(spinlock_t *lock)
+{
+        unsigned int val;
+        val = __lock_test_and_set(lock, 1);
+        return val == 0 ? 0 : EBUSY;
+}
+
+static inline void __spin_unlock(spinlock_t *lock)
+{
+        __lock_release(lock);
+}
+
+static inline void __spin_lock_init(spinlock_t *lock)
+{
+        __lock_release(lock);
+}
+
+/* Returns 1 if the lock is held, 0 otherwise. */
+static inline int __spin_is_locked(spinlock_t *lock)
+{
+        unsigned int val;
+        val = __add_and_fetch(lock, 0);
+	return val;
+}
+
 #elif defined(MIPS_SPINLOCKS) 
 
 static inline unsigned int load_linked(unsigned long addr)
@@ -221,7 +262,11 @@
 
 static int this_is_smp(void)
 {
+#if defined(HAVE_SYSCONF) && defined(SYSCONF_SC_NPROC_ONLN)
+        return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
+#else
 	return 0;
+#endif
 }
 
 /*



More information about the samba-technical mailing list