source: trunk/xcache/xc_shm.h @ 1468

Last change on this file since 1468 was 1468, checked in by moo, 5 months ago

clean up shm handlers

  • Property svn:eol-style set to native
File size: 2.0 KB
RevLine 
[305]1#ifndef XC_SHM_H
2#define XC_SHM_H
[1135]3
4#include <stdlib.h>
[1468]5#include <stddef.h>
6#include <assert.h>
[1135]7
[1468]8#ifndef XC_SHM_T_DEFINED
9typedef struct _xc_shm_base_t xc_shm_t;
10#define XC_SHM_T_DEFINED
[381]11#endif
12
[1468]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
[11]20typedef size_t xc_shmsize_t;
[1]21
[148]22/* shm */
[1468]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)
[1]25
[148]26#define XC_SHM_INIT(func)         xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2)
27#define XC_SHM_DESTROY(func)      void func(xc_shm_t *shm)
28
[1135]29#define XC_SHM_MEMINIT(func)      void *func(xc_shm_t *shm, xc_shmsize_t size)
30#define XC_SHM_MEMDESTROY(func)   void func(void *mem)
[148]31
[1468]32#define XC_SHM_VTABLE(name)      { \
33      xc_##name##_init             \
34    , xc_##name##_destroy          \
[148]35    , xc_##name##_is_readwrite     \
36    , xc_##name##_is_readonly      \
37\
38\
39    , xc_##name##_meminit          \
40    , xc_##name##_memdestroy       \
41}
42
[1468]43struct _xc_shm_vtable_t {
44    XC_SHM_INIT((*init));
45    XC_SHM_DESTROY((*destroy));
[148]46    XC_SHM_IS_READWRITE((*is_readwrite));
47    XC_SHM_IS_READONLY((*is_readonly));
48
49    XC_SHM_MEMINIT((*meminit));
50    XC_SHM_MEMDESTROY((*memdestroy));
[381]51};
[148]52
[163]53typedef struct _xc_shm_scheme_t xc_shm_scheme_t;
[148]54
55void xc_shm_init_modules();
[1468]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);
[163]58xc_shm_scheme_t *xc_shm_scheme_first();
59xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme);
60const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme);
[148]61
62xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
[1]63void xc_shm_destroy(xc_shm_t *shm);
[1468]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
[305]69#endif
Note: See TracBrowser for help on using the repository browser.