TCache

From Ultibo.org
Revision as of 04:36, 17 May 2018 by Ultibo (Talk | contribs) (Created page with "Return to Unit Filesystem __TOC__ === Description === ---- ''To be documented'' === Class definitions === ---- <div class="toccolours mw-collapsible...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Return to Unit Filesystem


Description


To be documented

Class definitions



TCache = class(TObject)

Note: A simple block cache with Read Only/Read Write modes and Free/Clean/Dirty page tracking. (No longer used)
 
constructor Create(ADriver:TFileSysDriver);  
destructor Destroy; override;  
private
FDriver:TFileSysDriver;  
 
FLock:TCriticalSectionHandle;  
 
FBuffer:Pointer;  
FPageSize:LongWord;  
FPageCount:LongWord;  
FCacheSize:LongWord;  
FCacheMode:TCacheMode;  
FCacheState:TCacheState;  
FCacheTimeout:LongWord;  
 
FReadCached:Int64;  
FReadDirect:Int64;  
 
FWriteBack:Int64;  
FWriteThrough:Int64;  
FWriteDirect:Int64;  
 
FHitCount:Int64;  
FMissCount:Int64;  
 
FFailCount:Int64;  
FSuccessCount:Int64;  
 
FFlushCount:Int64;  
FDiscardCount:Int64;  
FUnknownCount:Int64;  
 
FFirstPage:TCachePage; First Cache Page (Any State)
FLastPage:TCachePage; Last Cache Page (Any State)
FFirstEmpty:TCachePage; First Free Page
FLastEmpty:TCachePage; Last Free Page
FFirstClean:TCachePage; First Clean Page (Used with no Write pending)
FLastClean:TCachePage; Last Clean Page (Used with no Write pending)
FFirstDirty:TCachePage; First Dirty Page (Used with Write pending)
FLastDirty:TCachePage; Last Dirty Page (Used with Write pending)
 
FTimer:TCacheTimer;  
FThread:TCacheThread;  
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
 
function AddPage(APage:TCachePage):Boolean;  
function RemovePage(APage:TCachePage):Boolean;  
function AddEmpty(APage:TCachePage):Boolean;  
function AddClean(APage:TCachePage):Boolean;  
function AddDirty(APage:TCachePage):Boolean;  
function AddUnknown(APage:TCachePage):Boolean;  
 
function UpdateClean(APage:TCachePage):Boolean;  
function UpdateDirty(APage:TCachePage):Boolean;  
 
function RoundPageSize(APageSize:LongWord):LongWord;  
function RoundCacheSize(ACacheSize,APageSize:LongWord):LongWord;  
 
function LinkPage(APage:TCachePage):Boolean;  
function UnlinkPage(APage:TCachePage):Boolean;  
function LinkEmpty(APage:TCachePage):Boolean;  
function UnlinkEmpty(APage:TCachePage):Boolean;  
function LinkClean(APage:TCachePage):Boolean;  
function UnlinkClean(APage:TCachePage):Boolean;  
function LinkDirty(APage:TCachePage):Boolean;  
function UnlinkDirty(APage:TCachePage):Boolean;  
public
property PageSize:LongWord read FPageSize;  
property PageCount:LongWord read FPageCount;  
property CacheSize:LongWord read FCacheSize;  
property CacheMode:TCacheMode read FCacheMode;  
property CacheState:TCacheState read FCacheState;  
property CacheTimeout:LongWord read FCacheTimeout;  
 
property ReadCached:Int64 read FReadCached;  
property ReadDirect:Int64 read FReadDirect;  
 
property WriteBack:Int64 read FWriteBack;  
property WriteThrough:Int64 read FWriteThrough;  
property WriteDirect:Int64 read FWriteDirect;  
 
property HitCount:Int64 read FHitCount;  
property MissCount:Int64 read FMissCount;  
 
property FailCount:Int64 read FFailCount;  
property SuccessCount:Int64 read FSuccessCount;  
 
property FlushCount:Int64 read FFlushCount;  
property DiscardCount:Int64 read FDiscardCount;  
property UnknownCount:Int64 read FUnknownCount;  
 
function OpenCache(ACacheSize,APageSize:LongWord; ACacheMode:TCacheMode):Boolean;  
function CloseCache:Boolean;  
 
function DeviceRead(ADevice:TDiskDevice; ASector:LongWord; ACount:Word; var ABuffer):Boolean;  
function DeviceErase(ADevice:TDiskDevice; ASector:LongWord; ACount:Word):Boolean;  
 
function GetDevicePage(ADevice:TDiskDevice; ASector:LongWord):TCachePage; virtual;  
function GetEmptyPage:TCachePage;  
 
function AllocDevicePage(ADevice:TDiskDevice; ASector:LongWord; AWrite:Boolean):TCachePage; virtual;  
 
function DiscardPage(APage:TCachePage):Boolean;  
function DiscardCache(AFirst,AAll:Boolean):Boolean;  
 
function ReleaseDevicePages(ADevice:TDiskDevice):Boolean;  
 
function FlushPage(APage:TCachePage):Boolean;  
function FlushPageEx(APage:TCachePage):Boolean;  
function FlushCache(AFirst,AAll:Boolean):Boolean;  
 
function CheckTimer:Boolean;  
function ProcessTimer:Boolean;  
 
function SchedulePage(APage:TCachePage; ATimeout:LongWord):Boolean;  
function UnschedulePage(APage:TCachePage):Boolean;  


Function declarations



constructor TCache.Create(ADriver:TFileSysDriver);
Description: To be documented
Note None documented


destructor TCache.Destroy;
Description: To be documented
Note None documented


function TCache.AcquireLock:Boolean;
Description: To be documented
Note None documented


function TCache.ReleaseLock:Boolean;
Description: To be documented
Note None documented


function TCache.AddPage(APage:TCachePage):Boolean;
Description: Add a new page to the Page list and the Empty list
Note None documented


function TCache.RemovePage(APage:TCachePage):Boolean;
Description: Remove a Page from the Page list and any other lists then Free the Page
Note None documented


function TCache.AddEmpty(APage:TCachePage):Boolean;
Description: Add a Page to the Empty list, removing from other lists if needed
Note None documented


function TCache.AddClean(APage:TCachePage):Boolean;
Description: Add a Page to the Clean list, removing from other lists if needed
Note None documented


function TCache.AddDirty(APage:TCachePage):Boolean;
Description: Add a Page to the Dirty list, removing from other lists if needed
Note None documented


function TCache.AddUnknown(APage:TCachePage):Boolean;
Description: Make a Page Unknown by removing from any other lists if needed
Note None documented


function TCache.UpdateClean(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Clean list
Note None documented


function TCache.UpdateDirty(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Dirty list
Note None documented


function TCache.RoundPageSize(APageSize:LongWord):LongWord;
Description: Round Page Size to the power of 2 of Sector Size
Note Caller must hold the lock


function TCache.RoundCacheSize(ACacheSize,APageSize:LongWord):LongWord;
Description: Round Cache Size to the next multiple of Page Size
Note Caller must hold the lock


function TCache.LinkPage(APage:TCachePage):Boolean;
Description: Link APage to PrevPage,NextPage siblings and Adjust FirstPage/LastPage
Note Caller must hold the lock


function TCache.UnlinkPage(APage:TCachePage):Boolean;
Description: Unlink APage from PrevPage,NextPage Siblings and Adjust FirstPage/LastPage
Note Caller must hold the lock


function TCache.LinkEmpty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstEmpty/LastEmpty
Note Caller must hold the lock


function TCache.UnlinkEmpty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstEmpty/LastEmpty
Note Caller must hold the lock


function TCache.LinkClean(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstClean/LastClean
Note Caller must hold the lock


function TCache.UnlinkClean(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstClean/LastClean
Note Caller must hold the lock


function TCache.LinkDirty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstDirty/LastDirty
Note Caller must hold the lock


function TCache.UnlinkDirty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstDirty/LastDirty
Note None documented


function TCache.PrepareDeviceWrite(ADevice:TDiskDevice; APage:TCachePage; ASector,ACount:LongWord):Boolean;
Description: Prepare a Cache Page for Write by ensuring that required sectors are cached
Sector Passed Sector will be the starting sector for the write to this Page
Count Passed Count will be the write count to this Page (Calculated by caller)
Note Only called internally by DeviceWrite

Caller must hold the lock


function TCache.CalculateDevicePage(ADevice:TDiskDevice; ASector:LongWord; var ACount:LongWord):Boolean;
Description: Calculate the number of sectors remaining in a page given the starting sector
Note Only called internally by DeviceRead/DeviceWrite/DeviceErase

Caller must hold the lock


function TCache.OpenCache(ACacheSize,APageSize:LongWord; ACacheMode:TCacheMode):Boolean;
Description: Allocate the Memory, Create the Empty Pages and Open Cache
Note None documented


function TCache.CloseCache:Boolean;
Description: Flush all Dirty Pages, Release the Memory and Close the Cache
Note None documented


function TCache.DeviceRead(ADevice:TDiskDevice; ASector,ACount:LongWord; var ABuffer):Boolean;
Description: Read Data from the Physical Device using either Cached or Direct access
Note AllocDevicePage does all checks for Size, Sector and Count.


function TCache.DeviceWrite(ADevice:TDiskDevice; ASector,ACount:LongWord; const ABuffer):Boolean;
Description: Write Data to the Physical Device using either Cached or Direct access
Note AllocDevicePage does all checks for Size, Sector and Count.


function TCache.DeviceErase(ADevice:TDiskDevice; ASector,ACount:LongWord):Boolean;
Description: Erase Data from the Physical Device and update cached pages accordingly
Note None documented


function TCache.GetDevicePage(ADevice:TDiskDevice; ASector:LongWord):TCachePage;
Description: Get the Clean or Dirty Page that contains this Sector on this Device
Note None documented


function TCache.GetEmptyPage:TCachePage;
Description: Get the First Empty Page, Discard First Clean Page if none Empty
Note None documented


function TCache.AllocDevicePage(ADevice:TDiskDevice; ASector:LongWord; AWrite:Boolean):TCachePage;
Description: Allocate an Empty Page to the Device and mark as Clean or Dirty
Note None documented


function TCache.DiscardPage(APage:TCachePage):Boolean;
Description: Return a Clean Page to Empty
Note None documented


function TCache.DiscardCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Clean Pages older than CacheTimeout and Discard them
Note None documented


function TCache.ReleaseDevicePages(ADevice:TDiskDevice):Boolean;
Description: Return all Clean or Dirty Pages on the Device to Empty
Note None documented


function TCache.FlushPage(APage:TCachePage):Boolean;
Description: Return a Dirty Page to Clean
Note None documented


function TCache.FlushPageEx(APage:TCachePage):Boolean;
Description: Return a Dirty Page to Clean if it is older than CacheTimeout
Note Only called by CacheThread with page scheduled from CacheTimer


function TCache.FlushCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Dirty Pages older than CacheTimeout and Flush them
Note None documented


function TCache.CheckTimer:Boolean;
Description: To be documented
Note None documented


function TCache.ProcessTimer:Boolean;
Description: To be documented
Note None documented


function TCache.SchedulePage(APage:TCachePage; ATimeout:LongWord):Boolean;
Description: To be documented
Note None documented


function TCache.UnschedulePage(APage:TCachePage):Boolean;
Description: To be documented
Note None documented


Return to Unit Reference