本文整理汇总了C#中Btree类的典型用法代码示例。如果您正苦于以下问题:C#Btree类的具体用法?C#Btree怎么用?C#Btree使用的例子?这里精选的类代码示例或许可以为您提供帮助。
示例1:sqlite3BtreeEnter
/*
**EnteramutexonthegivenBTreeobject.
**
**Iftheobjectisnotsharable,thennomutexiseverrequired
**andthisroutineisano-op.Theunderlyingmutexisnon-recursive.
**ButwekeepareferencecountinBtree.wantToLocksothebehavior
**ofthisinterfaceisrecursive.
**
**Toavoiddeadlocks,multipleBtreesarelockedinthesameorder
**byalldatabaseconnections.Thep->pNextisalistofother
**BtreesbelongingtothesamedatabaseconnectionasthepBtree
**whichneedtobelockedafterp.Ifwecannotgetalockon
**p,thenfirstunlockalloftheothersonp->pNext,thenwait
**forthelocktobecomeavailableonp,thenrelockallofthe
**subsequentBtreesthatdesirealock.
*/
voidsqlite3BtreeEnter(Btree*p)
{
Btree*pLater;
/*SomebasicsanitycheckingontheBtree.ThelistofBtrees
**connectedbypNextandpPrevshouldbeinsortedorderby
**Btree.pBtvalue.Allelementsofthelistshouldbelongto
**thesameconnection.OnlysharedBtreesareonthelist.*/
assert(p->pNext==0||p->pNext->pBt>p->pBt);
assert(p->pPrev==0||p->pPrev->pBt
pBt);
assert(p->pNext==0||p->pNext->db==p->db);
assert(p->pPrev==0||p->pPrev->db==p->db);
assert(p->sharable||(p->pNext==0&&p->pPrev==0));
/*Checkforlockingconsistency*/
assert(!p->locked||p->wantToLock>0);
assert(p->sharable||p->wantToLock==0);
/*Weshouldalreadyholdalockonthedatabaseconnection*/
assert(sqlite3_mutex_held(p->db->mutex));
/*Unlessthedatabaseissharableandunlocked,thenBtShared.db
**shouldalreadybesetcorrectly.*/
assert((p->locked==0&&p->sharable)||p->pBt->db==p->db);
if(!p->sharable)return;
p->wantToLock++;
if(p->locked)return;
/*Inmostcases,weshouldbeabletoacquirethelockwe
**wantwithouthavingtogothroughttheascendinglock
**procedurethatfollows.Justbesurenottoblock.
*/
if(sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK){
p->pBt->db=p->db;
p->locked=1;
return;
}
/*Toavoiddeadlock,firstreleasealllockswithalarger
**BtSharedaddress.Thenacquireourlock.Thenreacquire
**theotherBtSharedlocksthatweusedtoholdinascending
**order.
*/
for(pLater=p->pNext;pLater;pLater=pLater->pNext){
assert(pLater->sharable);
assert(pLater->pNext==0||pLater->pNext->pBt>pLater->pBt);
assert(!pLater->locked||pLater->wantToLock>0);
if(pLater->locked){
unlockBtreeMutex(pLater);
}
}
lockBtreeMutex(p);
for(pLater=p->pNext;pLater;pLater=pLater->pNext){
if(pLater->wantToLock){
lockBtreeMutex(pLater);
}
}
}
原文链接:http://www.jxszl.com/biancheng/C/556586.html