Skip to content

Commit 8a4cce1

Browse files
Merge pull request #8 from matthewbastien/indexstoredb-changes
Cherry pick changes from IndexStoreDB's copy of LMDB
2 parents 59d2d78 + 85796ac commit 8a4cce1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Package.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -20,6 +20,12 @@ let package = Package(
2020
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2121
.target(
2222
name: "CLMDB",
23-
dependencies: []),
23+
dependencies: [],
24+
cSettings: [
25+
.define("MDB_USE_POSIX_MUTEX", to: "1",
26+
// Windows does not use POSIX mutex
27+
.when(platforms: [.linux, .macOS])),
28+
.define("MDB_USE_ROBUST", to: "0"),
29+
]),
2430
]
2531
)

libraries/liblmdb/mdb.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static txnid_t mdb_debug_start;
664664
* #MDB_DUPSORT data items must fit on a node in a regular page.
665665
*/
666666
#ifndef MDB_MAXKEYSIZE
667-
#define MDB_MAXKEYSIZE ((MDB_DEVEL) ? 0 : 511)
667+
#define MDB_MAXKEYSIZE 0 // ((MDB_DEVEL) ? 0 : 511) /* use computed max by default */
668668
#endif
669669

670670
/** The maximum size of a key we can write to the environment. */
@@ -809,11 +809,11 @@ typedef struct MDB_rxbody {
809809
* started from so we can avoid overwriting any data used in that
810810
* particular version.
811811
*/
812-
volatile txnid_t mrb_txnid;
812+
txnid_t mrb_txnid;
813813
/** The process ID of the process owning this reader txn. */
814-
volatile MDB_PID_T mrb_pid;
814+
_Atomic MDB_PID_T mrb_pid;
815815
/** The thread ID of the thread owning this txn. */
816-
volatile MDB_THR_T mrb_tid;
816+
_Atomic MDB_THR_T mrb_tid;
817817
} MDB_rxbody;
818818

819819
/** The actual reader record, with cacheline padding. */
@@ -853,12 +853,12 @@ typedef struct MDB_txbody {
853853
* This is recorded here only for convenience; the value can always
854854
* be determined by reading the main database meta pages.
855855
*/
856-
volatile txnid_t mtb_txnid;
856+
_Atomic txnid_t mtb_txnid;
857857
/** The number of slots that have been used in the reader table.
858858
* This always records the maximum count, it is not decremented
859859
* when readers release their slots.
860860
*/
861-
volatile unsigned mtb_numreaders;
861+
_Atomic unsigned mtb_numreaders;
862862
#if defined(_WIN32) || defined(MDB_USE_POSIX_SEM)
863863
/** Binary form of names of the reader/writer locks */
864864
mdb_hash_t mtb_mutexid;
@@ -1249,7 +1249,7 @@ typedef struct MDB_meta {
12491249
* Actually the file may be shorter if the freeDB lists the final pages.
12501250
*/
12511251
pgno_t mm_last_pg;
1252-
volatile txnid_t mm_txnid; /**< txnid that committed this page */
1252+
_Atomic txnid_t mm_txnid; /**< txnid that committed this page */
12531253
} MDB_meta;
12541254

12551255
/** Buffer for a stack-allocated meta page.
@@ -1510,7 +1510,7 @@ struct MDB_env {
15101510
unsigned int me_os_psize; /**< OS page size, from #GET_PAGESIZE */
15111511
unsigned int me_maxreaders; /**< size of the reader table */
15121512
/** Max #MDB_txninfo.%mti_numreaders of interest to #mdb_env_close() */
1513-
volatile int me_close_readers;
1513+
_Atomic int me_close_readers;
15141514
MDB_dbi me_numdbs; /**< number of DBs opened */
15151515
MDB_dbi me_maxdbs; /**< size of the DB table */
15161516
MDB_PID_T me_pid; /**< process ID of this env */
@@ -10111,7 +10111,7 @@ typedef struct mdb_copy {
1011110111
/** Error code. Never cleared if set. Both threads can set nonzero
1011210112
* to fail the copy. Not mutex-protected, LMDB expects atomic int.
1011310113
*/
10114-
volatile int mc_error;
10114+
_Atomic int mc_error;
1011510115
} mdb_copy;
1011610116

1011710117
/** Dedicated writer thread for compacting copy. */

0 commit comments

Comments
 (0)