~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to bdb/os/os_region.c

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * See the file LICENSE for redistribution information.
 
3
 *
 
4
 * Copyright (c) 1996-2002
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 */
 
7
 
 
8
#include "db_config.h"
 
9
 
 
10
#ifndef lint
 
11
static const char revid[] = "$Id: os_region.c,v 11.15 2002/07/12 18:56:51 bostic Exp $";
 
12
#endif /* not lint */
 
13
 
 
14
#ifndef NO_SYSTEM_INCLUDES
 
15
#include <sys/types.h>
 
16
 
 
17
#endif
 
18
 
 
19
#include "db_int.h"
 
20
 
 
21
/*
 
22
 * __os_r_attach --
 
23
 *      Attach to a shared memory region.
 
24
 *
 
25
 * PUBLIC: int __os_r_attach __P((DB_ENV *, REGINFO *, REGION *));
 
26
 */
 
27
int
 
28
__os_r_attach(dbenv, infop, rp)
 
29
        DB_ENV *dbenv;
 
30
        REGINFO *infop;
 
31
        REGION *rp;
 
32
{
 
33
        int ret;
 
34
        /* Round off the requested size for the underlying VM. */
 
35
        OS_VMROUNDOFF(rp->size);
 
36
 
 
37
#ifdef DB_REGIONSIZE_MAX
 
38
        /* Some architectures have hard limits on the maximum region size. */
 
39
        if (rp->size > DB_REGIONSIZE_MAX) {
 
40
                __db_err(dbenv, "region size %lu is too large; maximum is %lu",
 
41
                    (u_long)rp->size, (u_long)DB_REGIONSIZE_MAX);
 
42
                return (EINVAL);
 
43
        }
 
44
#endif
 
45
 
 
46
        /*
 
47
         * If a region is private, malloc the memory.
 
48
         *
 
49
         * !!!
 
50
         * If this fails because the region is too large to malloc, mmap(2)
 
51
         * using the MAP_ANON or MAP_ANONYMOUS flags would be an alternative.
 
52
         * I don't know of any architectures (yet!) where malloc is a problem.
 
53
         */
 
54
        if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
 
55
#if defined(MUTEX_NO_MALLOC_LOCKS)
 
56
                /*
 
57
                 * !!!
 
58
                 * There exist spinlocks that don't work in malloc memory, e.g.,
 
59
                 * the HP/UX msemaphore interface.  If we don't have locks that
 
60
                 * will work in malloc memory, we better not be private or not
 
61
                 * be threaded.
 
62
                 */
 
63
                if (F_ISSET(dbenv, DB_ENV_THREAD)) {
 
64
                        __db_err(dbenv, "%s",
 
65
    "architecture does not support locks inside process-local (malloc) memory");
 
66
                        __db_err(dbenv, "%s",
 
67
    "application may not specify both DB_PRIVATE and DB_THREAD");
 
68
                        return (EINVAL);
 
69
                }
 
70
#endif
 
71
                if ((ret =
 
72
                    __os_malloc(dbenv, rp->size, &infop->addr)) != 0)
 
73
                        return (ret);
 
74
#if defined(UMRW) && !defined(DIAGNOSTIC)
 
75
                memset(infop->addr, CLEAR_BYTE, rp->size);
 
76
#endif
 
77
                return (0);
 
78
        }
 
79
 
 
80
        /* If the user replaced the map call, call through their interface. */
 
81
        if (DB_GLOBAL(j_map) != NULL)
 
82
                return (DB_GLOBAL(j_map)(infop->name,
 
83
                    rp->size, 1, 0, &infop->addr));
 
84
 
 
85
        return (__os_r_sysattach(dbenv, infop, rp));
 
86
}
 
87
 
 
88
/*
 
89
 * __os_r_detach --
 
90
 *      Detach from a shared memory region.
 
91
 *
 
92
 * PUBLIC: int __os_r_detach __P((DB_ENV *, REGINFO *, int));
 
93
 */
 
94
int
 
95
__os_r_detach(dbenv, infop, destroy)
 
96
        DB_ENV *dbenv;
 
97
        REGINFO *infop;
 
98
        int destroy;
 
99
{
 
100
        REGION *rp;
 
101
 
 
102
        rp = infop->rp;
 
103
 
 
104
        /* If a region is private, free the memory. */
 
105
        if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
 
106
                __os_free(dbenv, infop->addr);
 
107
                return (0);
 
108
        }
 
109
 
 
110
        /* If the user replaced the map call, call through their interface. */
 
111
        if (DB_GLOBAL(j_unmap) != NULL)
 
112
                return (DB_GLOBAL(j_unmap)(infop->addr, rp->size));
 
113
 
 
114
        return (__os_r_sysdetach(dbenv, infop, destroy));
 
115
}