source: trunk/main/xc_shm.c @ 982

Last change on this file since 982 was 982, checked in by moo, 21 months ago

move files to subdirs

  • Property svn:eol-style set to native
File size: 2.0 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
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15#include "xc_shm.h"
16
17struct _xc_shm_scheme_t {
18    const char              *name;
19    const xc_shm_handlers_t *handlers;
20};
21static xc_shm_scheme_t xc_shm_schemes[10];
22
23void xc_shm_init_modules() /* {{{ */
24{
25    extern void xc_shm_mem_init();
26#ifdef HAVE_XCACHE_TEST
27    extern void xc_shm_malloc_register();
28#endif
29    extern void xc_shm_mmap_register();
30
31    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
32    xc_shm_mem_init();
33#ifdef HAVE_XCACHE_TEST
34    xc_shm_malloc_register();
35#endif
36    xc_shm_mmap_register();
37}
38/* }}} */
39int 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/* }}} */
52const 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/* }}} */
63xc_shm_scheme_t *xc_shm_scheme_first() /* {{{ */
64{
65    return xc_shm_schemes;
66}
67/* }}} */
68xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme) /* {{{ */
69{
70    scheme ++;
71    return scheme->name ? scheme : NULL;
72}
73/* }}} */
74const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
75{
76    assert(scheme);
77    return scheme->name;
78}
79/* }}} */
80xc_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/* }}} */
95void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
96{
97    shm->handlers->destroy(shm);
98}
99/* }}} */
Note: See TracBrowser for help on using the repository browser.