source: trunk/xc_shm.c @ 148

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

reconstruct shm/allocator

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