update entry points to backing store ready for allowing differing object lifetimes

This commit is contained in:
Vincent Sanders 2014-11-20 22:28:19 +00:00
parent 75623179aa
commit eb87406758
4 changed files with 92 additions and 15 deletions

View File

@ -27,13 +27,12 @@
/** storage control flags */
enum backing_store_flags {
BACKING_STORE_NONE = 0, /**< no special processing */
BACKING_STORE_META = 1, /**< data is metadata */
BACKING_STORE_MMAP = 2, /**< when data is retrived this indicates the
* returned buffer may be memory mapped,
* flag must be cleared if the storage is
* allocated and is not memory mapped.
*/
/** no special processing */
BACKING_STORE_NONE = 0,
/** data is metadata */
BACKING_STORE_META = 1,
/** backing store will handle allocation. */
BACKING_STORE_ALLOC = 2
};
/** low level cache backing store operation table
@ -61,10 +60,18 @@ struct gui_llcache_table {
/**
* Place an object in the backing store.
*
* @param url The url is used as the unique primary key for the data.
* @param flags The flags to control how the obejct is stored.
* @param data The objects data.
* @param datalen The length of the \a data.
* The object is placed in the persistent store and may be
* retrieved. If the BACKING_STORE_ALLOC flag is used the
* backing store will take a reference to the passed data,
* subsequently the caller should explicitly release the
* allocation using the release method and not free the data
* itself. An additional effect of this is that the persistent
* storage may not have been completely written on return.
*
* @param[in] url The url is used as the unique primary key for the data.
* @param[in] flags The flags to control how the obejct is stored.
* @param[in] data The objects data.
* @param[in] datalen The length of the \a data.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*store)(struct nsurl *url, enum backing_store_flags flags,
@ -73,10 +80,14 @@ struct gui_llcache_table {
/**
* Retrive an object from the backing store.
*
* @param url The url is used as the unique primary key for the data.
* @param flags The flags to control how the object is retrived.
* @param data The objects data.
* @param datalen The length of the \a data retrieved.
* If the BACKING_STORE_ALLOC flag is set the returned memory
* is managed by the backing store and should be freed by
* calling the release method.
*
* @param[in] url The url is used as the unique primary key for the data.
* @param[in] flags The flags to control how the object is retrived.
* @param[in,out] data The retrived objects data.
* @param[in,out] datalen The length of the \a data retrieved.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*fetch)(struct nsurl *url, enum backing_store_flags *flags,
@ -88,10 +99,26 @@ struct gui_llcache_table {
* The entry (if present in the backing store) must no longer
* be returned as a result to the fetch or meta operations.
*
* If the entry had data allocated it will be released.
*
* @param url The url is used as the unique primary key to invalidate.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*invalidate)(struct nsurl *url);
/**
* release a previously fetched or stored memory object.
*
* if the BACKING_STORE_ALLOC flag was used with the fetch or
* store operation for this url the returned storage is
* unreferenced. When the reference count drops to zero the
* storage is released.
*
* @param url The url is used as the unique primary key to invalidate.
* @param[in] flags The flags to control how the object data is released.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*release)(struct nsurl *url, enum backing_store_flags flags);
};
extern struct gui_llcache_table* null_llcache_table;

View File

@ -73,8 +73,19 @@
/** Filename of serialised entries */
#define ENTRIES_FNAME "entries"
/**
* flags that indicate what additional information is contained within
* an entry.
*/
enum store_entry_flags {
/** entry is not managing the allocation */
STORE_ENTRY_FLAG_NONE = 0,
/** entry allocation is on heap */
STORE_ENTRY_FLAG_HEAP = 1,
/** entry allocation is mmaped */
STORE_ENTRY_FLAG_MMAP = 2,
/** entry allocation is in small object pool */
STORE_ENTRY_FLAG_SMALL = 4,
};
/**
@ -1303,12 +1314,30 @@ invalidate(nsurl *url)
}
/**
* release a previously fetched or stored memory object.
*
* if the BACKING_STORE_ALLOC flag was used with the fetch or
* store operation for this url the returned storage is
* unreferenced. When the reference count drops to zero the
* storage is released.
*
* @param url The url is used as the unique primary key to invalidate.
* @param[in] flags The flags to control how the object data is released.
* @return NSERROR_OK on success or error code on faliure.
*/
static nserror release(nsurl *url, enum backing_store_flags flags)
{
return NSERROR_NOT_FOUND;
}
static struct gui_llcache_table llcache_table = {
.initialise = initialise,
.finalise = finalise,
.store = store,
.fetch = fetch,
.invalidate = invalidate,
.release = release,
};
struct gui_llcache_table *filesystem_llcache_table = &llcache_table;

View File

@ -57,12 +57,30 @@ static nserror invalidate(nsurl *url)
return NSERROR_NOT_FOUND;
}
/**
* release a previously fetched or stored memory object.
*
* if the BACKING_STORE_ALLOC flag was used with the fetch or
* store operation for this url the returned storage is
* unreferenced. When the reference count drops to zero the
* storage is released.
*
* @param url The url is used as the unique primary key to invalidate.
* @param[in] flags The flags to control how the object data is released.
* @return NSERROR_OK on success or error code on faliure.
*/
static nserror release(nsurl *url, enum backing_store_flags flags)
{
return NSERROR_NOT_FOUND;
}
static struct gui_llcache_table llcache_table = {
.initialise = initialise,
.finalise = finalise,
.store = store,
.fetch = fetch,
.invalidate = invalidate,
.release = release,
};
struct gui_llcache_table *null_llcache_table = &llcache_table;

View File

@ -477,6 +477,9 @@ static nserror verify_llcache_register(struct gui_llcache_table *glt)
if (glt->invalidate == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->release == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->initialise == NULL) {
return NSERROR_BAD_PARAMETER;
}