1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/mutex.c"
13 #include "tap-interface.h"
15 #include <sys/types.h>
19 static TDB_DATA key, data;
21 static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level,
26 vfprintf(stderr, fmt, ap);
30 static double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2)
32 return (tv2->tv_sec - tv1->tv_sec) +
33 (tv2->tv_usec - tv1->tv_usec)*1.0e-6;
36 static double timeval_elapsed(const struct timeval *tv)
39 gettimeofday(&tv2, NULL);
40 return timeval_elapsed2(tv, &tv2);
43 /* The code should barf on TDBs created with rwlocks. */
44 int main(int argc, char *argv[])
46 struct tdb_context *tdb;
47 unsigned int log_count;
48 struct tdb_logging_context log_ctx = { log_fn, &log_count };
54 runtime_support = tdb_runtime_check_for_robust_mutexes();
56 if (!runtime_support) {
57 skip(1, "No robust mutex support");
61 key.dsize = strlen("hi");
62 key.dptr = discard_const_p(uint8_t, "hi");
63 data.dsize = strlen("world");
64 data.dptr = discard_const_p(uint8_t, "world");
66 tdb = tdb_open_ex("mutex-allrecord-bench.tdb", 1000000,
67 TDB_INCOMPATIBLE_HASH|
70 O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
71 ok(tdb, "tdb_open_ex should succeed");
73 gettimeofday(&start, NULL);
74 ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
75 elapsed = timeval_elapsed(&start);
77 ok(ret == 0, "tdb_allrecord_lock should succeed");
79 diag("allrecord_lock took %f seconds", elapsed);