summaryrefslogtreecommitdiff
path: root/xcache/xc_shm.c
diff options
context:
space:
mode:
Diffstat (limited to 'xcache/xc_shm.c')
-rw-r--r--xcache/xc_shm.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/xcache/xc_shm.c b/xcache/xc_shm.c
index 190e80e..2bd05ff 100644
--- a/xcache/xc_shm.c
+++ b/xcache/xc_shm.c
@@ -14,8 +14,8 @@
#include <string.h>
struct _xc_shm_scheme_t {
- const char *name;
- const xc_shm_handlers_t *handlers;
+ const char *name;
+ const xc_shm_vtable_t *vtable;
};
static xc_shm_scheme_t xc_shm_schemes[10];
@@ -35,25 +35,25 @@ void xc_shm_init_modules() /* {{{ */
xc_shm_mmap_register();
}
/* }}} */
-int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
+int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable) /* {{{ */
{
int i;
for (i = 0; i < 10; i ++) {
if (!xc_shm_schemes[i].name) {
xc_shm_schemes[i].name = name;
- xc_shm_schemes[i].handlers = handlers;
+ xc_shm_schemes[i].vtable = vtable;
return 1;
}
}
return 0;
}
/* }}} */
-const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
+const xc_shm_vtable_t *xc_shm_scheme_find(const char *name) /* {{{ */
{
int i;
for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
if (strcmp(xc_shm_schemes[i].name, name) == 0) {
- return xc_shm_schemes[i].handlers;
+ return xc_shm_schemes[i].vtable;
}
}
return NULL;
@@ -78,12 +78,12 @@ const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
/* }}} */
xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
{
- const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
+ const xc_shm_vtable_t *vtable = xc_shm_scheme_find(type);
- if (handlers) {
- xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
+ if (vtable) {
+ xc_shm_t *shm = vtable->init(size, readonly_protection, arg1, arg2);
if (shm) {
- shm->handlers = handlers;
+ shm->vtable = vtable;
}
return shm;
}
@@ -93,6 +93,36 @@ xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protecti
/* }}} */
void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
{
- shm->handlers->destroy(shm);
+ shm->vtable->destroy(shm);
+}
+/* }}} */
+
+int xc_shm_can_readonly(const xc_shm_t *shm) /* {{{ */
+{
+ return ((xc_shm_base_t *)shm)->readonlydiff != 0;
+}
+/* }}} */
+void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p) /* {{{ */
+{
+ const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
+
+ if (shm->readonlydiff) {
+ assert(shm->vtable->is_readonly(shm_, p));
+ p = ((char *) p) - shm->readonlydiff;
+ }
+ assert(shm->vtable->is_readwrite(shm_, p));
+ return p;
+}
+/* }}} */
+void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p) /* {{{ */
+{
+ const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
+
+ assert(shm->vtable->is_readwrite(shm_, p));
+ if (shm->readonlydiff) {
+ p = ((char *) p) + shm->readonlydiff;
+ assert(shm->vtable->is_readonly(shm_, p));
+ }
+ return p;
}
/* }}} */