diff options
author | jbj <devnull@localhost> | 2004-10-16 01:31:54 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2004-10-16 01:31:54 +0000 |
commit | d03f220fde879509cab2ac1c73b71b7efb52b737 (patch) | |
tree | 1e34bfadac0a6618d0e9a7933bad90063a785acf /db/mutex | |
parent | 2dc699bfe049b9319ea3719f604d25940ff52004 (diff) | |
download | rpm-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.gz rpm-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.bz2 rpm-d03f220fde879509cab2ac1c73b71b7efb52b737.zip |
... and in with the New ...
CVS patchset: 7471
CVS date: 2004/10/16 01:31:54
Diffstat (limited to 'db/mutex')
-rw-r--r-- | db/mutex/mut_fcntl.c | 9 | ||||
-rw-r--r-- | db/mutex/mut_pthread.c | 29 | ||||
-rw-r--r-- | db/mutex/mut_tas.c | 25 | ||||
-rw-r--r-- | db/mutex/mut_win32.c | 23 | ||||
-rw-r--r-- | db/mutex/mutex.c | 47 | ||||
-rw-r--r-- | db/mutex/tm.c | 12 | ||||
-rw-r--r-- | db/mutex/uts4_cc.s | 4 |
7 files changed, 86 insertions, 63 deletions
diff --git a/db/mutex/mut_fcntl.c b/db/mutex/mut_fcntl.c index ac600312c..03521bd77 100644 --- a/db/mutex/mut_fcntl.c +++ b/db/mutex/mut_fcntl.c @@ -1,22 +1,21 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1996-2003 + * Copyright (c) 1996-2004 * Sleepycat Software. All rights reserved. + * + * $Id: mut_fcntl.c,v 11.26 2004/01/28 03:36:18 bostic Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: mut_fcntl.c,v 11.24 2003/05/05 19:55:03 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> /* SEEK_SET on SunOS. */ #endif #include "db_int.h" diff --git a/db/mutex/mut_pthread.c b/db/mutex/mut_pthread.c index 10c9bc597..6507eba73 100644 --- a/db/mutex/mut_pthread.c +++ b/db/mutex/mut_pthread.c @@ -1,20 +1,19 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1999-2003 + * Copyright (c) 1999-2004 * Sleepycat Software. All rights reserved. + * + * $Id: mut_pthread.c,v 11.62 2004/09/22 16:27:05 bostic Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: mut_pthread.c,v 11.57 2003/05/05 19:55:03 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> #include <string.h> +#include <unistd.h> #endif #include "db_int.h" @@ -30,26 +29,29 @@ static const char revid[] = "$Id: mut_pthread.c,v 11.57 2003/05/05 19:55:03 bost #endif #ifdef HAVE_MUTEX_SOLARIS_LWP +#define pthread_cond_destroy(x) 0 #define pthread_cond_signal _lwp_cond_signal #define pthread_cond_wait _lwp_cond_wait +#define pthread_mutex_destroy(x) 0 #define pthread_mutex_lock _lwp_mutex_lock #define pthread_mutex_trylock _lwp_mutex_trylock #define pthread_mutex_unlock _lwp_mutex_unlock /* + * !!! * _lwp_self returns the LWP process ID which isn't a unique per-thread * identifier. Use pthread_self instead, it appears to work even if we * are not a pthreads application. */ -#define pthread_mutex_destroy(x) 0 #endif #ifdef HAVE_MUTEX_UI_THREADS +#define pthread_cond_destroy(x) cond_destroy #define pthread_cond_signal cond_signal #define pthread_cond_wait cond_wait +#define pthread_mutex_destroy mutex_destroy #define pthread_mutex_lock mutex_lock #define pthread_mutex_trylock mutex_trylock #define pthread_mutex_unlock mutex_unlock #define pthread_self thr_self -#define pthread_mutex_destroy mutex_destroy #endif #define PTHREAD_UNLOCK_ATTEMPTS 5 @@ -348,12 +350,19 @@ int __db_pthread_mutex_destroy(mutexp) DB_MUTEX *mutexp; { - int ret; + int ret, t_ret; if (F_ISSET(mutexp, MUTEX_IGNORE)) return (0); - if ((ret = pthread_mutex_destroy(&mutexp->mutex)) != 0) - __db_err(NULL, "unable to destroy mutex: %s", strerror(ret)); + ret = 0; + if (F_ISSET(mutexp, MUTEX_SELF_BLOCK) && + (ret = pthread_cond_destroy(&mutexp->cond)) != 0) + __db_err(NULL, "unable to destroy cond: %s", strerror(ret)); + if ((t_ret = pthread_mutex_destroy(&mutexp->mutex)) != 0) { + __db_err(NULL, "unable to destroy mutex: %s", strerror(t_ret)); + if (ret == 0) + ret = t_ret; + } return (ret); } diff --git a/db/mutex/mut_tas.c b/db/mutex/mut_tas.c index cfe31c5a9..08d7ed876 100644 --- a/db/mutex/mut_tas.c +++ b/db/mutex/mut_tas.c @@ -1,16 +1,14 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1996-2003 + * Copyright (c) 1996-2004 * Sleepycat Software. All rights reserved. + * + * $Id: mut_tas.c,v 11.44 2004/09/15 19:14:49 bostic Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: mut_tas.c,v 11.40 2003/05/06 14:25:33 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> @@ -39,7 +37,11 @@ __db_tas_mutex_init(dbenv, mutexp, flags) u_int32_t save; /* Check alignment. */ - DB_ASSERT(((db_alignp_t)mutexp & (MUTEX_ALIGN - 1)) == 0); + if ((uintptr_t)mutexp & (MUTEX_ALIGN - 1)) { + __db_err(dbenv, + "__db_tas_mutex_init: mutex not appropriately aligned"); + return (EINVAL); + } /* * The only setting/checking of the MUTEX_MPOOL flag is in the mutex @@ -115,7 +117,16 @@ relock: #ifdef HAVE_MUTEX_S390_CC_ASSEMBLY tsl_t zero = 0; #endif - if (!MUTEX_SET(&mutexp->tas)) { + if ( +#ifdef MUTEX_SET_TEST + /* + * If using test-and-set mutexes, and we know the "set" value, + * we can avoid interlocked instructions since they're unlikely + * to succeed. + */ + mutexp->tas || +#endif + !MUTEX_SET(&mutexp->tas)) { /* * Some systems (notably those with newer Intel CPUs) * need a small pause here. [#6975] diff --git a/db/mutex/mut_win32.c b/db/mutex/mut_win32.c index b5cbfc731..b51000321 100644 --- a/db/mutex/mut_win32.c +++ b/db/mutex/mut_win32.c @@ -1,16 +1,14 @@ /* * See the file LICENSE for redistribution information. * - * Copyright (c) 2002-2003 + * Copyright (c) 2002-2004 * Sleepycat Software. All rights reserved. + * + * $Id: mut_win32.c,v 1.18 2004/07/06 21:06:39 mjc Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: mut_win32.c,v 1.15 2003/05/05 19:55:03 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> @@ -26,13 +24,18 @@ static const char revid[] = "$Id: mut_win32.c,v 1.15 2003/05/05 19:55:03 bostic /* We don't want to run this code even in "ordinary" diagnostic mode. */ #undef MUTEX_DIAG +static _TCHAR hex_digits[] = _T("0123456789abcdef"); + #define GET_HANDLE(mutexp, event) do { \ - char idbuf[13]; \ + _TCHAR idbuf[] = _T("db.m00000000"); \ + _TCHAR *p = idbuf + 12; \ + u_int32_t id; \ \ - snprintf(idbuf, sizeof idbuf, "db.m%08x", mutexp->id); \ + for (id = (mutexp)->id; id != 0; id >>= 4) \ + *--p = hex_digits[id & 0xf]; \ event = CreateEvent(NULL, FALSE, FALSE, idbuf); \ if (event == NULL) \ - return (__os_win32_errno()); \ + return (__os_get_errno()); \ } while (0) /* @@ -158,7 +161,7 @@ loop: /* Attempt to acquire the resource for N spins. */ GET_HANDLE(mutexp, event); } if ((ret = WaitForSingleObject(event, ms)) == WAIT_FAILED) - return (__os_win32_errno()); + return (__os_get_errno()); if ((ms <<= 1) > MS_PER_SEC) ms = MS_PER_SEC; @@ -205,7 +208,7 @@ __db_win32_mutex_unlock(dbenv, mutexp) now.QuadPart, mutexp, mutexp->id); #endif if (!PulseEvent(event)) - ret = __os_win32_errno(); + ret = __os_get_errno(); CloseHandle(event); } diff --git a/db/mutex/mutex.c b/db/mutex/mutex.c index 51ed121de..91400cd62 100644 --- a/db/mutex/mutex.c +++ b/db/mutex/mutex.c @@ -1,16 +1,14 @@ /*- * See the file LICENSE for redistribution information. * - * Copyright (c) 1999-2003 + * Copyright (c) 1999-2004 * Sleepycat Software. All rights reserved. + * + * $Id: mutex.c,v 11.42 2004/09/15 21:49:19 mjc Exp $ */ #include "db_config.h" -#ifndef lint -static const char revid[] = "$Id: mutex.c,v 11.39 2003/04/23 19:43:37 bostic Exp $"; -#endif /* not lint */ - #ifndef NO_SYSTEM_INCLUDES #include <sys/types.h> @@ -132,7 +130,7 @@ __db_mutex_alloc_int(dbenv, infop, storep) * we can free buffers until memory is available. */ #if defined(MUTEX_NO_MALLOC_LOCKS) || defined(HAVE_MUTEX_SYSTEM_RESOURCES) - ret = __db_shalloc(infop->addr, sizeof(DB_MUTEX), MUTEX_ALIGN, storep); + ret = __db_shalloc(infop, sizeof(DB_MUTEX), MUTEX_ALIGN, storep); if (ret == ENOMEM && MPOOL_ON(dbenv)) { DB_MPOOL *dbmp; @@ -176,10 +174,10 @@ __db_mutex_free(dbenv, infop, mutexp) dbmp = dbenv->mp_handle; R_LOCK(dbenv, dbmp->reginfo); - __db_shalloc_free(dbmp->reginfo[0].addr, mutexp); + __db_shalloc_free(&dbmp->reginfo[0], mutexp); R_UNLOCK(dbenv, dbmp->reginfo); } else - __db_shalloc_free(infop->addr, mutexp); + __db_shalloc_free(infop, mutexp); R_UNLOCK(dbenv, infop); #else COMPQUIET(dbenv, NULL); @@ -207,7 +205,8 @@ __db_shreg_locks_record(dbenv, mutexp, infop, rp) return (0); DB_ASSERT(mutexp->reg_off == INVALID_ROFF); rp->stat.st_records++; - i = (roff_t *)R_ADDR(infop, rp->regmutex_hint) - &rp->regmutexes[0]; + i = (roff_t *)R_ADDR(dbenv, infop, rp->regmutex_hint) - + &rp->regmutexes[0]; if (rp->regmutexes[i] != INVALID_ROFF) { /* * Our hint failed, search for an open slot. @@ -229,11 +228,11 @@ __db_shreg_locks_record(dbenv, mutexp, infop, rp) * When we get here, i is an empty slot. Record this * mutex, set hint to point to the next slot and we are done. */ - rp->regmutexes[i] = R_OFFSET(infop, mutexp); - mutexp->reg_off = R_OFFSET(infop, &rp->regmutexes[i]); + rp->regmutexes[i] = R_OFFSET(dbenv, infop, mutexp); + mutexp->reg_off = R_OFFSET(dbenv, infop, &rp->regmutexes[i]); rp->regmutex_hint = (i < rp->reglocks - 1) ? - R_OFFSET(infop, &rp->regmutexes[i+1]) : - R_OFFSET(infop, &rp->regmutexes[0]); + R_OFFSET(dbenv, infop, &rp->regmutexes[i+1]) : + R_OFFSET(dbenv, infop, &rp->regmutexes[0]); return (0); } @@ -260,9 +259,9 @@ __db_shreg_locks_clear(mutexp, infop, rp) * environment. We recorded our index in the mutex, find and clear it. */ DB_ASSERT(mutexp->reg_off != INVALID_ROFF); - DB_ASSERT(*(roff_t *)R_ADDR(infop, mutexp->reg_off) == \ - R_OFFSET(infop, mutexp)); - *(roff_t *)R_ADDR(infop, mutexp->reg_off) = 0; + DB_ASSERT(*(roff_t *)R_ADDR(dbenv, infop, mutexp->reg_off) == \ + R_OFFSET(dbenv, infop, mutexp)); + *(roff_t *)R_ADDR(dbenv, infop, mutexp->reg_off) = 0; if (rp != NULL) { rp->regmutex_hint = mutexp->reg_off; rp->stat.st_clears++; @@ -290,7 +289,7 @@ __db_shreg_locks_destroy(infop, rp) for (i = 0; i < rp->reglocks; i++) if (rp->regmutexes[i] != 0) { rp->stat.st_destroys++; - __db_mutex_destroy((DB_MUTEX *)R_ADDR(infop, + __db_mutex_destroy((DB_MUTEX *)R_ADDR(dbenv, infop, rp->regmutexes[i])); } } @@ -358,7 +357,7 @@ __db_shreg_maintinit(infop, addr, size) rp = (REGMAINT *)addr; memset(addr, 0, sizeof(REGMAINT)); rp->reglocks = size / sizeof(roff_t); - rp->regmutex_hint = R_OFFSET(infop, &rp->regmutexes[0]); + rp->regmutex_hint = R_OFFSET(dbenv, infop, &rp->regmutexes[0]); for (i = 0; i < rp->reglocks; i++) rp->regmutexes[i] = INVALID_ROFF; } @@ -372,17 +371,19 @@ __db_mutex_maint(dbenv, infop) switch (infop->type) { case REGION_TYPE_LOCK: - moff = ((DB_LOCKREGION *)R_ADDR(infop, + moff = ((DB_LOCKREGION *)R_ADDR(dbenv, infop, infop->rp->primary))->maint_off; break; case REGION_TYPE_LOG: - moff = ((LOG *)R_ADDR(infop, infop->rp->primary))->maint_off; + moff = ((LOG *)R_ADDR(dbenv, infop, + infop->rp->primary))->maint_off; break; case REGION_TYPE_MPOOL: - moff = ((MPOOL *)R_ADDR(infop, infop->rp->primary))->maint_off; + moff = ((MPOOL *)R_ADDR(dbenv, infop, + infop->rp->primary))->maint_off; break; case REGION_TYPE_TXN: - moff = ((DB_TXNREGION *)R_ADDR(infop, + moff = ((DB_TXNREGION *)R_ADDR(dbenv, infop, infop->rp->primary))->maint_off; break; default: @@ -390,6 +391,6 @@ __db_mutex_maint(dbenv, infop) "Attempting to record mutex in a region not set up to do so"); return (NULL); } - return ((REGMAINT *)R_ADDR(infop, moff)); + return ((REGMAINT *)R_ADDR(dbenv, infop, moff)); } #endif /* HAVE_MUTEX_SYSTEM_RESOURCES */ diff --git a/db/mutex/tm.c b/db/mutex/tm.c index 49f1ac7eb..448e1bfde 100644 --- a/db/mutex/tm.c +++ b/db/mutex/tm.c @@ -127,7 +127,7 @@ main(argc, argv) * TM[nthreads] per-thread mutex array * TM[maxlocks] per-lock mutex array */ - align = ALIGN(sizeof(TM), MUTEX_ALIGN); + align = DB_ALIGN(sizeof(TM), MUTEX_ALIGN); len = align * (1 + nthreads * nprocs + maxlocks); switch (rtype) { @@ -253,7 +253,7 @@ run_locker(id) #endif int status; - (void)__os_sleep(&dbenv, 3, 0); /* Let everyone catch up. */ + __os_sleep(&dbenv, 3, 0); /* Let everyone catch up. */ srand((u_int)time(NULL) % getpid()); /* Initialize random numbers. */ @@ -348,7 +348,7 @@ run_lthread(arg) * we still hold the mutex. */ for (i = 0; i < 3; ++i) { - (void)__os_sleep(&dbenv, 0, rand() % 3); + __os_sleep(&dbenv, 0, rand() % 3); if (mp->id != id) { fprintf(stderr, "RACE! (%03lu stole lock %d from %03lu)\n", @@ -427,7 +427,7 @@ run_lthread(arg) if (nl == 0) break; - (void)__os_sleep(&dbenv, 0, rand() % 500); + __os_sleep(&dbenv, 0, rand() % 500); } } @@ -443,7 +443,7 @@ run_wakeup(id) int status; void *retp; #endif - (void)__os_sleep(&dbenv, 3, 0); /* Let everyone catch up. */ + __os_sleep(&dbenv, 3, 0); /* Let everyone catch up. */ srand((u_int)time(NULL) % getpid()); /* Initialize random numbers. */ @@ -543,7 +543,7 @@ run_wthread(arg) return ((void *)EXIT_FAILURE); } - (void)__os_sleep(&dbenv, 0, rand() % 3); + __os_sleep(&dbenv, 0, rand() % 3); } return (NULL); } diff --git a/db/mutex/uts4_cc.s b/db/mutex/uts4_cc.s index f68d82922..9b314c4af 100644 --- a/db/mutex/uts4_cc.s +++ b/db/mutex/uts4_cc.s @@ -1,9 +1,9 @@ / See the file LICENSE for redistribution information. / - / Copyright (c) 1997-2003 + / Copyright (c) 1997-2004 / Sleepycat Software. All rights reserved. / - / $Id: uts4_cc.s,v 11.3 2003/01/08 05:28:42 bostic Exp $ + / $Id: uts4_cc.s,v 11.4 2004/01/28 03:36:18 bostic Exp $ / / int uts_lock ( int *p, int i ); / Update the lock word pointed to by p with the |