本文整理汇总了C#中BtShared类的典型用法代码示例。如果您正苦于以下问题:C# BtShared类的具体用法?C# BtShared怎么用?C# BtShared使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BtShared类属于命名空间,在下文中一共展示了BtShared类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: btreeGetPage
static RC btreeGetPage(BtShared bt, Pid id, ref MemPage page, bool noContent)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
IPage dbPage = null;
var rc = bt.Pager.Acquire(id, ref dbPage, noContent);
if (rc != RC.OK) return rc;
page = btreePageFromDbPage(dbPage, id, bt);
return RC.OK;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:9,代码来源:Btree.cs
示例2: ptrmapPageno
static Pid ptrmapPageno(BtShared bt, Pid id)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
if (id < 2) return 0;
var pagesPerMapPage = (int)(bt.UsableSize / 5 + 1);
var ptrMap = (Pid)((id - 2) / pagesPerMapPage);
var ret = (Pid)(ptrMap * pagesPerMapPage) + 2;
if (ret == PENDING_BYTE_PAGE(bt))
ret++;
return ret;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:11,代码来源:Btree.cs
示例3: ptrmapGet
static RC ptrmapGet(BtShared bt, Pid key, ref PTRMAP type, ref Pid id)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
var page = (IPage)new PgHdr(); // The pointer map page
var ptrmapIdx = (Pid)PTRMAP_PAGENO(bt, key); // Pointer map page index
var rc = bt.Pager.Acquire(ptrmapIdx, ref page, false);
if (rc != RC.OK)
return rc;
var ptrmap = Pager.GetData(page); // Pointer map page data
var offset = (int)PTRMAP_PTROFFSET(ptrmapIdx, key); // Offset of entry in pointer map
if (offset < 0)
{
Pager.Unref(page);
return SysEx.CORRUPT_BKPT();
}
Debug.Assert(offset <= (int)bt.UsableSize - 5);
Debug.Assert(type != 0);
type = (PTRMAP)ptrmap[offset];
id = ConvertEx.Get4(ptrmap, offset + 1);
Pager.Unref(page);
if ((byte)type < 1 || (byte)type > 5) return SysEx.CORRUPT_BKPT();
return RC.OK;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:26,代码来源:Btree.cs
示例4: btreeClearHasContent
static void btreeClearHasContent(BtShared bt)
{
Bitvec.Destroy(ref bt.HasContent);
bt.HasContent = null;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:5,代码来源:Btree.cs
示例5: saveAllCursors
static RC saveAllCursors(BtShared bt, Pid root, BtCursor except)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
Debug.Assert(except == null || except.Bt == bt);
for (var p = bt.Cursor; p != null; p = p.Next)
{
if (p != except && (root == 0 || p.RootID == root) && p.State == CURSOR.VALID)
{
var rc = saveCursorPosition(p);
if (rc != RC.OK)
return rc;
}
}
return RC.OK;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:15,代码来源:Btree.cs
示例6: invalidateAllOverflowCache
static void invalidateAllOverflowCache(BtShared bt)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
for (var p = bt.Cursor; p != null; p = p.Next)
invalidateOverflowCache(p);
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:6,代码来源:Btree.cs
示例7: btreeSetHasContent
static RC btreeSetHasContent(BtShared bt, Pid id)
{
var rc = RC.OK;
if (bt.HasContent == null)
{
Debug.Assert(id <= bt.Pages);
bt.HasContent = new Bitvec(bt.Pages);
}
if (rc == RC.OK && id <= bt.HasContent.Length)
rc = bt.HasContent.Set(id);
return rc;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:12,代码来源:Btree.cs
示例8: allocateTempSpace
static void allocateTempSpace(BtShared bt)
{
if (bt.TmpSpace == null)
bt.TmpSpace = PCache.PageAlloc2((int)bt.PageSize);
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:5,代码来源:Btree.cs
示例9: freeTempSpace
static void freeTempSpace(BtShared bt)
{
PCache.PageFree2(ref bt.TmpSpace);
bt.TmpSpace = null;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:5,代码来源:Btree.cs
示例10: Open
public static RC Open(VSystem vfs, string filename, BContext ctx, ref Btree btree, OPEN flags, VSystem.OPEN vfsFlags)
{
// True if opening an ephemeral, temporary database
bool tempDB = string.IsNullOrEmpty(filename);
// Set the variable isMemdb to true for an in-memory database, or false for a file-based database.
bool memoryDB = (filename == ":memory:") ||
(tempDB && ctx.TempInMemory()) ||
(vfsFlags & VSystem.OPEN.MEMORY) != 0;
Debug.Assert(ctx != null);
Debug.Assert(vfs != null);
Debug.Assert(MutexEx.Held(ctx.Mutex));
Debug.Assert(((uint)flags & 0xff) == (uint)flags); // flags fit in 8 bits
// Only a BTREE_SINGLE database can be BTREE_UNORDERED
Debug.Assert((flags & OPEN.UNORDERED) == 0 || (flags & OPEN.SINGLE) != 0);
// A BTREE_SINGLE database is always a temporary and/or ephemeral
Debug.Assert((flags & OPEN.SINGLE) == 0 || tempDB);
if (memoryDB)
flags |= OPEN.MEMORY;
if ((vfsFlags & VSystem.OPEN.MAIN_DB) != 0 && (memoryDB || tempDB))
vfsFlags = (vfsFlags & ~VSystem.OPEN.MAIN_DB) | VSystem.OPEN.TEMP_DB;
var p = new Btree(); // Handle to return
if (p == null)
return RC.NOMEM;
p.InTrans = TRANS.NONE;
p.Ctx = ctx;
#if !OMIT_SHARED_CACHE
p.Lock.Btree = p;
p.Lock.Table = 1;
#endif
RC rc = RC.OK; // Result code from this function
BtShared bt = null; // Shared part of btree structure
MutexEx mutexOpen = null;
#if !OMIT_SHARED_CACHE && !OMIT_DISKIO
// If this Btree is a candidate for shared cache, try to find an existing BtShared object that we can share with
if (!tempDB && (!memoryDB || (vfsFlags & VSystem.OPEN.URI) != 0))
if ((vfsFlags & VSystem.OPEN.SHAREDCACHE) != 0)
{
string fullPathname;
p.Sharable_ = true;
if (memoryDB)
fullPathname = filename;
else
vfs.FullPathname(filename, out fullPathname);
MutexEx mutexShared;
#if THREADSAFE
mutexOpen = MutexEx.Alloc(MutexEx.MUTEX.STATIC_OPEN); // Prevents a race condition. Ticket #3537
MutexEx.Enter(mutexOpen);
mutexShared = MutexEx.Alloc(MutexEx.MUTEX.STATIC_MASTER);
MutexEx.Enter(mutexShared);
#endif
for (bt = _sharedCacheList; bt != null; bt = bt.Next)
{
Debug.Assert(bt.Refs > 0);
if (fullPathname == bt.Pager.get_Filename(false) && bt.Pager.get_Vfs() == vfs)
{
for (var i = ctx.DBs.length - 1; i >= 0; i--)
{
var existing = ctx.DBs[i].Bt;
if (existing != null && existing.Bt == bt)
{
MutexEx.Leave(mutexShared);
MutexEx.Leave(mutexOpen);
fullPathname = null;
p = null;
return RC.CONSTRAINT;
}
}
p.Bt = bt;
bt.Refs++;
break;
}
}
MutexEx.Leave(mutexShared);
fullPathname = null;
}
#if DEBUG
else
// In debug mode, we mark all persistent databases as sharable even when they are not. This exercises the locking code and
// gives more opportunity for asserts(sqlite3_mutex_held()) statements to find locking problems.
p.Sharable_ = true;
#endif
#endif
byte reserves; // Byte of unused space on each page
var dbHeader = new byte[100]; // Database header content
if (bt == null)
{
// The following asserts make sure that structures used by the btree are the right size. This is to guard against size changes that result
// when compiling on a different architecture.
Debug.Assert(sizeof(long) == 8 || sizeof(long) == 4);
Debug.Assert(sizeof(ulong) == 8 || sizeof(ulong) == 4);
Debug.Assert(sizeof(uint) == 4);
Debug.Assert(sizeof(ushort) == 2);
Debug.Assert(sizeof(Pid) == 4);
//.........这里部分代码省略.........
开发者ID:BclEx,项目名称:GpuStructs,代码行数:101,代码来源:Btree.cs
示例11: removeFromSharingList
static bool removeFromSharingList(BtShared bt)
{
#if !OMIT_SHARED_CACHE
Debug.Assert(MutexEx.Held(bt.Mutex));
#if THREADSAFE
var master = MutexEx.Alloc(MutexEx.MUTEX.STATIC_MASTER);
#endif
var removed = false;
MutexEx.Enter(master);
bt.Refs--;
if (bt.Refs <= 0)
{
if (_sharedCacheList == bt)
_sharedCacheList = bt.Next;
else
{
var list = _sharedCacheList;
while (C._ALWAYS(list != null) && list.Next != bt)
list = list.Next;
if (C._ALWAYS(list != null))
list.Next = bt.Next;
}
#if THREADSAFE
MutexEx.Free(bt.Mutex);
#endif
removed = true;
}
MutexEx.Leave(master);
return removed;
#else
return true;
#endif
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:33,代码来源:Btree.cs
示例12: getAndInitPage
static RC getAndInitPage(BtShared bt, Pid id, ref MemPage page)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
RC rc;
if (id > btreePagecount(bt))
rc = SysEx.CORRUPT_BKPT();
else
{
rc = btreeGetPage(bt, id, ref page, false);
if (rc == RC.OK)
{
rc = btreeInitPage(page);
if (rc != RC.OK)
releasePage(page);
}
}
Debug.Assert(id != 0 || rc == RC.CORRUPT);
return rc;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:21,代码来源:Btree.cs
示例13: btreePagecount
static Pid btreePagecount(BtShared bt)
{
return bt.Pages;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:4,代码来源:Btree.cs
示例14: btreePageLookup
static MemPage btreePageLookup(BtShared bt, Pid id)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
var dbPage = bt.Pager.Lookup(id);
return (dbPage != null ? btreePageFromDbPage(dbPage, id, bt) : null);
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:6,代码来源:Btree.cs
示例15: countWriteCursors
static int countWriteCursors(BtShared bt)
{
int r = 0;
for (var cur = bt.Cursor; cur != null; cur = cur.Next)
if (cur.WrFlag && cur.State != CURSOR.FAULT) r++;
return r;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:7,代码来源:Btree.cs
示例16: lockBtree
static RC lockBtree(BtShared bt)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
Debug.Assert(bt.Page1 == null);
var rc = bt.Pager.SharedLock();
if (rc != RC.OK) return rc;
MemPage page1 = null; // Page 1 of the database file
rc = btreeGetPage(bt, 1, ref page1, false);
if (rc != RC.OK) return rc;
// Do some checking to help insure the file we opened really is a valid database file.
Pid pagesHeader; // Number of pages in the database according to hdr
Pid pages = pagesHeader = ConvertEx.Get4(page1.Data, 28); // Number of pages in the database
Pid pagesFile = 0; // Number of pages in the database file
bt.Pager.Pages(out pagesFile);
if (pages == 0 || C.memcmp(page1.Data, 24, page1.Data, 92, 4) != 0)
pages = pagesFile;
if (pages > 0)
{
var page1Data = page1.Data;
rc = RC.NOTADB;
if (C.memcmp(page1Data, _magicHeader, 16) != 0)
goto page1_init_failed;
#if OMIT_WAL
if (page1Data[18] > 1)
bt.BtsFlags |= BTS.READ_ONLY;
if (page1Data[19] > 1)
goto page1_init_failed;
#else
if (page1Data[18] > 2)
bt.BtsFlags |= BTS.READ_ONLY;
if (page1Data[19] > 2)
goto page1_init_failed;
// return SQLITE_OK and return without populating BtShared.pPage1. The caller detects this and calls this function again. This is
// required as the version of page 1 currently in the page1 buffer may not be the latest version - there may be a newer one in the log file.
if (page1Data[19] == 2 && (bt.BtsFlags & BTS.NO_WAL) == 0)
{
int isOpen = 0;
rc = bt.Pager.OpenWal(ref isOpen);
if (rc != RC.OK)
goto page1_init_failed;
else if (isOpen == 0)
{
releasePage(page1);
return RC.OK;
}
rc = RC.NOTADB;
}
#endif
// The maximum embedded fraction must be exactly 25%. And the minimum embedded fraction must be 12.5% for both leaf-data and non-leaf-data.
// The original design allowed these amounts to vary, but as of version 3.6.0, we require them to be fixed.
if (C.memcmp(page1Data, 21, "\x0040\x0020\x0020", 3) != 0) // "\100\040\040"
goto page1_init_failed;
uint pageSize = (uint)((page1Data[16] << 8) | (page1Data[17] << 16));
if (((pageSize - 1) & pageSize) != 0 ||
pageSize > Pager.MAX_PAGE_SIZE ||
pageSize <= 256)
goto page1_init_failed;
Debug.Assert((pageSize & 7) == 0);
uint usableSize = pageSize - page1Data[20];
if (pageSize != bt.PageSize)
{
// After reading the first page of the database assuming a page size of BtShared.pageSize, we have discovered that the page-size is
// actually pageSize. Unlock the database, leave pBt->pPage1 at zero and return SQLITE_OK. The caller will call this function
// again with the correct page-size.
releasePage(page1);
bt.UsableSize = usableSize;
bt.PageSize = pageSize;
freeTempSpace(bt);
rc = bt.Pager.SetPageSize(ref bt.PageSize, (int)(pageSize - usableSize));
return rc;
}
if ((bt.Ctx.Flags & BContext.FLAG.RecoveryMode) == 0 && pages > pagesFile)
{
rc = SysEx.CORRUPT_BKPT();
goto page1_init_failed;
}
if (usableSize < 480)
goto page1_init_failed;
bt.PageSize = pageSize;
bt.UsableSize = usableSize;
#if !OMIT_AUTOVACUUM
bt.AutoVacuum = (ConvertEx.Get4(page1Data, 36 + 4 * 4) != 0);
bt.IncrVacuum = (ConvertEx.Get4(page1Data, 36 + 7 * 4) != 0);
#endif
}
// maxLocal is the maximum amount of payload to store locally for a cell. Make sure it is small enough so that at least minFanout
// cells can will fit on one page. We assume a 10-byte page header. Besides the payload, the cell must store:
// 2-byte pointer to the cell
// 4-byte child pointer
// 9-byte nKey value
// 4-byte nData value
// 4-byte overflow page pointer
// So a cell consists of a 2-byte pointer, a header which is as much as 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
// page pointer.
bt.MaxLocal = (ushort)((bt.UsableSize - 12) * 64 / 255 - 23);
//.........这里部分代码省略.........
开发者ID:BclEx,项目名称:GpuStructs,代码行数:101,代码来源:Btree.cs
示例17: getOverflowPage
static RC getOverflowPage(BtShared bt, Pid ovfl, out MemPage pageOut, out Pid idNextOut)
{
Pid next = 0;
MemPage page = null;
pageOut = null;
var rc = RC.OK;
Debug.Assert(MutexEx.Held(bt.Mutex));
#if !OMIT_AUTOVACUUM
// Try to find the next page in the overflow list using the autovacuum pointer-map pages. Guess that the next page in
// the overflow list is page number (ovfl+1). If that guess turns out to be wrong, fall back to loading the data of page
// number ovfl to determine the next page number.
if (bt.AutoVacuum)
{
Pid guess = ovfl + 1;
while (PTRMAP_ISPAGE(bt, guess) || guess == PENDING_BYTE_PAGE(bt))
guess++;
if (guess <= btreePagecount(bt))
{
Pid id = 0;
PTRMAP type = 0;
rc = ptrmapGet(bt, guess, ref type, ref id);
if (rc == RC.OK && type == PTRMAP.OVERFLOW2 && id == ovfl)
{
next = guess;
rc = RC.DONE;
}
}
}
#endif
Debug.Assert(next == 0 || rc == RC.DONE);
if (rc == RC.OK)
{
rc = btreeGetPage(bt, ovfl, ref page, false);
Debug.Assert(rc == RC.OK || page == null);
if (rc == RC.OK)
next = ConvertEx.Get4(page.Data);
}
idNextOut = next;
if (pageOut != null)
pageOut = page;
else
releasePage(page);
return (rc == RC.DONE ? RC.OK : rc);
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:49,代码来源:Btree.cs
示例18: unlockBtreeIfUnused
static void unlockBtreeIfUnused(BtShared bt)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
Debug.Assert(bt.Cursor == null || bt.InTransaction > TRANS.NONE);
if (bt.InTransaction == TRANS.NONE && bt.Page1 != null)
{
Debug.Assert(bt.Page1.Data != null);
Debug.Assert(bt.Pager.get_Refs() == 1);
releasePage(bt.Page1);
bt.Page1 = null;
}
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:12,代码来源:Btree.cs
示例19: newDatabase
static RC newDatabase(BtShared bt)
{
Debug.Assert(MutexEx.Held(bt.Mutex));
if (bt.Pages > 0)
return RC.OK;
var p1 = bt.Page1;
Debug.Assert(p1 != null);
var data = p1.Data;
var rc = Pager.Write(p1.DBPage);
if (rc != RC.OK) return rc;
Buffer.BlockCopy(_magicHeader, 0, data, 0, _magicHeader.Length);
Debug.Assert(_magicHeader.Length == 16);
data[16] = (byte)((bt.PageSize >> 8) & 0xff);
data[17] = (byte)((bt.PageSize >> 16) & 0xff);
data[18] = 1;
data[19] = 1;
Debug.Assert(bt.UsableSize <= bt.PageSize && bt.UsableSize + 255 >= bt.PageSize);
data[20] = (byte)(bt.PageSize - bt.UsableSize);
data[21] = 64;
data[22] = 32;
data[23] = 32;
//_memset(&data[24], 0, 100 - 24);
zeroPage(p1, PTF_INTKEY | PTF_LEAF | PTF_LEAFDATA);
bt.BtsFlags |= BTS.PAGESIZE_FIXED;
#if !SQLITE_OMIT_AUTOVACUUM
ConvertEx.Put4(data, 36 + 4 * 4, bt.AutoVacuum ? 1 : 0);
ConvertEx.Put4(data, 36 + 7 * 4, bt.IncrVacuum ? 1 : 0);
#endif
bt.Pages = 1;
data[31] = 1;
return RC.OK;
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:32,代码来源:Btree.cs
示例20: btreeGetHasContent
static bool btreeGetHasContent(BtShared bt, Pid id)
{
var p = bt.HasContent;
return (p != null && (id > p.Length || p.Get(id)));
}
开发者ID:BclEx,项目名称:GpuStructs,代码行数:5,代码来源:Btree.cs
注:本文中的BtShared类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论