]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - db2/mutex/mutex.c
Update.
[thirdparty/glibc.git] / db2 / mutex / mutex.c
index 5315b2d3fe7f54ef02da5fd59cee10246266f80b..6dca3231138b657efbfccfb5ceef5a3f1ee3c5f5 100644 (file)
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)mutex.c      10.25 (Sleepycat) 9/23/97";
+static const char sccsid[] = "@(#)mutex.c      10.32 (Sleepycat) 1/16/98";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -67,6 +67,10 @@ static const char sccsid[] = "@(#)mutex.c    10.25 (Sleepycat) 9/23/97";
 #define        TSL_UNSET(x)    _lock_clear(x)
 #endif
 
+#ifdef HAVE_ASSEM_SCO_CC
+#include "sco.cc"
+#endif
+
 #ifdef HAVE_ASSEM_SPARC_GCC
 #include "sparc.gcc"
 #endif
@@ -97,22 +101,16 @@ static const char sccsid[] = "@(#)mutex.c  10.25 (Sleepycat) 9/23/97";
 
 #endif /* HAVE_SPINLOCKS */
 
-#ifdef MORE_THAN_ONE_PROCESSOR
-#define        TSL_DEFAULT_SPINS       5       /* Default spins before block. */
-#else
-#define        TSL_DEFAULT_SPINS       1       /* Default spins before block. */
-#endif
-
 /*
  * __db_mutex_init --
  *     Initialize a DB mutex structure.
  *
- * PUBLIC: void __db_mutex_init __P((db_mutex_t *, off_t));
+ * PUBLIC: void __db_mutex_init __P((db_mutex_t *, u_int32_t));
  */
 void
 __db_mutex_init(mp, off)
        db_mutex_t *mp;
-       off_t off;
+       u_int32_t off;
 {
 #ifdef DEBUG
        if ((ALIGNTYPE)mp & (MUTEX_ALIGNMENT - 1)) {
@@ -125,7 +123,10 @@ __db_mutex_init(mp, off)
        memset(mp, 0, sizeof(db_mutex_t));
 
 #ifdef HAVE_SPINLOCKS
+       COMPQUIET(off, 0);
+
        TSL_INIT(&mp->tsl_resource);
+       mp->spins = __os_spin();
 #else
        mp->off = off;
 #endif
@@ -138,25 +139,23 @@ __db_mutex_init(mp, off)
  * __db_mutex_lock
  *     Lock on a mutex, logically blocking if necessary.
  *
- * PUBLIC: int __db_mutex_lock __P((db_mutex_t *, int, int (*)(void)));
+ * PUBLIC: int __db_mutex_lock __P((db_mutex_t *, int));
  */
 int
-__db_mutex_lock(mp, fd, yield)
+__db_mutex_lock(mp, fd)
        db_mutex_t *mp;
        int fd;
-       int (*yield) __P((void));
 {
        u_long usecs;
 
 #ifdef HAVE_SPINLOCKS
        int nspins;
 
+       COMPQUIET(fd, 0);
+
        for (usecs = MS(10);;) {
-               /*
-                * Try and acquire the uncontested resource lock for
-                * TSL_DEFAULT_SPINS.
-                */
-               for (nspins = TSL_DEFAULT_SPINS; nspins > 0; --nspins)
+               /* Try and acquire the uncontested resource lock for N spins. */
+               for (nspins = mp->spins; nspins > 0; --nspins)
                        if (TSL_SET(&mp->tsl_resource)) {
 #ifdef DEBUG
                                if (mp->pid != 0) {
@@ -166,17 +165,15 @@ __db_mutex_lock(mp, fd, yield)
                                }
                                mp->pid = getpid();
 #endif
-#ifdef MUTEX_STATISTICS
                                if (usecs == MS(10))
                                        ++mp->mutex_set_nowait;
                                else
                                        ++mp->mutex_set_wait;
-#endif
                                return (0);
                        }
 
                /* Yield the processor; wait 10ms initially, up to 1 second. */
-               if (yield == NULL || yield() != 0) {
+               if (__db_yield == NULL || __db_yield() != 0) {
                        (void)__db_sleep(0, usecs);
                        if ((usecs <<= 1) > SECOND)
                                usecs = SECOND;
@@ -200,7 +197,7 @@ __db_mutex_lock(mp, fd, yield)
                 * up to 1 second.
                 */
                for (usecs = MS(10); mp->pid != 0;)
-                       if (yield == NULL || yield() != 0) {
+                       if (__db_yield == NULL || __db_yield() != 0) {
                                (void)__db_sleep(0, usecs);
                                if ((usecs <<= 1) > SECOND)
                                        usecs = SECOND;
@@ -209,7 +206,7 @@ __db_mutex_lock(mp, fd, yield)
                /* Acquire an exclusive kernel lock. */
                k_lock.l_type = F_WRLCK;
                if (fcntl(fd, F_SETLKW, &k_lock))
-                       return (1);
+                       return (errno);
 
                /* If the resource tsl is still available, it's ours. */
                if (mp->pid == 0) {
@@ -220,7 +217,7 @@ __db_mutex_lock(mp, fd, yield)
                /* Release the kernel lock. */
                k_lock.l_type = F_UNLCK;
                if (fcntl(fd, F_SETLK, &k_lock))
-                       return (1);
+                       return (errno);
 
                /*
                 * If we got the resource tsl we're done.
@@ -234,10 +231,6 @@ __db_mutex_lock(mp, fd, yield)
                if (locked)
                        break;
        }
-
-#ifdef MUTEX_STATISTICS
-       ++mp->mutex_set_wait;
-#endif
        return (0);
 #endif /* !HAVE_SPINLOCKS */
 }
@@ -262,6 +255,8 @@ __db_mutex_unlock(mp, fd)
 #endif
 
 #ifdef HAVE_SPINLOCKS
+       COMPQUIET(fd, 0);
+
 #ifdef DEBUG
        mp->pid = 0;
 #endif