source: trunk/xcache/xc_shm.h

Last change on this file 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
Line 
1#ifndef XC_SHM_H
2#define XC_SHM_H
3
4#include <stdlib.h>
5#include <stddef.h>
6#include <assert.h>
7
8#ifndef XC_SHM_T_DEFINED
9typedef struct _xc_shm_base_t xc_shm_t;
10#define XC_SHM_T_DEFINED
11#endif
12
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
20typedef size_t xc_shmsize_t;
21
22/* shm */
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)
25
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
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)
31
32#define XC_SHM_VTABLE(name)      { \
33      xc_##name##_init             \
34    , xc_##name##_destroy          \
35    , xc_##name##_is_readwrite     \
36    , xc_##name##_is_readonly      \
37\
38\
39    , xc_##name##_meminit          \
40    , xc_##name##_memdestroy       \
41}
42
43struct _xc_shm_vtable_t {
44    XC_SHM_INIT((*init));
45    XC_SHM_DESTROY((*destroy));
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));
51};
52
53typedef struct _xc_shm_scheme_t xc_shm_scheme_t;
54
55void xc_shm_init_modules();
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);
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);
61
62xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
63void 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
69#endif
Note: See TracBrowser for help on using the repository browser.