コード例 #1
0
ANSC_STATUS
BwrmPmoAddPage
    (
        ANSC_HANDLE                 hThisObject,
        char*                       root_path,
        char*                       file_path,
        ANSC_HANDLE                 hCookedPage
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PBWRM_PAGE_MANAGER_OBJECT       pMyObject         = (PBWRM_PAGE_MANAGER_OBJECT    )hThisObject;
    PBWRM_PAGE_MANAGER_PROPERTY     pProperty         = (PBWRM_PAGE_MANAGER_PROPERTY  )&pMyObject->Property;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pCacheTimerObject = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hCacheTimerObject;
    PBWRM_COOKED_PAGE_OBJECT        pCookedPage       = (PBWRM_COOKED_PAGE_OBJECT     )hCookedPage;
    ULONG                           ulHashIndex       = (ULONG                        )AnscHashString(file_path, AnscSizeOfString(file_path), BWRM_PMO_CPO_TABLE_SIZE);
    ULONG                           ulPageCount       = 0;
    ULONG                           ulCurTime         = AnscGetTickInSeconds();

    pMyObject->Timestamp = ulCurTime;

    pCookedPage->SetRootPath ((ANSC_HANDLE)pCookedPage, root_path);
    pCookedPage->SetPagePath ((ANSC_HANDLE)pCookedPage, file_path);
    pCookedPage->SetTimestamp((ANSC_HANDLE)pCookedPage, ulCurTime);
    pCookedPage->IncRefCount ((ANSC_HANDLE)pCookedPage           );

    AnscAcquireLock   (&pMyObject->CpoTableLock);
    AnscSListPushEntry(&pMyObject->CpoTable[ulHashIndex], &pCookedPage->Linkage);
    AnscReleaseLock   (&pMyObject->CpoTableLock);

    if ( TRUE )
    {
        ulPageCount = pMyObject->GetPageCount((ANSC_HANDLE)pMyObject);

        if ( ulPageCount == 1 )
        {
            pCacheTimerObject->Start((ANSC_HANDLE)pCacheTimerObject);
        }
        else if ( ulPageCount > pProperty->CacheEntryCount )
        {
            pCookedPage = (PBWRM_COOKED_PAGE_OBJECT)pMyObject->GetOldestPage((ANSC_HANDLE)pMyObject);

            if ( pCookedPage && 0 == pCookedPage->GetRefCount((ANSC_HANDLE)pCookedPage) )
            {
                returnStatus =
                    pMyObject->DelPage
                        (
                            (ANSC_HANDLE)pMyObject,
                            pCookedPage->GetRootPath((ANSC_HANDLE)pCookedPage),
                            pCookedPage->GetPagePath((ANSC_HANDLE)pCookedPage)
                        );
            }
        }
    }

    return  ANSC_STATUS_SUCCESS;
}
コード例 #2
0
ANSC_HANDLE
BwrmPmoGetPage
    (
        ANSC_HANDLE                 hThisObject,
        char*                       root_path,
        char*                       file_path
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PBWRM_PAGE_MANAGER_OBJECT       pMyObject         = (PBWRM_PAGE_MANAGER_OBJECT    )hThisObject;
    PBWRM_PAGE_MANAGER_PROPERTY     pProperty         = (PBWRM_PAGE_MANAGER_PROPERTY  )&pMyObject->Property;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pCacheTimerObject = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hCacheTimerObject;
    PBWRM_COOKED_PAGE_OBJECT        pCookedPage       = (PBWRM_COOKED_PAGE_OBJECT     )NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry       = (PSINGLE_LINK_ENTRY           )NULL;
    ULONG                           ulHashIndex       = (ULONG                        )AnscHashString(file_path, AnscSizeOfString(file_path), BWRM_PMO_CPO_TABLE_SIZE);
    ULONG                           ulCurTime         = AnscGetTickInSeconds();

    pMyObject->Timestamp = ulCurTime;

    AnscAcquireLock(&pMyObject->CpoTableLock);

    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->CpoTable[ulHashIndex]);

    while ( pSLinkEntry )
    {
        pCookedPage = ACCESS_BWRM_COOKED_PAGE_OBJECT(pSLinkEntry);
        pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry);

        if ( pCookedPage->MatchPath
                (
                    (ANSC_HANDLE)pCookedPage,
                    root_path,
                    file_path
                ) )
        {
            pCookedPage->SetTimestamp((ANSC_HANDLE)pCookedPage, ulCurTime);
            pCookedPage->IncRefCount ((ANSC_HANDLE)pCookedPage);

            AnscReleaseLock(&pMyObject->CpoTableLock);

            return  (ANSC_HANDLE)pCookedPage;
        }
    }

    AnscReleaseLock(&pMyObject->CpoTableLock);

    return  (ANSC_HANDLE)NULL;
}