source: trunk/xcache/xc_shm.c @ 1378

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

use config.h correctly wherever needed

  • Property svn:eol-style set to native
File size: 2.0 KB
RevLine 
[148]1#ifdef TEST
[1378]2#   ifdef HAVE_CONFIG_H
3#       include <config.h>
4#   endif
5#   include <limits.h>
6#   include <stdio.h>
[148]7#else
[1378]8#   include "xcache.h"
[148]9#endif
[1378]10#include "xc_shm.h"
[148]11
12#include <assert.h>
13#include <stdlib.h>
14#include <string.h>
[478]15
[163]16struct _xc_shm_scheme_t {
[148]17    const char              *name;
18    const xc_shm_handlers_t *handlers;
[163]19};
[148]20static xc_shm_scheme_t xc_shm_schemes[10];
21
22void xc_shm_init_modules() /* {{{ */
23{
[1135]24    extern void xc_allocator_init();
[470]25#ifdef HAVE_XCACHE_TEST
[148]26    extern void xc_shm_malloc_register();
[470]27#endif
[148]28    extern void xc_shm_mmap_register();
[153]29
30    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
[1135]31    xc_allocator_init();
[470]32#ifdef HAVE_XCACHE_TEST
[153]33    xc_shm_malloc_register();
[470]34#endif
[148]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/* }}} */
[163]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/* }}} */
[148]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.