A vm_cache can no longer be created with a NULL vm_store (nobody did it before,

but it would have worked - and crashed soon after).
Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15642 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-12-21 17:05:50 +00:00
parent ea2cd27e57
commit 1e12fe8e5d

View File

@ -31,7 +31,7 @@
/* hash table of pages keyed by cache they're in and offset */ /* hash table of pages keyed by cache they're in and offset */
#define PAGE_TABLE_SIZE 1024 /* make this dynamic */ #define PAGE_TABLE_SIZE 1024 /* TODO: make this dynamic */
static void *page_cache_table; static void *page_cache_table;
static spinlock page_cache_table_lock; static spinlock page_cache_table_lock;
@ -92,6 +92,11 @@ vm_cache_create(vm_store *store)
{ {
vm_cache *cache; vm_cache *cache;
if (store == NULL) {
panic("vm_cache created with NULL store!");
return NULL;
}
cache = malloc(sizeof(vm_cache)); cache = malloc(sizeof(vm_cache));
if (cache == NULL) if (cache == NULL)
return NULL; return NULL;
@ -99,13 +104,14 @@ vm_cache_create(vm_store *store)
cache->page_list = NULL; cache->page_list = NULL;
cache->ref = NULL; cache->ref = NULL;
cache->source = NULL; cache->source = NULL;
cache->store = store;
if (store != NULL)
store->cache = cache;
cache->virtual_size = 0; cache->virtual_size = 0;
cache->temporary = 0; cache->temporary = 0;
cache->scan_skip = 0; cache->scan_skip = 0;
// connect the store to its cache
cache->store = store;
store->cache = cache;
return cache; return cache;
} }
@ -119,10 +125,16 @@ vm_cache_ref_create(vm_cache *cache)
if (ref == NULL) if (ref == NULL)
return NULL; return NULL;
ref->cache = cache; if (mutex_init(&ref->lock, "cache_ref_mutex") < B_OK) {
mutex_init(&ref->lock, "cache_ref_mutex"); free(ref);
return NULL;
}
ref->areas = NULL; ref->areas = NULL;
ref->ref_count = 1; ref->ref_count = 1;
// connect the cache to its ref
ref->cache = cache;
cache->ref = ref; cache->ref = ref;
return ref; return ref;
@ -167,9 +179,8 @@ vm_cache_release_ref(vm_cache_ref *cache_ref)
// delete this cache // delete this cache
// delete the cache's backing store, if it has one // delete the cache's backing store
if (cache_ref->cache->store) cache_ref->cache->store->ops->destroy(cache_ref->cache->store);
(*cache_ref->cache->store->ops->destroy)(cache_ref->cache->store);
// free all of the pages in the cache // free all of the pages in the cache
page = cache_ref->cache->page_list; page = cache_ref->cache->page_list;
@ -322,7 +333,7 @@ vm_cache_set_minimal_commitment(vm_cache_ref *ref, off_t commitment)
// enough for a commitment of that size? // enough for a commitment of that size?
// try to commit more memory // try to commit more memory
status = (store->ops->commit)(store, commitment); status = store->ops->commit(store, commitment);
} }
mutex_unlock(&ref->lock); mutex_unlock(&ref->lock);