Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
nsDiskCacheBindery Class Reference

#include <nsDiskCacheBinding.h>

Collaboration diagram for nsDiskCacheBindery:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsDiskCacheBindery ()
 ~nsDiskCacheBindery ()
nsresult Init ()
void Reset ()
nsDiskCacheBindingCreateBinding (nsCacheEntry *entry, nsDiskCacheRecord *record)
nsDiskCacheBindingFindActiveBinding (PRUint32 hashNumber)
 FindActiveEntry : to find active colliding entry so we can doom it.
void RemoveBinding (nsDiskCacheBinding *binding)
 RemoveBinding : remove binding from collision detection on deactivation.
PRBool ActiveBindings ()
 ActiveBindings : return PR_TRUE if any bindings have open descriptors.

Private Member Functions

nsresult AddBinding (nsDiskCacheBinding *binding)
 AddBinding.

Private Attributes

PLDHashTable table
PRBool initialized

Static Private Attributes

static PLDHashTableOps ops

Detailed Description

Definition at line 120 of file nsDiskCacheBinding.h.


Constructor & Destructor Documentation

Definition at line 180 of file nsDiskCacheBinding.cpp.

Definition at line 186 of file nsDiskCacheBinding.cpp.

{
    Reset();
}

Here is the call graph for this function:


Member Function Documentation

ActiveBindings : return PR_TRUE if any bindings have open descriptors.

Definition at line 402 of file nsDiskCacheBinding.cpp.

{
    NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
    if (!initialized) return PR_FALSE;

    PRBool  activeBinding = PR_FALSE;
    PL_DHashTableEnumerate(&table, ActiveBinding, &activeBinding);

    return activeBinding;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AddBinding.

Called from FindEntry() if we read an entry off of disk

  • it may already have a generation number
  • a generation number conflict is an error

Called from BindEntry()

  • a generation number needs to be assigned

Definition at line 275 of file nsDiskCacheBinding.cpp.

{
    NS_ENSURE_ARG_POINTER(binding);
    NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");

    // find hash entry for key
    HashTableEntry * hashEntry;
    hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table,
                                                        (void*) binding->mRecord.HashNumber(),
                                                        PL_DHASH_ADD);
    if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY;
    
    if (hashEntry->mBinding == nsnull) {
        hashEntry->mBinding = binding;
        if (binding->mGeneration == 0)
            binding->mGeneration = 1;   // if generation uninitialized, set it to 1
            
        return NS_OK;
    }
    
    
    // insert binding in generation order
    nsDiskCacheBinding * p  = hashEntry->mBinding;
    PRBool   calcGeneration = (binding->mGeneration == 0);  // do we need to calculate generation?
    if (calcGeneration)  binding->mGeneration = 1;          // initialize to 1 if uninitialized
    while (1) {
    
        if (binding->mGeneration < p->mGeneration) {
            // here we are
            PR_INSERT_BEFORE(binding, p);
            if (hashEntry->mBinding == p)
                hashEntry->mBinding = binding;
            break;
        }
        
        if (binding->mGeneration == p->mGeneration) {
            if (calcGeneration)  ++binding->mGeneration;    // try the next generation
            else {
                NS_ERROR("### disk cache: generations collide!");
                return NS_ERROR_UNEXPECTED;
            }
        }

        p = (nsDiskCacheBinding *)PR_NEXT_LINK(p);
        if (p == hashEntry->mBinding) {
            // end of line: insert here or die
            p = (nsDiskCacheBinding *)PR_PREV_LINK(p);  // back up and check generation
            if (p->mGeneration == 255) {
                NS_WARNING("### disk cache: generation capacity at full");
                return NS_ERROR_UNEXPECTED;
            }
            PR_INSERT_BEFORE(binding, hashEntry->mBinding);
            break;
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 214 of file nsDiskCacheBinding.cpp.

{
    NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
    nsCOMPtr<nsISupports> data = entry->Data();
    if (data) {
        NS_ERROR("cache entry already has bind data");
        return nsnull;
    }
    
    nsDiskCacheBinding * binding = new nsDiskCacheBinding(entry, record);
    if (!binding)  return nsnull;
        
    // give ownership of the binding to the entry
    entry->SetData(binding);
    
    // add binding to collision detection system
    nsresult rv = AddBinding(binding);
    if (NS_FAILED(rv)) {
        entry->SetData(nsnull);
        return nsnull;
    }

    return binding;
}

Here is the call graph for this function:

Here is the caller graph for this function:

FindActiveEntry : to find active colliding entry so we can doom it.

Definition at line 245 of file nsDiskCacheBinding.cpp.

{
    NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
    // find hash entry for key
    HashTableEntry * hashEntry;
    hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table, (void*) hashNumber, PL_DHASH_LOOKUP);
    if (PL_DHASH_ENTRY_IS_FREE(hashEntry)) return nsnull;
    
    // walk list looking for active entry
    NS_ASSERTION(hashEntry->mBinding, "hash entry left with no binding");
    nsDiskCacheBinding * binding = hashEntry->mBinding;    
    while (binding->mCacheEntry->IsDoomed()) {
        binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
        if (binding == hashEntry->mBinding)  return nsnull;
    }
    return binding;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 193 of file nsDiskCacheBinding.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

RemoveBinding : remove binding from collision detection on deactivation.

Definition at line 338 of file nsDiskCacheBinding.cpp.

{
    NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
    if (!initialized)   return;
    
    HashTableEntry * hashEntry;
    void *           key = (void *)binding->mRecord.HashNumber();

    hashEntry = (HashTableEntry*) PL_DHashTableOperate(&table,
                                                       (void*) key,
                                                       PL_DHASH_LOOKUP);
    if (!PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
        NS_WARNING("### disk cache: binding not in hashtable!");
        return;
    }
    
    if (binding == hashEntry->mBinding) {
        if (PR_CLIST_IS_EMPTY(binding)) {
            // remove this hash entry
            (void) PL_DHashTableOperate(&table,
                                        (void*) binding->mRecord.HashNumber(),
                                        PL_DHASH_REMOVE);
            return;
            
        } else {
            // promote next binding to head, and unlink this binding
            hashEntry->mBinding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
        }
    }
    PR_REMOVE_AND_INIT_LINK(binding);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 204 of file nsDiskCacheBinding.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 141 of file nsDiskCacheBinding.h.

Definition at line 140 of file nsDiskCacheBinding.h.


The documentation for this class was generated from the following files: