source: branches/1.2/xc_shm.c @ 466

Last change on this file since 466 was 466, checked in by moo, 7 years ago

support shm-malloc only on --enable-xcache-test

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
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>
11#include "xc_shm.h"
12
13struct _xc_shm_scheme_t {
14    const char              *name;
15    const xc_shm_handlers_t *handlers;
16};
17static xc_shm_scheme_t xc_shm_schemes[10];
18
19void xc_shm_init_modules() /* {{{ */
20{
21    extern void xc_shm_mem_init();
22#ifdef HAVE_XCACHE_TEST
23    extern void xc_shm_malloc_register();
24#endif
25    extern void xc_shm_mmap_register();
26
27    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
28    xc_shm_mem_init();
29#ifdef HAVE_XCACHE_TEST
30    xc_shm_malloc_register();
31#endif
32    xc_shm_mmap_register();
33}
34/* }}} */
35int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
36{
37    int i;
38    for (i = 0; i < 10; i ++) {
39        if (!xc_shm_schemes[i].name) {
40            xc_shm_schemes[i].name = name;
41            xc_shm_schemes[i].handlers = handlers;
42            return 1;
43        }
44    }
45    return 0;
46}
47/* }}} */
48const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
49{
50    int i;
51    for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
52        if (strcmp(xc_shm_schemes[i].name, name) == 0) {
53            return xc_shm_schemes[i].handlers;
54        }
55    }
56    return NULL;
57}
58/* }}} */
59xc_shm_scheme_t *xc_shm_scheme_first() /* {{{ */
60{
61    return xc_shm_schemes;
62}
63/* }}} */
64xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme) /* {{{ */
65{
66    scheme ++;
67    return scheme->name ? scheme : NULL;
68}
69/* }}} */
70const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
71{
72    assert(scheme);
73    return scheme->name;
74}
75/* }}} */
76xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
77{
78    const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
79
80    if (handlers) {
81        xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
82        if (shm) {
83            shm->handlers = handlers;
84        }
85        return shm;
86    }
87
88    return NULL;
89}
90/* }}} */
91void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
92{
93    shm->handlers->destroy(shm);
94}
95/* }}} */
Note: See TracBrowser for help on using the repository browser.