source: trunk/xc_shm.c @ 163

Last change on this file since 163 was 163, checked in by moo, 8 years ago

show available shm scheme in moduleinfo

  • 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    extern void xc_shm_malloc_register();
23    extern void xc_shm_mmap_register();
24
25    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
26    xc_shm_mem_init();
27    xc_shm_malloc_register();
28    xc_shm_mmap_register();
29}
30/* }}} */
31int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
32{
33    int i;
34    for (i = 0; i < 10; i ++) {
35        if (!xc_shm_schemes[i].name) {
36            xc_shm_schemes[i].name = name;
37            xc_shm_schemes[i].handlers = handlers;
38            return 1;
39        }
40    }
41    return 0;
42}
43/* }}} */
44const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
45{
46    int i;
47    for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
48        if (strcmp(xc_shm_schemes[i].name, name) == 0) {
49            return xc_shm_schemes[i].handlers;
50        }
51    }
52    return NULL;
53}
54/* }}} */
55xc_shm_scheme_t *xc_shm_scheme_first() /* {{{ */
56{
57    return xc_shm_schemes;
58}
59/* }}} */
60xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme) /* {{{ */
61{
62    scheme ++;
63    return scheme->name ? scheme : NULL;
64}
65/* }}} */
66const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
67{
68    assert(scheme);
69    return scheme->name;
70}
71/* }}} */
72xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
73{
74    const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
75
76    if (handlers) {
77        xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
78        if (shm) {
79            shm->handlers = handlers;
80        }
81        return shm;
82    }
83
84    return NULL;
85}
86/* }}} */
87void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
88{
89    shm->handlers->destroy(shm);
90}
91/* }}} */
Note: See TracBrowser for help on using the repository browser.