* @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
* @{
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
{
MDB_cursor mc;
MDB_val key, data;
+ MDB_ID freecount, count;
MDB_dbi i;
int rc;
- ID freecount, count;
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_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.
*/
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++) {
#define CMP(x,y) ( (x) < (y) ? -1 : (x) > (y) )
#if 0 /* superseded by append/sort */
-static unsigned mdb_midl_search( IDL ids, ID id )
+static unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id )
{
/*
* binary search of id in ids
return cursor;
}
-int mdb_midl_insert( IDL ids, ID id )
+int mdb_midl_insert( MDB_IDL ids, MDB_ID id )
{
unsigned x, i;
} else {
ids[2] = ids[ids[0]-1];
}
- ids[0] = NOID;
+ ids[0] = MDB_NOID;
} else {
/* insert id */
}
#endif
-IDL mdb_midl_alloc()
+MDB_IDL mdb_midl_alloc()
{
- IDL ids = malloc((MDB_IDL_UM_MAX+1) * sizeof(ID));
+ MDB_IDL ids = malloc((MDB_IDL_UM_MAX+1) * sizeof(MDB_ID));
*ids++ = MDB_IDL_UM_MAX;
return ids;
}
-void mdb_midl_free(IDL ids)
+void mdb_midl_free(MDB_IDL ids)
{
free(ids-1);
}
-int mdb_midl_shrink( IDL *idp )
+int mdb_midl_shrink( MDB_IDL *idp )
{
- IDL ids = *idp;
+ MDB_IDL ids = *idp;
if (ids[-1] > MDB_IDL_UM_MAX) {
- ids = realloc(ids, (MDB_IDL_UM_MAX+1) * sizeof(ID));
+ ids = realloc(ids, (MDB_IDL_UM_MAX+1) * sizeof(MDB_ID));
*ids++ = MDB_IDL_UM_MAX;
*idp = ids;
return 1;
return 0;
}
-int mdb_midl_append( IDL *idp, ID id )
+int mdb_midl_append( MDB_IDL *idp, MDB_ID id )
{
- IDL ids = *idp;
+ MDB_IDL ids = *idp;
/* Too big? */
if (ids[0] >= ids[-1]) {
- IDL idn = ids-1;
+ MDB_IDL idn = ids-1;
/* grow it */
- idn = realloc(idn, (*idn + MDB_IDL_UM_MAX + 1) * sizeof(ID));
+ idn = realloc(idn, (*idn + MDB_IDL_UM_MAX + 1) * sizeof(MDB_ID));
if (!idn)
return -1;
*idn++ += MDB_IDL_UM_MAX;
return 0;
}
-int mdb_midl_append_list( IDL *idp, IDL app )
+int mdb_midl_append_list( MDB_IDL *idp, MDB_IDL app )
{
- IDL ids = *idp;
+ MDB_IDL ids = *idp;
/* Too big? */
if (ids[0] + app[0] >= ids[-1]) {
- IDL idn = ids-1;
+ MDB_IDL idn = ids-1;
/* grow it */
- idn = realloc(idn, (*idn + app[-1]) * sizeof(ID));
+ idn = realloc(idn, (*idn + app[-1]) * sizeof(MDB_ID));
if (!idn)
return -1;
*idn++ += app[-1];
ids = idn;
*idp = ids;
}
- memcpy(&ids[ids[0]+1], &app[1], app[0] * sizeof(ID));
+ memcpy(&ids[ids[0]+1], &app[1], app[0] * sizeof(MDB_ID));
ids[0] += app[0];
return 0;
}
#define SWAP(a,b) { itmp=(a); (a)=(b); (b)=itmp; }
void
-mdb_midl_sort( IDL ids )
+mdb_midl_sort( MDB_IDL ids )
{
/* Max possible depth of int-indexed tree * 2 items/level */
int istack[sizeof(int)*CHAR_BIT * 2];
int i,j,k,l,ir,jstack;
- ID a, itmp;
+ MDB_ID a, itmp;
ir = ids[0];
l = 1;
}
}
-unsigned mdb_mid2l_search( ID2L ids, ID id )
+unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id )
{
/*
* binary search of id in ids
return cursor;
}
-int mdb_mid2l_insert( ID2L ids, ID2 *id )
+int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id )
{
unsigned x, i;
/** @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
/** 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 );
/** @} */
/** @} */