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


Ignore:
Timestamp:
2013-11-12T09:46:04Z (22 months ago)
Author:
Xuefer
Message:

clean up shm handlers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache/xc_shm.h

    r1135 r1468  
    33
    44#include <stdlib.h>
     5#include <stddef.h>
     6#include <assert.h>
    57
    6 typedef struct _xc_shm_handlers_t xc_shm_handlers_t;
    7 
    8 #ifndef XC_SHM_IMPL
    9 struct _xc_shm_t {
    10     const xc_shm_handlers_t *handlers;
    11 };
    12 #define XC_SHM_IMPL _xc_shm_t
     8#ifndef XC_SHM_T_DEFINED
     9typedef struct _xc_shm_base_t xc_shm_t;
     10#define XC_SHM_T_DEFINED
    1311#endif
    1412
    15 typedef struct XC_SHM_IMPL xc_shm_t;
     13typedef struct _xc_shm_vtable_t xc_shm_vtable_t;
     14
     15typedef struct _xc_shm_base_t {
     16    const xc_shm_vtable_t *vtable;
     17    ptrdiff_t readonlydiff;
     18} xc_shm_base_t;
     19
    1620typedef size_t xc_shmsize_t;
    1721
    1822/* shm */
    19 #define XC_SHM_CAN_READONLY(func) int   func(xc_shm_t *shm)
    20 #define XC_SHM_IS_READWRITE(func) int   func(xc_shm_t *shm, const void *p)
    21 #define XC_SHM_IS_READONLY(func)  int   func(xc_shm_t *shm, const void *p)
    22 #define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p)
    23 #define XC_SHM_TO_READONLY(func)  void *func(xc_shm_t *shm, void *p)
     23#define XC_SHM_IS_READWRITE(func) int   func(const xc_shm_t *shm, const void *p)
     24#define XC_SHM_IS_READONLY(func)  int   func(const xc_shm_t *shm, const void *p)
    2425
    2526#define XC_SHM_INIT(func)         xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2)
     
    2930#define XC_SHM_MEMDESTROY(func)   void func(void *mem)
    3031
    31 #define XC_SHM_HANDLERS(name)    { \
    32     xc_##name##_can_readonly       \
     32#define XC_SHM_VTABLE(name)      { \
     33      xc_##name##_init             \
     34    , xc_##name##_destroy          \
    3335    , xc_##name##_is_readwrite     \
    3436    , xc_##name##_is_readonly      \
    35     , xc_##name##_to_readwrite     \
    36     , xc_##name##_to_readonly      \
    3737\
    38     , xc_##name##_init             \
    39     , xc_##name##_destroy          \
    4038\
    4139    , xc_##name##_meminit          \
     
    4341}
    4442
    45 struct _xc_shm_handlers_t {
    46     XC_SHM_CAN_READONLY((*can_readonly));
     43struct _xc_shm_vtable_t {
     44    XC_SHM_INIT((*init));
     45    XC_SHM_DESTROY((*destroy));
    4746    XC_SHM_IS_READWRITE((*is_readwrite));
    4847    XC_SHM_IS_READONLY((*is_readonly));
    49     XC_SHM_TO_READWRITE((*to_readwrite));
    50     XC_SHM_TO_READONLY((*to_readonly));
    51     XC_SHM_INIT((*init));
    52     XC_SHM_DESTROY((*destroy));
    5348
    5449    XC_SHM_MEMINIT((*meminit));
     
    5954
    6055void xc_shm_init_modules();
    61 int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers);
    62 const xc_shm_handlers_t *xc_shm_scheme_find(const char *name);
     56int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable);
     57const xc_shm_vtable_t *xc_shm_scheme_find(const char *name);
    6358xc_shm_scheme_t *xc_shm_scheme_first();
    6459xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme);
     
    6762xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
    6863void xc_shm_destroy(xc_shm_t *shm);
     64
     65int xc_shm_can_readonly(const xc_shm_t *shm);
     66void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p);
     67void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p);
     68
    6969#endif
Note: See TracChangeset for help on using the changeset viewer.