#define LOCK_MUTEX_W(env) pthread_mutex_lock((env)->me_wmutex)
#define UNLOCK_MUTEX_W(env) pthread_mutex_unlock((env)->me_wmutex)
#define getpid() GetCurrentProcessId()
-#define fdatasync(fd) (!FlushFileBuffers(fd))
+#define MDB_FDATASYNC(fd) (!FlushFileBuffers(fd))
#define ErrCode() GetLastError()
#define GET_PAGESIZE(x) {SYSTEM_INFO si; GetSystemInfo(&si); (x) = si.dwPageSize;}
#define close(fd) CloseHandle(fd)
#define UNLOCK_MUTEX_R(env) sem_post((env)->me_rmutex)
#define LOCK_MUTEX_W(env) sem_wait((env)->me_wmutex)
#define UNLOCK_MUTEX_W(env) sem_post((env)->me_wmutex)
-#define fdatasync(fd) fsync(fd)
+#define MDB_FDATASYNC(fd) fsync(fd)
#else
#ifdef ANDROID
-#define fdatasync(fd) fsync(fd)
+#define MDB_FDATASYNC(fd) fsync(fd)
#endif
/** Lock the reader mutex.
*/
* @note In the #MDB_node structure, we only store 48 bits of this value,
* which thus limits us to only 60 bits of addressable data.
*/
-typedef ID pgno_t;
+typedef MDB_ID pgno_t;
/** A transaction ID.
* See struct MDB_txn.mt_txnid for details.
*/
-typedef ID txnid_t;
+typedef MDB_ID txnid_t;
/** @defgroup debug Debug Macros
* @{
# define DPRINTF (void) /* Vararg macros may be unsupported */
#elif MDB_DEBUG
static int mdb_debug;
-static int mdb_debug_start;
+static txnid_t mdb_debug_start;
/** Print a debug message with printf formatting. */
# define DPRINTF(fmt, ...) /**< Requires 2 or more args */ \
- if (mdb_debug) fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, __VA_ARGS__)
+ ((void) ((mdb_debug) && \
+ fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, __VA_ARGS__)))
#else
# define DPRINTF(fmt, ...) ((void) 0)
#endif
*/
pthread_mutex_t mtb_mutex;
#endif
+#if MDB_VERSION == 1
/** The ID of the last transaction committed to the database.
* This is recorded here only for convenience; the value can always
* be determined by reading the main database meta pages.
+ *
+ * Value is unused, but maintained for backwards compatibility.
+ * Drop this or mtb_me_toggle when changing MDB_VERSION.
+ * (Reading both should have been done atomically.)
*/
txnid_t mtb_txnid;
+#endif
/** The number of slots that have been used in the reader table.
* This always records the maximum count, it is not decremented
* when readers release their slots.
#define mti_version mt1.mtb.mtb_version
#define mti_mutex mt1.mtb.mtb_mutex
#define mti_rmname mt1.mtb.mtb_rmname
+#if MDB_VERSION == 1
#define mti_txnid mt1.mtb.mtb_txnid
+#endif
#define mti_numreaders mt1.mtb.mtb_numreaders
#define mti_me_toggle mt1.mtb.mtb_me_toggle
char pad[(sizeof(MDB_txbody)+CACHELINE-1) & ~(CACHELINE-1)];
MDB_env *mt_env; /**< the DB environment */
/** The list of pages that became unused during this transaction.
*/
- IDL mt_free_pgs;
+ MDB_IDL mt_free_pgs;
union {
- ID2L dirty_list; /**< modified pages */
+ MDB_ID2L dirty_list; /**< modified pages */
MDB_reader *reader; /**< this thread's slot in the reader table */
} mt_u;
/** Array of records for each DB known in the environment. */
pthread_key_t me_txkey; /**< thread-key for readers */
MDB_page *me_dpages; /**< list of malloc'd blocks for re-use */
/** IDL of pages that became unused in a write txn */
- IDL me_free_pgs;
+ MDB_IDL me_free_pgs;
/** ID2L of pages that were written during a write txn */
- ID2 me_dirty_list[MDB_IDL_UM_SIZE];
+ MDB_ID2 me_dirty_list[MDB_IDL_UM_SIZE];
/** rwlock for the DB tables, if #LAZY_LOCKS is false */
LAZY_RWLOCK_DEF(me_dblock)
#ifdef _WIN32
pgno_t newpgno, unsigned int nflags);
static int mdb_env_read_header(MDB_env *env, MDB_meta *meta);
-static int mdb_env_read_meta(MDB_env *env, int *which);
+static int mdb_env_pick_meta(const MDB_env *env);
static int mdb_env_write_meta(MDB_txn *txn);
static MDB_node *mdb_node_search(MDB_cursor *mc, MDB_val *key, int *exactp);
{
MDB_cursor mc;
MDB_val key, data;
- int rc, i;
- ID freecount, count;
+ MDB_ID freecount, count;
+ MDB_dbi i;
+ int rc;
freecount = 0;
mdb_cursor_init(&mc, txn, FREE_DBI, NULL);
while ((rc = mdb_cursor_get(&mc, &key, &data, MDB_NEXT)) == 0)
- freecount += *(ID *)data.mv_data;
+ freecount += *(MDB_ID *)data.mv_data;
freecount += txn->mt_dbs[0].md_branch_pages + txn->mt_dbs[0].md_leaf_pages +
txn->mt_dbs[0].md_overflow_pages;
mdb_cursor_init(&mc, txn, i, &mx);
mdb_page_search(&mc, NULL, 0);
do {
- int j;
+ unsigned j;
MDB_page *mp;
mp = mc.mc_pg[mc.mc_top];
for (j=0; j<NUMKEYS(mp); j++) {
MDB_txn *txn = mc->mc_txn;
MDB_page *np;
pgno_t pgno = P_INVALID;
- ID2 mid;
+ MDB_ID2 mid;
if (txn->mt_txnid > 2) {
txn->mt_env->me_pglast = last;
if (!txn->mt_env->me_pgfirst)
txn->mt_env->me_pgfirst = last;
- idl = (ID *) data.mv_data;
+ idl = (MDB_ID *) data.mv_data;
/* We might have a zero-length IDL due to freelist growth
* during a prior commit
*/
mc->mc_db->md_root = mp->mp_pgno;
} else if (mc->mc_txn->mt_parent) {
MDB_page *np;
- ID2 mid;
+ MDB_ID2 mid;
/* If txn has a parent, make sure the page is in our
* dirty list.
*/
pthread_setspecific(env->me_txkey, r);
}
txn->mt_toggle = env->me_txns->mti_me_toggle;
- txn->mt_txnid = env->me_txns->mti_txnid;
+ txn->mt_txnid = r->mr_txnid = env->me_metas[txn->mt_toggle]->mm_txnid;
+
/* This happens if a different process was the
* last writer to the DB.
*/
if (env->me_wtxnid < txn->mt_txnid)
mt_dbflag = DB_STALE;
- r->mr_txnid = txn->mt_txnid;
txn->mt_u.reader = r;
} else {
LOCK_MUTEX_W(env);
- txn->mt_txnid = env->me_txns->mti_txnid;
+ txn->mt_toggle = env->me_txns->mti_me_toggle;
+ txn->mt_txnid = env->me_metas[txn->mt_toggle]->mm_txnid;
if (env->me_wtxnid < txn->mt_txnid)
mt_dbflag = DB_STALE;
txn->mt_txnid++;
if (txn->mt_txnid == mdb_debug_start)
mdb_debug = 1;
#endif
- txn->mt_toggle = env->me_txns->mti_me_toggle;
txn->mt_u.dirty_list = env->me_dirty_list;
txn->mt_u.dirty_list[0].mid = 0;
txn->mt_free_pgs = env->me_free_pgs;
free(txn);
return ENOMEM;
}
- txn->mt_u.dirty_list = malloc(sizeof(ID2)*MDB_IDL_UM_SIZE);
+ txn->mt_u.dirty_list = malloc(sizeof(MDB_ID2)*MDB_IDL_UM_SIZE);
if (!txn->mt_u.dirty_list) {
free(txn->mt_free_pgs);
free(txn);
MDB_db *ip, *jp;
MDB_dbi i;
unsigned x, y;
- ID2L dst, src;
+ MDB_ID2L dst, src;
/* Update parent's DB table */
ip = &txn->mt_parent->mt_dbs[2];
#if MDB_DEBUG > 1
{
unsigned int i;
- ID *idl = txn->mt_free_pgs;
+ MDB_IDL idl = txn->mt_free_pgs;
DPRINTF("IDL write txn %zu root %zu num %zu",
txn->mt_txnid, txn->mt_dbs[FREE_DBI].md_root, idl[0]);
for (i=0; i<idl[0]; i++) {
/** Check both meta pages to see which one is newer.
* @param[in] env the environment handle
- * @param[out] which address of where to store the meta toggle ID
- * @return 0 on success, non-zero on failure.
+ * @return meta toggle (0 or 1).
*/
static int
-mdb_env_read_meta(MDB_env *env, int *which)
+mdb_env_pick_meta(const MDB_env *env)
{
- int toggle = 0;
-
- assert(env != NULL);
-
- if (env->me_metas[0]->mm_txnid < env->me_metas[1]->mm_txnid)
- toggle = 1;
-
- DPRINTF("Using meta page %d", toggle);
- *which = toggle;
-
- return MDB_SUCCESS;
+ return (env->me_metas[0]->mm_txnid < env->me_metas[1]->mm_txnid);
}
int
static int
mdb_env_open2(MDB_env *env, unsigned int flags)
{
- int i, newenv = 0, toggle;
+ int i, newenv = 0;
MDB_meta meta;
MDB_page *p;
env->me_metas[0] = METADATA(p);
env->me_metas[1] = (MDB_meta *)((char *)env->me_metas[0] + meta.mm_psize);
- if ((i = mdb_env_read_meta(env, &toggle)) != 0)
- return i;
-
- DPRINTF("opened database version %u, pagesize %u",
- env->me_metas[toggle]->mm_version, env->me_psize);
- DPRINTF("depth: %u", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_depth);
- DPRINTF("entries: %zu", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_entries);
- DPRINTF("branch pages: %zu", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_branch_pages);
- DPRINTF("leaf pages: %zu", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_leaf_pages);
- DPRINTF("overflow pages: %zu", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_overflow_pages);
- DPRINTF("root: %zu", env->me_metas[toggle]->mm_dbs[MAIN_DBI].md_root);
+#if MDB_DEBUG
+ {
+ int toggle = mdb_env_pick_meta(env);
+ MDB_db *db = &env->me_metas[toggle]->mm_dbs[MAIN_DBI];
+
+ DPRINTF("opened database version %u, pagesize %u",
+ env->me_metas[0]->mm_version, env->me_psize);
+ DPRINTF("using meta page %d", toggle);
+ DPRINTF("depth: %u", db->md_depth);
+ DPRINTF("entries: %zu", db->md_entries);
+ DPRINTF("branch pages: %zu", db->md_branch_pages);
+ DPRINTF("leaf pages: %zu", db->md_leaf_pages);
+ DPRINTF("overflow pages: %zu", db->md_overflow_pages);
+ DPRINTF("root: %zu", db->md_root);
+ }
+#endif
return MDB_SUCCESS;
}
+
#ifndef _WIN32
/** Release a reader thread's slot in the reader lock table.
* This function is called automatically when a thread exits.
static void
mdb_env_share_locks(MDB_env *env)
{
- int toggle = 0;
+ int toggle = mdb_env_pick_meta(env);
- if (env->me_metas[0]->mm_txnid < env->me_metas[1]->mm_txnid)
- toggle = 1;
env->me_txns->mti_me_toggle = toggle;
env->me_txns->mti_txnid = env->me_metas[toggle]->mm_txnid;
* hval arg on the first call.
*/
static mdb_hash_t
-mdb_hash_str(char *str, mdb_hash_t hval)
+mdb_hash_val(MDB_val *val, mdb_hash_t hval)
{
- unsigned char *s = (unsigned char *)str; /* unsigned string */
+ unsigned char *s = (unsigned char *)val->mv_data; /* unsigned string */
+ unsigned char *end = s + val->mv_size;
/*
* FNV-1a hash each octet of the string
*/
- while (*s) {
+ while (s < end) {
/* xor the bottom with the current octet */
hval ^= (mdb_hash_t)*s++;
* @param[out] hexbuf an array of 17 chars to hold the hash
*/
static void
-mdb_hash_hex(char *str, char *hexbuf)
+mdb_hash_hex(MDB_val *val, char *hexbuf)
{
int i;
- mdb_hash_t h = mdb_hash_str(str, MDB_HASH_INIT);
+ mdb_hash_t h = mdb_hash_val(val, MDB_HASH_INIT);
for (i=0; i<8; i++) {
hexbuf += sprintf(hexbuf, "%02x", (unsigned int)h & 0xff);
h >>= 8;
}
}
size = GetFileSize(env->me_lfd, NULL);
+
#else
- if ((env->me_lfd = open(lpath, O_RDWR|O_CREAT, mode)) == -1) {
- rc = ErrCode();
- return rc;
+#if !(O_CLOEXEC)
+ {
+ int fdflags;
+ if ((env->me_lfd = open(lpath, O_RDWR|O_CREAT, mode)) == -1)
+ return ErrCode();
+ /* Lose record locks when exec*() */
+ if ((fdflags = fcntl(env->me_lfd, F_GETFD) | FD_CLOEXEC) >= 0)
+ fcntl(env->me_lfd, F_SETFD, fdflags);
}
+#else /* O_CLOEXEC on Linux: Open file and set FD_CLOEXEC atomically */
+ if ((env->me_lfd = open(lpath, O_RDWR|O_CREAT|O_CLOEXEC, mode)) == -1)
+ return ErrCode();
+#endif
+
/* Try to get exclusive lock. If we succeed, then
* nobody is using the lock region and we should initialize it.
*/
}
if (*excl) {
#ifdef _WIN32
+ BY_HANDLE_FILE_INFORMATION stbuf;
+ struct {
+ DWORD volume;
+ DWORD nhigh;
+ DWORD nlow;
+ } idbuf;
+ MDB_val val;
char hexbuf[17];
+
if (!mdb_sec_inited) {
InitializeSecurityDescriptor(&mdb_null_sd,
SECURITY_DESCRIPTOR_REVISION);
mdb_all_sa.lpSecurityDescriptor = &mdb_null_sd;
mdb_sec_inited = 1;
}
- mdb_hash_hex(lpath, hexbuf);
+ GetFileInformationByHandle(env->me_lfd, &stbuf);
+ idbuf.volume = stbuf.dwVolumeSerialNumber;
+ idbuf.nhigh = stbuf.nFileIndexHigh;
+ idbuf.nlow = stbuf.nFileIndexLow;
+ val.mv_data = &idbuf;
+ val.mv_size = sizeof(idbuf);
+ mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "Global\\MDBr%s", hexbuf);
env->me_rmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_rmname);
if (!env->me_rmutex) {
}
#else /* _WIN32 */
#ifdef __APPLE__
+ struct stat stbuf;
+ struct {
+ dev_t dev;
+ ino_t ino;
+ } idbuf;
+ MDB_val val;
char hexbuf[17];
- mdb_hash_hex(lpath, hexbuf);
+
+ fstat(env->me_lfd, &stbuf);
+ idbuf.dev = stbuf.st_dev;
+ idbuf.ino = stbuf.st_ino;
+ val.mv_data = &idbuf;
+ val.mv_size = sizeof(idbuf);
+ mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "MDBr%s", hexbuf);
if (sem_unlink(env->me_txns->mti_rmname)) {
rc = ErrCode();
len = OPEN_ALWAYS;
}
mode = FILE_ATTRIBUTE_NORMAL;
- if ((env->me_fd = CreateFile(dpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL, len, mode, NULL)) == INVALID_HANDLE_VALUE) {
- rc = ErrCode();
- goto leave;
- }
+ env->me_fd = CreateFile(dpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, len, mode, NULL);
#else
if (F_ISSET(flags, MDB_RDONLY))
oflags = O_RDONLY;
else
oflags = O_RDWR | O_CREAT;
- if ((env->me_fd = open(dpath, oflags, mode)) == -1) {
+ env->me_fd = open(dpath, oflags, mode);
+#endif
+ if (env->me_fd == INVALID_HANDLE_VALUE) {
rc = ErrCode();
goto leave;
}
-#endif
if ((rc = mdb_env_open2(env, flags)) == MDB_SUCCESS) {
- /* synchronous fd for meta writes */
+ if (flags & (MDB_RDONLY|MDB_NOSYNC)) {
+ env->me_mfd = env->me_fd;
+ } else {
+ /* synchronous fd for meta writes */
#ifdef _WIN32
- if (!(flags & (MDB_RDONLY|MDB_NOSYNC)))
- mode |= FILE_FLAG_WRITE_THROUGH;
- if ((env->me_mfd = CreateFile(dpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL, len, mode, NULL)) == INVALID_HANDLE_VALUE) {
- rc = ErrCode();
- goto leave;
- }
+ env->me_mfd = CreateFile(dpath, oflags,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len,
+ mode | FILE_FLAG_WRITE_THROUGH, NULL);
#else
- if (!(flags & (MDB_RDONLY|MDB_NOSYNC)))
- oflags |= MDB_DSYNC;
- if ((env->me_mfd = open(dpath, oflags, mode)) == -1) {
- rc = ErrCode();
- goto leave;
- }
+ env->me_mfd = open(dpath, oflags | MDB_DSYNC, mode);
#endif
+ if (env->me_mfd == INVALID_HANDLE_VALUE) {
+ rc = ErrCode();
+ goto leave;
+ }
+ }
env->me_path = strdup(path);
DPRINTF("opened dbenv %p", (void *) env);
pthread_key_create(&env->me_txkey, mdb_env_reader_dest);
if (env->me_map) {
munmap(env->me_map, env->me_mapsize);
}
- close(env->me_mfd);
+ if (env->me_mfd != env->me_fd)
+ close(env->me_mfd);
close(env->me_fd);
if (env->me_txns) {
pid_t pid = getpid();
if (env == NULL || arg == NULL)
return EINVAL;
- mdb_env_read_meta(env, &toggle);
+ toggle = mdb_env_pick_meta(env);
return mdb_stat0(env, &env->me_metas[toggle]->mm_dbs[MAIN_DBI], arg);
}
static void
mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi)
{
- if (txn->mt_dbs[dbi].md_flags & MDB_REVERSEKEY)
- txn->mt_dbxs[dbi].md_cmp = mdb_cmp_memnr;
- else if (txn->mt_dbs[dbi].md_flags & MDB_INTEGERKEY)
- txn->mt_dbxs[dbi].md_cmp = mdb_cmp_cint;
- else
- txn->mt_dbxs[dbi].md_cmp = mdb_cmp_memn;
+ uint16_t f = txn->mt_dbs[dbi].md_flags;
- if (txn->mt_dbs[dbi].md_flags & MDB_DUPSORT) {
- if (txn->mt_dbs[dbi].md_flags & MDB_INTEGERDUP) {
- if (txn->mt_dbs[dbi].md_flags & MDB_DUPFIXED)
- txn->mt_dbxs[dbi].md_dcmp = mdb_cmp_int;
- else
- txn->mt_dbxs[dbi].md_dcmp = mdb_cmp_cint;
- } else if (txn->mt_dbs[dbi].md_flags & MDB_REVERSEDUP) {
- txn->mt_dbxs[dbi].md_dcmp = mdb_cmp_memnr;
- } else {
- txn->mt_dbxs[dbi].md_dcmp = mdb_cmp_memn;
- }
- } else {
- txn->mt_dbxs[dbi].md_dcmp = NULL;
- }
+ txn->mt_dbxs[dbi].md_cmp =
+ (f & MDB_REVERSEKEY) ? mdb_cmp_memnr :
+ (f & MDB_INTEGERKEY) ? mdb_cmp_cint : mdb_cmp_memn;
+
+ txn->mt_dbxs[dbi].md_dcmp =
+ !(f & MDB_DUPSORT) ? 0 :
+ ((f & MDB_INTEGERDUP)
+ ? ((f & MDB_DUPFIXED) ? mdb_cmp_int : mdb_cmp_cint)
+ : ((f & MDB_REVERSEDUP) ? mdb_cmp_memnr : mdb_cmp_memn));
}
int mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
/** @file midl.h
- * @brief ldap bdb back-end ID List header file.
+ * @brief mdb ID List header file.
*
* This file was originally part of back-bdb but has been
* modified for use in libmdb. Most of the macros defined
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/** @defgroup internal MDB Internals
* @{
*/
/** A generic ID number. These were entryIDs in back-bdb.
* Preferably it should have the same size as a pointer.
*/
-typedef size_t ID;
+typedef size_t MDB_ID;
/** An IDL is an ID List, a sorted array of IDs. The first
* element of the array is a counter for how many actual
* sorted in ascending order. For libmdb IDLs are sorted in
* descending order.
*/
-typedef ID *IDL;
+typedef MDB_ID *MDB_IDL;
-#define NOID (~(ID)0)
+#define MDB_NOID (~(MDB_ID)0)
/* IDL sizes - likely should be even bigger
* limiting factors: sizeof(ID), thread stack size
#define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */
#define MDB_IDL_DB_SIZE (1<<MDB_IDL_LOGN)
#define MDB_IDL_UM_SIZE (1<<(MDB_IDL_LOGN+1))
-#define MDB_IDL_UM_SIZEOF (MDB_IDL_UM_SIZE * sizeof(ID))
+#define MDB_IDL_UM_SIZEOF (MDB_IDL_UM_SIZE * sizeof(MDB_ID))
#define MDB_IDL_DB_MAX (MDB_IDL_DB_SIZE-1)
#define MDB_IDL_UM_MAX (MDB_IDL_UM_SIZE-1)
-#define MDB_IDL_IS_RANGE(ids) ((ids)[0] == NOID)
+#define MDB_IDL_IS_RANGE(ids) ((ids)[0] == MDB_NOID)
#define MDB_IDL_RANGE_SIZE (3)
-#define MDB_IDL_RANGE_SIZEOF (MDB_IDL_RANGE_SIZE * sizeof(ID))
+#define MDB_IDL_RANGE_SIZEOF (MDB_IDL_RANGE_SIZE * sizeof(MDB_ID))
#define MDB_IDL_SIZEOF(ids) ((MDB_IDL_IS_RANGE(ids) \
- ? MDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(ID))
+ ? MDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(MDB_ID))
#define MDB_IDL_RANGE_FIRST(ids) ((ids)[1])
#define MDB_IDL_RANGE_LAST(ids) ((ids)[2])
#define MDB_IDL_RANGE( ids, f, l ) \
do { \
- (ids)[0] = NOID; \
+ (ids)[0] = MDB_NOID; \
(ids)[1] = (f); \
(ids)[2] = (l); \
} while(0)
} while(0)
#define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 )
-#define MDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == NOID \
+#define MDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == MDB_NOID \
&& (ids)[1] <= (range)[1] && (range)[2] <= (ids)[2] )
#define MDB_IDL_CPY( dst, src ) (memcpy( dst, src, MDB_IDL_SIZEOF( src ) ))
* @param[in] id The ID to insert.
* @return 0 on success, -1 if the ID was already present in the IDL.
*/
-int mdb_midl_insert( IDL ids, ID id );
+int mdb_midl_insert( MDB_IDL ids, MDB_ID id );
#endif
/** Allocate an IDL.
* Allocates memory for an IDL of a default size.
* @return IDL on success, NULL on failure.
*/
-IDL mdb_midl_alloc();
+MDB_IDL mdb_midl_alloc();
/** Free an IDL.
* @param[in] ids The IDL to free.
*/
-void mdb_midl_free(IDL ids);
+void mdb_midl_free(MDB_IDL ids);
/** Shrink an IDL.
* Return the IDL to the default size if it has grown larger.
* @param[in,out] idp Address of the IDL to shrink.
* @return 0 on no change, non-zero if shrunk.
*/
-int mdb_midl_shrink(IDL *idp);
+int mdb_midl_shrink(MDB_IDL *idp);
/** Append an ID onto an IDL.
* @param[in,out] idp Address of the IDL to append to.
* @param[in] id The ID to append.
* @return 0 on success, -1 if the IDL is too large.
*/
-int mdb_midl_append( IDL *idp, ID id );
+int mdb_midl_append( MDB_IDL *idp, MDB_ID id );
/** Append an IDL onto an IDL.
* @param[in,out] idp Address of the IDL to append to.
* @param[in] app The IDL to append.
* @return 0 on success, -1 if the IDL is too large.
*/
-int mdb_midl_append_list( IDL *idp, IDL app );
+int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app );
/** Sort an IDL.
* @param[in,out] ids The IDL to sort.
*/
-void mdb_midl_sort( IDL ids );
+void mdb_midl_sort( MDB_IDL ids );
/** An ID2 is an ID/pointer pair.
*/
-typedef struct ID2 {
- ID mid; /**< The ID */
+typedef struct MDB_ID2 {
+ MDB_ID mid; /**< The ID */
void *mptr; /**< The pointer */
-} ID2;
+} MDB_ID2;
/** An ID2L is an ID2 List, a sorted array of ID2s.
* The first element's \b mid member is a count of how many actual
* elements are in the array. The \b mptr member of the first element is unused.
* The array is sorted in ascending order by \b mid.
*/
-typedef ID2 *ID2L;
+typedef MDB_ID2 *MDB_ID2L;
/** Search for an ID in an ID2L.
* @param[in] ids The ID2L to search.
* @param[in] id The ID to search for.
* @return The index of the first ID2 whose \b mid member is greater than or equal to \b id.
*/
-unsigned mdb_mid2l_search( ID2L ids, ID id );
+unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id );
/** Insert an ID2 into a ID2L.
* @param[in] id The ID2 to insert.
* @return 0 on success, -1 if the ID was already present in the ID2L.
*/
-int mdb_mid2l_insert( ID2L ids, ID2 *id );
+int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id );
/** @} */
/** @} */
+#ifdef __cplusplus
+}
+#endif
#endif /* _MDB_MIDL_H_ */