summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-10-18 08:52:16 +0000
committerAndrew Tridgell <tridge@samba.org>2003-10-18 08:52:16 +0000
commitf4d9600e6813f151350d9a89749ee4d12b62b842 (patch)
tree54ed914a9efc59f19a75ad572d70e794c48d4626 /source3/tdb
parent8c4e25a331bb9e72374202378340b2acd525adce (diff)
downloadsamba-f4d9600e6813f151350d9a89749ee4d12b62b842.tar.gz
samba-f4d9600e6813f151350d9a89749ee4d12b62b842.tar.bz2
samba-f4d9600e6813f151350d9a89749ee4d12b62b842.zip
fixed spinlocks in tdb
I still wouldn't recommend them, but at least they now work (This used to be commit 76992e7d1655ed15d61254f2be651db020ec4f5e)
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/spinlock.c2
-rw-r--r--source3/tdb/spinlock.h4
-rw-r--r--source3/tdb/tdb.c6
-rw-r--r--source3/tdb/tdbtorture.c1
4 files changed, 10 insertions, 3 deletions
diff --git a/source3/tdb/spinlock.c b/source3/tdb/spinlock.c
index 2370ce3bdd..3fddeafb2c 100644
--- a/source3/tdb/spinlock.c
+++ b/source3/tdb/spinlock.c
@@ -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;
diff --git a/source3/tdb/spinlock.h b/source3/tdb/spinlock.h
index 8b0e833ff5..967fe37457 100644
--- a/source3/tdb/spinlock.h
+++ b/source3/tdb/spinlock.h
@@ -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
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index f5809ef63a..e68bda4055 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -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));
diff --git a/source3/tdb/tdbtorture.c b/source3/tdb/tdbtorture.c
index e27bbff990..3f704e537e 100644
--- a/source3/tdb/tdbtorture.c
+++ b/source3/tdb/tdbtorture.c
@@ -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>