Changeset 1468 in svn for trunk/xcache/xc_shm.c


Ignore:
Timestamp:
2013-11-12T10:46:04+01:00 (21 months ago)
Author:
Xuefer
Message:

clean up shm handlers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache/xc_shm.c

    r1378 r1468  
    1515
    1616struct _xc_shm_scheme_t {
    17     const char              *name;
    18     const xc_shm_handlers_t *handlers;
     17    const char            *name;
     18    const xc_shm_vtable_t *vtable;
    1919};
    2020static xc_shm_scheme_t xc_shm_schemes[10];
     
    3636}
    3737/* }}} */
    38 int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
     38int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable) /* {{{ */
    3939{
    4040    int i;
     
    4242        if (!xc_shm_schemes[i].name) {
    4343            xc_shm_schemes[i].name = name;
    44             xc_shm_schemes[i].handlers = handlers;
     44            xc_shm_schemes[i].vtable = vtable;
    4545            return 1;
    4646        }
     
    4949}
    5050/* }}} */
    51 const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
     51const xc_shm_vtable_t *xc_shm_scheme_find(const char *name) /* {{{ */
    5252{
    5353    int i;
    5454    for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
    5555        if (strcmp(xc_shm_schemes[i].name, name) == 0) {
    56             return xc_shm_schemes[i].handlers;
     56            return xc_shm_schemes[i].vtable;
    5757        }
    5858    }
     
    7979xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
    8080{
    81     const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
     81    const xc_shm_vtable_t *vtable = xc_shm_scheme_find(type);
    8282
    83     if (handlers) {
    84         xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
     83    if (vtable) {
     84        xc_shm_t *shm = vtable->init(size, readonly_protection, arg1, arg2);
    8585        if (shm) {
    86             shm->handlers = handlers;
     86            shm->vtable = vtable;
    8787        }
    8888        return shm;
     
    9494void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
    9595{
    96     shm->handlers->destroy(shm);
     96    shm->vtable->destroy(shm);
    9797}
    9898/* }}} */
     99
     100int xc_shm_can_readonly(const xc_shm_t *shm) /* {{{ */
     101{
     102    return ((xc_shm_base_t *)shm)->readonlydiff != 0;
     103}
     104/* }}} */
     105void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p) /* {{{ */
     106{
     107    const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
     108
     109    if (shm->readonlydiff) {
     110        assert(shm->vtable->is_readonly(shm_, p));
     111        p = ((char *) p) - shm->readonlydiff;
     112    }
     113    assert(shm->vtable->is_readwrite(shm_, p));
     114    return p;
     115}
     116/* }}} */
     117void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p) /* {{{ */
     118{
     119    const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
     120
     121    assert(shm->vtable->is_readwrite(shm_, p));
     122    if (shm->readonlydiff) {
     123        p = ((char *) p) + shm->readonlydiff;
     124        assert(shm->vtable->is_readonly(shm_, p));
     125    }
     126    return p;
     127}
     128/* }}} */
Note: See TracChangeset for help on using the changeset viewer.