source: trunk/xc_shm.c @ 153

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

win32/vc build fix

  • 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    extern void xc_shm_mem_init();
22    extern void xc_shm_malloc_register();
23    extern void xc_shm_mmap_register();
[153]24
25    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
26    xc_shm_mem_init();
27    xc_shm_malloc_register();
[148]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_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
56{
57    const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
58
59    if (handlers) {
60        xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
61        if (shm) {
62            shm->handlers = handlers;
63        }
64        return shm;
65    }
66
67    return NULL;
68}
69/* }}} */
70void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
71{
72    shm->handlers->destroy(shm);
73}
74/* }}} */
Note: See TracBrowser for help on using the repository browser.