Exemplo n.º 1
0
/*
 * Push cache item into cache manager,
 * this function return a cache item,
 * may be return value not equals push item,
 * so we must use return value.
 */
cache_item_t *beast_cache_push(cache_item_t *item)
{
    int hashval = beast_cache_hash(&item->key);
    int index = hashval % BUCKETS_DEFAULT_SIZE;
    cache_item_t **this;
    
    beast_locker_lock(beast_cache_locker);
    
    this = &beast_cache_buckets[index];
    while (*this) {
        /* this item was exists */
        if (!memcmp(&(*this)->key, &item->key, sizeof(cache_key_t))) {
            beast_mm_free(item);
            item = *this;
            break;
        }
        this = &(*this)->next;
    }
    
    *this = item;
    
    beast_locker_unlock(beast_cache_locker);
    
    return item;
}
Exemplo n.º 2
0
/*
 * Push cache item into cache manager,
 * this function return a cache item,
 * may be return value not equals push item,
 * so we must use return value.
 */
cache_item_t *beast_cache_push(cache_item_t *item)
{
    int hashval = beast_cache_hash(&item->key);
    int index = hashval % BUCKETS_DEFAULT_SIZE;
    cache_item_t **this, *self;
    int pid = (int)getpid();
    
    beast_spinlock(cache_lock, pid);

#if 0
    this = &beast_cache_buckets[index];
    while (*this) {
        self = *this;
        /* the same files */
        if (self->key.device == item->key.device &&
             self->key.inode == item->key.inode)
        {
            if (self->key.mtime >= item->key.mtime) {
                beast_mm_free(item);
                beast_spinunlock(cache_lock, pid);
                return self;
            } else { /* do replace */
                item->next = self->next;
                beast_mm_free(self);
                *this = item;
                beast_spinunlock(cache_lock, pid);
                return item;
            }
        }
        this = &self->next;
    }

    *this = item;
#endif

    item->next = beast_cache_buckets[index];
    beast_cache_buckets[index] = item;

    beast_spinunlock(cache_lock, pid);
    
    return item;
}
Exemplo n.º 3
0
cache_item_t *beast_cache_find(cache_key_t *key)
{
    int hashval = beast_cache_hash(key);
    int index = hashval % BUCKETS_DEFAULT_SIZE;
    cache_item_t *item, *temp;
    int pid = (int)getpid();

    beast_spinlock(cache_lock, pid);

    item = beast_cache_buckets[index];
    while (item) {
        if (item->key.device == key->device &&
              item->key.inode == key->inode)
        {
            break;
        }
        item = item->next;
    }

    if (item && item->key.mtime < key->mtime) /* cache exprie */
    {
        temp = beast_cache_buckets[index];
        if (temp == item) { /* the header node */
            beast_cache_buckets[index] = item->next;
        } else {
            while (temp->next != item) /* find prev node */
                temp = temp->next;
            temp->next = item->next;
        }

        beast_mm_free(item);
        item = NULL;
    }

    beast_spinunlock(cache_lock, pid);

    return item;
}