mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-03-07 14:18:15 +08:00
libmdb: midl.h namespace cleanup.
Prefix ID, NOID, ID2, IDL, ID2L with 'MDB_'. Also drop bdb from file description.
This commit is contained in:
parent
0a4aa88927
commit
20baad4a20
@ -238,12 +238,12 @@
|
||||
* @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
|
||||
* @{
|
||||
@ -819,9 +819,9 @@ struct MDB_txn {
|
||||
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. */
|
||||
@ -961,9 +961,9 @@ struct MDB_env {
|
||||
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
|
||||
@ -1129,14 +1129,14 @@ static void mdb_audit(MDB_txn *txn)
|
||||
{
|
||||
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;
|
||||
|
||||
@ -1217,7 +1217,7 @@ mdb_page_alloc(MDB_cursor *mc, int num)
|
||||
MDB_txn *txn = mc->mc_txn;
|
||||
MDB_page *np;
|
||||
pgno_t pgno = P_INVALID;
|
||||
ID2 mid;
|
||||
MDB_ID2 mid;
|
||||
|
||||
if (txn->mt_txnid > 2) {
|
||||
|
||||
@ -1272,7 +1272,7 @@ again:
|
||||
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
|
||||
*/
|
||||
@ -1410,7 +1410,7 @@ finish:
|
||||
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.
|
||||
*/
|
||||
@ -1679,7 +1679,7 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
|
||||
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);
|
||||
@ -1866,7 +1866,7 @@ mdb_txn_commit(MDB_txn *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];
|
||||
@ -1961,7 +1961,7 @@ free2:
|
||||
#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++) {
|
||||
|
@ -31,7 +31,7 @@
|
||||
#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
|
||||
@ -66,7 +66,7 @@ static unsigned mdb_midl_search( IDL ids, ID id )
|
||||
return cursor;
|
||||
}
|
||||
|
||||
int mdb_midl_insert( IDL ids, ID id )
|
||||
int mdb_midl_insert( MDB_IDL ids, MDB_ID id )
|
||||
{
|
||||
unsigned x, i;
|
||||
|
||||
@ -104,7 +104,7 @@ int mdb_midl_insert( IDL ids, ID id )
|
||||
} else {
|
||||
ids[2] = ids[ids[0]-1];
|
||||
}
|
||||
ids[0] = NOID;
|
||||
ids[0] = MDB_NOID;
|
||||
|
||||
} else {
|
||||
/* insert id */
|
||||
@ -117,23 +117,23 @@ int mdb_midl_insert( IDL ids, ID 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;
|
||||
@ -141,14 +141,14 @@ int mdb_midl_shrink( IDL *idp )
|
||||
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;
|
||||
@ -160,21 +160,21 @@ int mdb_midl_append( IDL *idp, ID id )
|
||||
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;
|
||||
}
|
||||
@ -185,12 +185,12 @@ int mdb_midl_append_list( IDL *idp, IDL app )
|
||||
#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;
|
||||
@ -245,7 +245,7 @@ mdb_midl_sort( IDL ids )
|
||||
}
|
||||
}
|
||||
|
||||
unsigned mdb_mid2l_search( ID2L ids, ID id )
|
||||
unsigned mdb_mid2l_search( MDB_ID2L ids, MDB_ID id )
|
||||
{
|
||||
/*
|
||||
* binary search of id in ids
|
||||
@ -280,7 +280,7 @@ unsigned mdb_mid2l_search( ID2L ids, ID id )
|
||||
return cursor;
|
||||
}
|
||||
|
||||
int mdb_mid2l_insert( ID2L ids, ID2 *id )
|
||||
int mdb_mid2l_insert( MDB_ID2L ids, MDB_ID2 *id )
|
||||
{
|
||||
unsigned x, i;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/** @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
|
||||
@ -42,7 +42,7 @@ extern "C" {
|
||||
/** 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
|
||||
@ -50,9 +50,9 @@ typedef size_t ID;
|
||||
* 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
|
||||
@ -60,24 +60,24 @@ typedef ID *IDL;
|
||||
#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)
|
||||
@ -90,7 +90,7 @@ typedef ID *IDL;
|
||||
} 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 ) ))
|
||||
@ -111,66 +111,66 @@ typedef ID *IDL;
|
||||
* @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.
|
||||
@ -178,7 +178,7 @@ unsigned mdb_mid2l_search( ID2L ids, ID id );
|
||||
* @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 );
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user