| [148] | 1 | #ifdef TEST |
|---|
| 2 | #include <limits.h> |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #else |
|---|
| 5 | #include <php.h> |
|---|
| 6 | #endif |
|---|
| 7 | |
|---|
| 8 | #include <assert.h> |
|---|
| 9 | #include <stdlib.h> |
|---|
| 10 | #include <string.h> |
|---|
| [478] | 11 | |
|---|
| 12 | #ifdef HAVE_CONFIG_H |
|---|
| 13 | #include <config.h> |
|---|
| 14 | #endif |
|---|
| [148] | 15 | #include "xc_shm.h" |
|---|
| 16 | |
|---|
| [163] | 17 | struct _xc_shm_scheme_t { |
|---|
| [148] | 18 | const char *name; |
|---|
| 19 | const xc_shm_handlers_t *handlers; |
|---|
| [163] | 20 | }; |
|---|
| [148] | 21 | static xc_shm_scheme_t xc_shm_schemes[10]; |
|---|
| 22 | |
|---|
| 23 | void xc_shm_init_modules() /* {{{ */ |
|---|
| 24 | { |
|---|
| 25 | extern void xc_shm_mem_init(); |
|---|
| [470] | 26 | #ifdef HAVE_XCACHE_TEST |
|---|
| [148] | 27 | extern void xc_shm_malloc_register(); |
|---|
| [470] | 28 | #endif |
|---|
| [148] | 29 | extern void xc_shm_mmap_register(); |
|---|
| [153] | 30 | |
|---|
| 31 | memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes)); |
|---|
| 32 | xc_shm_mem_init(); |
|---|
| [470] | 33 | #ifdef HAVE_XCACHE_TEST |
|---|
| [153] | 34 | xc_shm_malloc_register(); |
|---|
| [470] | 35 | #endif |
|---|
| [148] | 36 | xc_shm_mmap_register(); |
|---|
| 37 | } |
|---|
| 38 | /* }}} */ |
|---|
| 39 | int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */ |
|---|
| 40 | { |
|---|
| 41 | int i; |
|---|
| 42 | for (i = 0; i < 10; i ++) { |
|---|
| 43 | if (!xc_shm_schemes[i].name) { |
|---|
| 44 | xc_shm_schemes[i].name = name; |
|---|
| 45 | xc_shm_schemes[i].handlers = handlers; |
|---|
| 46 | return 1; |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | return 0; |
|---|
| 50 | } |
|---|
| 51 | /* }}} */ |
|---|
| 52 | const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */ |
|---|
| 53 | { |
|---|
| 54 | int i; |
|---|
| 55 | for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) { |
|---|
| 56 | if (strcmp(xc_shm_schemes[i].name, name) == 0) { |
|---|
| 57 | return xc_shm_schemes[i].handlers; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | return NULL; |
|---|
| 61 | } |
|---|
| 62 | /* }}} */ |
|---|
| [163] | 63 | xc_shm_scheme_t *xc_shm_scheme_first() /* {{{ */ |
|---|
| 64 | { |
|---|
| 65 | return xc_shm_schemes; |
|---|
| 66 | } |
|---|
| 67 | /* }}} */ |
|---|
| 68 | xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme) /* {{{ */ |
|---|
| 69 | { |
|---|
| 70 | scheme ++; |
|---|
| 71 | return scheme->name ? scheme : NULL; |
|---|
| 72 | } |
|---|
| 73 | /* }}} */ |
|---|
| 74 | const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */ |
|---|
| 75 | { |
|---|
| 76 | assert(scheme); |
|---|
| 77 | return scheme->name; |
|---|
| 78 | } |
|---|
| 79 | /* }}} */ |
|---|
| [148] | 80 | xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */ |
|---|
| 81 | { |
|---|
| 82 | const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type); |
|---|
| 83 | |
|---|
| 84 | if (handlers) { |
|---|
| 85 | xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2); |
|---|
| 86 | if (shm) { |
|---|
| 87 | shm->handlers = handlers; |
|---|
| 88 | } |
|---|
| 89 | return shm; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | return NULL; |
|---|
| 93 | } |
|---|
| 94 | /* }}} */ |
|---|
| 95 | void xc_shm_destroy(xc_shm_t *shm) /* {{{ */ |
|---|
| 96 | { |
|---|
| 97 | shm->handlers->destroy(shm); |
|---|
| 98 | } |
|---|
| 99 | /* }}} */ |
|---|