fixed spinlocks in tdb
authorAndrew Tridgell <tridge@samba.org>
Sat, 18 Oct 2003 08:52:16 +0000 (08:52 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 18 Oct 2003 08:52:16 +0000 (08:52 +0000)
I still wouldn't recommend them, but at least they now work

source/tdb/spinlock.c
source/tdb/spinlock.h
source/tdb/tdb.c
source/tdb/tdbtorture.c

index 2370ce3bdd93286d8c86e3f7c410a3e0ad1e37a4..3fddeafb2c1a3412a9d3d309c68a0242eafc9e86 100644 (file)
@@ -372,7 +372,7 @@ int tdb_create_rwlocks(int fd, unsigned int hash_size)
        unsigned size, i;
        tdb_rwlock_t *rwlocks;
 
-       size = (hash_size + 1) * sizeof(tdb_rwlock_t);
+       size = TDB_SPINLOCK_SIZE(hash_size);
        rwlocks = malloc(size);
        if (!rwlocks)
                return -1;
index 8b0e833ff56c695ee0ce6cf5984bd5ccfc73c7c9..967fe37457fb9a69b754c3ef50fc860d729a7963 100644 (file)
@@ -39,6 +39,8 @@ int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
 int tdb_create_rwlocks(int fd, unsigned int hash_size);
 int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
 
+#define TDB_SPINLOCK_SIZE(hash_size) (((hash_size) + 1) * sizeof(tdb_rwlock_t))
+
 #else /* !USE_SPINLOCKS */
 #if 0
 #define tdb_create_rwlocks(fd, hash_size) 0
@@ -50,6 +52,8 @@ int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
 int tdb_create_rwlocks(int fd, unsigned int hash_size);
 #endif
 int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
+#define TDB_SPINLOCK_SIZE(hash_size) 0
+
 #endif
 
 #endif
index f5809ef63ad3d3ad9de4037ee69aca4a3d41bb2d..e68bda4055626b26a208f42c60039ddf05e80267 100644 (file)
@@ -77,6 +77,8 @@
 #define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
 #define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
 #define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off))
+#define TDB_DATA_START(hash_size) (TDB_HASH_TOP(hash_size-1) + TDB_SPINLOCK_SIZE(hash_size))
+
 
 /* NB assumes there is a local variable called "tdb" that is the
  * current context, also takes doubly-parenthesized print-style
@@ -663,10 +665,10 @@ static int tdb_free(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
 left:
        /* Look left */
        left = offset - sizeof(tdb_off);
-       if (left > TDB_HASH_TOP(tdb->header.hash_size-1)) {
+       if (left > TDB_DATA_START(tdb->header.hash_size)) {
                struct list_struct l;
                tdb_off leftsize;
-
+               
                /* Read in tailer and jump back to header */
                if (ofs_read(tdb, left, &leftsize) == -1) {
                        TDB_LOG((tdb, 0, "tdb_free: left offset read failed at %u\n", left));
index e27bbff9909bbf478214f3f72885ab9a00d02ff1..3f704e537ea90ebf768a887f3dc5911495632f9c 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <sys/mman.h>
 #include <sys/stat.h>