Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 954
/* lock a list in the database. list -1 is the alloc list */
static int tdb_lock(TDB_CONTEXT *tdb, int list)
{
if (list < -1 || list >= (int)tdb->header.hash_size) {
#if TDB_DEBUG
printf("bad list %d\n", list);
#endif
return -1;
}
if (tdb->locked[list+1] == 0) {
if (tdb_brlock(tdb, LIST_LOCK_BASE + 4*list, LOCK_SET,
F_WRLCK, F_SETLKW) != 0) {
return -1;
}
}
tdb->locked[list+1]++;
return 0;
}
/* unlock the database. */
static int tdb_unlock(TDB_CONTEXT *tdb, int list)
{
if (list < -1 || list >= (int)tdb->header.hash_size) {
#if TDB_DEBUG
printf("bad unlock list %d\n", list);
#endif
return -1;
}
if (tdb->locked[list+1] == 0) {
#if TDB_DEBUG
printf("not locked %d\n", list);
#endif
tdb->ecode = TDB_ERR_LOCK;
return -1;
}
if (tdb->locked[list+1] == 1) {
if (tdb_brlock(tdb, LIST_LOCK_BASE + 4*list, LOCK_CLEAR,
F_WRLCK, F_SETLKW) != 0) {
return -1;
}
}
tdb->locked[list+1]--;
return 0;
}
/* the hash algorithm - turn a key into an integer