source: trunk/xcache/xc_shm.c @ 1378

Last change on this file since 1378 was 1378, checked in by moo, 11 months ago

use config.h correctly wherever needed

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