source: trunk/third/db/build_vms/db_int.h @ 17055

Revision 17055, 12.2 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17054, which included commits to RCS files with non-trunk default branches.
Line 
1/* DO NOT EDIT: automatically built by dist/distrib. */
2/*-
3 * See the file LICENSE for redistribution information.
4 *
5 * Copyright (c) 1996, 1997, 1998, 1999, 2000
6 *      Sleepycat Software.  All rights reserved.
7 *
8 *      $Id: db_int.h,v 1.1.1.2 2002-02-11 16:30:22 ghudson Exp $
9 */
10
11#ifndef _DB_INTERNAL_H_
12#define _DB_INTERNAL_H_
13
14/*******************************************************
15 * General includes.
16 *******************************************************/
17#include "db.h"
18
19#ifndef NO_SYSTEM_INCLUDES
20#if defined(__STDC__) || defined(__cplusplus)
21#include <stdarg.h>
22#else
23#include <varargs.h>
24#endif
25#endif
26
27/*
28 * XXX
29 * We need to #undef the following LIST_XXX macros because VxWorks copied
30 * some of them into UnixLib.h -- not all of them though, so we can't use
31 * their versions.
32 */
33#undef LIST_INIT
34#undef LIST_INSERT_HEAD
35#undef LIST_REMOVE
36#include "queue.h"
37#include "shqueue.h"
38
39#if defined(__cplusplus)
40extern "C" {
41#endif
42
43/*******************************************************
44 * General purpose constants and macros.
45 *******************************************************/
46#define UINT16_T_MAX        0xffff      /* Maximum 16 bit unsigned. */
47#define UINT32_T_MAX    0xffffffff      /* Maximum 32 bit unsigned. */
48
49#define MEGABYTE        1048576
50#define GIGABYTE        1073741824
51
52#define MS_PER_SEC      1000            /* Milliseconds in a second. */
53#define USEC_PER_MS     1000            /* Microseconds in a millisecond. */
54
55#define DB_MIN_PGSIZE   0x000200        /* Minimum page size (512). */
56#define DB_MAX_PGSIZE   0x010000        /* Maximum page size (65536). */
57
58#define RECNO_OOB       0               /* Illegal record number. */
59
60/*
61 * If we are unable to determine the underlying filesystem block size, use
62 * 8K on the grounds that most OS's use less than 8K for a VM page size.
63 */
64#define DB_DEF_IOSIZE   (8 * 1024)
65
66/*
67 * Aligning items to particular sizes or in pages or memory.
68 *
69 * db_align_t --
70 * Largest integral type, used to align structures in memory.  We don't store
71 * floating point types in structures, so integral types should be sufficient
72 * (and we don't have to worry about systems that store floats in other than
73 * power-of-2 numbers of bytes).  Additionally this fixes compiler that rewrite
74 * structure assignments and ANSI C memcpy calls to be in-line instructions
75 * that happen to require alignment.  Note: this alignment isn't sufficient for
76 * mutexes, which depend on things like cache line alignment.  Mutex alignment
77 * is handled separately, in mutex.h.
78 *
79 * db_alignp_t --
80 * Integral type that's the same size as a pointer.  There are places where
81 * DB modifies pointers by discarding the bottom bits to guarantee alignment.
82 * We can't use db_align_t, it may be larger than the pointer, and compilers
83 * get upset about that.  So far we haven't run on any machine where there
84 * isn't an integral type the same size as a pointer -- here's hoping.
85 */
86typedef unsigned long db_align_t;
87typedef unsigned long db_alignp_t;
88
89/* Align an integer to a specific boundary. */
90#undef  ALIGN
91#define ALIGN(value, bound) \
92    (((value) + (bound) - 1) & ~(((u_int)bound) - 1))
93
94/* Align a pointer to a specific boundary. */
95#undef  ALIGNP
96#define ALIGNP(value, bound)    ALIGN((db_alignp_t)value, bound)
97
98/*
99 * There are several on-page structures that are declared to have a number of
100 * fields followed by a variable length array of items.  The structure size
101 * without including the variable length array or the address of the first of
102 * those elements can be found using SSZ.
103 *
104 * This macro can also be used to find the offset of a structure element in a
105 * structure.  This is used in various places to copy structure elements from
106 * unaligned memory references, e.g., pointers into a packed page.
107 *
108 * There are two versions because compilers object if you take the address of
109 * an array.
110 */
111#undef  SSZ
112#define SSZ(name, field)        ((int)&(((name *)0)->field))
113
114#undef  SSZA
115#define SSZA(name, field)       ((int)&(((name *)0)->field[0]))
116
117/*
118 * Print an address as a u_long (a u_long is the largest type we can print
119 * portably).  Most 64-bit systems have made longs 64-bits, so this should
120 * work.
121 */
122#define P_TO_ULONG(p)   ((u_long)(db_alignp_t)(p))
123
124/* Structure used to print flag values. */
125typedef struct __fn {
126        u_int32_t mask;                 /* Flag value. */
127        const char *name;               /* Flag name. */
128} FN;
129
130/* Set, clear and test flags. */
131#define FLD_CLR(fld, f)         (fld) &= ~(f)
132#define FLD_ISSET(fld, f)       ((fld) & (f))
133#define FLD_SET(fld, f)         (fld) |= (f)
134#define F_CLR(p, f)             (p)->flags &= ~(f)
135#define F_ISSET(p, f)           ((p)->flags & (f))
136#define F_SET(p, f)             (p)->flags |= (f)
137#define LF_CLR(f)               (flags &= ~(f))
138#define LF_ISSET(f)             (flags & (f))
139#define LF_SET(f)               (flags |= (f))
140
141/* Display separator string. */
142#undef  DB_LINE
143#define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
144
145/* Unused, or not-used-yet variable.  "Shut that bloody compiler up!" */
146#define COMPQUIET(n, v) (n) = (v)
147
148/*******************************************************
149 * Files.
150 *******************************************************/
151 /*
152  * We use 1024 as the maximum path length.  It's too hard to figure out what
153  * the real path length is, as it was traditionally stored in <sys/param.h>,
154  * and that file isn't always available.
155  */
156#undef  MAXPATHLEN
157#define MAXPATHLEN      1024
158
159#define PATH_DOT        "."     /* Current working directory. */
160#define PATH_SEPARATOR  "/"     /* Path separator character. */
161
162/*
163 * Flags understood by __os_open.
164 */
165#define DB_OSO_CREATE   0x001           /* POSIX: O_CREAT */
166#define DB_OSO_EXCL     0x002           /* POSIX: O_EXCL */
167#define DB_OSO_LOG      0x004           /* Opening a log file. */
168#define DB_OSO_RDONLY   0x008           /* POSIX: O_RDONLY */
169#define DB_OSO_SEQ      0x010           /* Expected sequential access. */
170#define DB_OSO_TEMP     0x020           /* Remove after last close. */
171#define DB_OSO_TRUNC    0x040           /* POSIX: O_TRUNC */
172
173/*
174 * Seek options understood by __os_seek.
175 */
176typedef enum {
177        DB_OS_SEEK_CUR,                 /* POSIX: SEEK_CUR */
178        DB_OS_SEEK_END,                 /* POSIX: SEEK_END */
179        DB_OS_SEEK_SET                  /* POSIX: SEEK_SET */
180} DB_OS_SEEK;
181
182/*******************************************************
183 * Environment.
184 *******************************************************/
185/* Type passed to __db_appname(). */
186typedef enum {
187        DB_APP_NONE=0,                  /* No type (region). */
188        DB_APP_DATA,                    /* Data file. */
189        DB_APP_LOG,                     /* Log file. */
190        DB_APP_TMP                      /* Temporary file. */
191} APPNAME;
192
193/*
194 * CDB_LOCKING  CDB product locking.
195 * LOCKING_ON   Locking has been configured.
196 * LOGGING_ON   Logging has been configured.
197 * MPOOL_ON     Memory pool has been configured.
198 * TXN_ON       Transactions have been configured.
199 */
200#define CDB_LOCKING(dbenv)      F_ISSET(dbenv, DB_ENV_CDB)
201#define LOCKING_ON(dbenv)       ((dbenv)->lk_handle != NULL)
202#define LOGGING_ON(dbenv)       ((dbenv)->lg_handle != NULL)
203#define MPOOL_ON(dbenv)         ((dbenv)->mp_handle != NULL)
204#define TXN_ON(dbenv)           ((dbenv)->tx_handle != NULL)
205
206/*
207 * STD_LOCKING  Standard locking, that is, locking was configured and CDB
208 *              was not.  We do not do locking in off-page duplicate trees,
209 *              so we check for that in the cursor first.
210 */
211#define STD_LOCKING(dbc)                                                \
212        (!F_ISSET(dbc, DBC_OPD) &&                                      \
213            !CDB_LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv))
214
215/*
216 * IS_RECOVERING The system is running recovery.
217 */
218#define IS_RECOVERING(dbenv)                                            \
219        (LOGGING_ON(dbenv) &&                                           \
220            F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER))
221
222/* Most initialization methods cannot be called after open is called. */
223#define ENV_ILLEGAL_AFTER_OPEN(dbenv, name)                             \
224        if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                       \
225                return (__db_mi_open(dbenv, name, 1));
226
227/* We're not actually user hostile, honest. */
228#define ENV_REQUIRES_CONFIG(dbenv, handle, subsystem)                   \
229        if (handle == NULL)                                             \
230                return (__db_env_config(dbenv, subsystem));
231
232/*******************************************************
233 * Database Access Methods.
234 *******************************************************/
235/*
236 * DB_IS_THREADED --
237 *      The database handle is free-threaded (was opened with DB_THREAD).
238 */
239#define DB_IS_THREADED(dbp)                                             \
240        ((dbp)->mutexp != NULL)
241
242/* Initialization methods are often illegal before/after open is called. */
243#define DB_ILLEGAL_AFTER_OPEN(dbp, name)                                \
244        if (F_ISSET((dbp), DB_OPEN_CALLED))                             \
245                return (__db_mi_open(dbp->dbenv, name, 1));
246#define DB_ILLEGAL_BEFORE_OPEN(dbp, name)                               \
247        if (!F_ISSET((dbp), DB_OPEN_CALLED))                            \
248                return (__db_mi_open(dbp->dbenv, name, 0));
249/* Some initialization methods are illegal if environment isn't local. */
250#define DB_ILLEGAL_IN_ENV(dbp, name)                                    \
251        if (!F_ISSET(dbp->dbenv, DB_ENV_DBLOCAL))                       \
252                return (__db_mi_env(dbp->dbenv, name));
253#define DB_ILLEGAL_METHOD(dbp, flags) {                                 \
254        int __ret;                                                      \
255        if ((__ret = __dbh_am_chk(dbp, flags)) != 0)                    \
256                return (__ret);                                         \
257}
258
259/*
260 * Common DBC->internal fields.  Each access method adds additional fields
261 * to this list, but the initial fields are common.
262 */
263#define __DBC_INTERNAL                                                  \
264        DBC      *opd;                  /* Off-page duplicate cursor. */\
265                                                                        \
266        void     *page;                 /* Referenced page. */          \
267        db_pgno_t root;                 /* Tree root. */                \
268        db_pgno_t pgno;                 /* Referenced page number. */   \
269        db_indx_t indx;                 /* Referenced key item index. */\
270                                                                        \
271        DB_LOCK         lock;           /* Cursor lock. */              \
272        db_lockmode_t   lock_mode;      /* Lock mode. */
273
274struct __dbc_internal {
275        __DBC_INTERNAL
276};
277
278/*******************************************************
279 * Mpool.
280 *******************************************************/
281/*
282 * File types for DB access methods.  Negative numbers are reserved to DB.
283 */
284#define DB_FTYPE_SET            -1      /* Call pgin/pgout functions. */
285#define DB_FTYPE_NOTSET          0      /* Don't call... */
286
287/* Structure used as the DB pgin/pgout pgcookie. */
288typedef struct __dbpginfo {
289        size_t  db_pagesize;            /* Underlying page size. */
290        int     needswap;               /* If swapping required. */
291} DB_PGINFO;
292
293/*******************************************************
294 * Log.
295 *******************************************************/
296/* Initialize an LSN to 'zero'. */
297#define ZERO_LSN(LSN) do {                                              \
298        (LSN).file = 0;                                                 \
299        (LSN).offset = 0;                                               \
300} while (0)
301
302/* Return 1 if LSN is a 'zero' lsn, otherwise return 0. */
303#define IS_ZERO_LSN(LSN)        ((LSN).file == 0)
304
305/* Test if we need to log a change. */
306#define DB_LOGGING(dbc)                                                 \
307        (LOGGING_ON((dbc)->dbp->dbenv) && !F_ISSET(dbc, DBC_RECOVER))
308
309/* Internal flag for use with internal __log_unregister. */
310#define DB_LOGONLY      0x01
311/*******************************************************
312 * Txn.
313 *******************************************************/
314#define DB_NONBLOCK(C)  ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT))
315
316/*******************************************************
317 * Global variables.
318 *******************************************************/
319#ifdef HAVE_VXWORKS
320#include "semLib.h"
321#endif
322
323/*
324 * DB global variables.  Done in a single structure to minimize the name-space
325 * pollution.
326 */
327typedef struct __db_globals {
328        u_int32_t db_mutexlocks;        /* db_set_mutexlocks */
329        u_int32_t db_pageyield;         /* db_set_pageyield */
330        u_int32_t db_panic;             /* db_set_panic */
331        u_int32_t db_region_init;       /* db_set_region_init */
332        u_int32_t db_tas_spins;         /* db_set_tas_spins */
333#ifdef HAVE_VXWORKS
334        u_int32_t db_global_init;       /* VxWorks: inited */
335        SEM_ID db_global_lock;          /* VxWorks: global semaphore */
336#endif
337                                        /* XA: list of opened environments. */
338        TAILQ_HEAD(__db_envq, __db_env) db_envq;
339} DB_GLOBALS;
340
341#ifdef DB_INITIALIZE_DB_GLOBALS
342DB_GLOBALS __db_global_values = {
343        1,                                      /* db_set_mutexlocks */
344        0,                                      /* db_set_pageyield */
345        1,                                      /* db_set_panic */
346        0,                                      /* db_set_region_init */
347        0,                                      /* db_set_tas_spins */
348#ifdef HAVE_VXWORKS
349        0,                                      /* db_global_init */
350        NULL,                                   /* db_global_lock */
351#endif
352                                                /* XA environment queue */
353        {NULL, &__db_global_values.db_envq.tqh_first}
354};
355#else
356extern  DB_GLOBALS      __db_global_values;
357#endif
358#define DB_GLOBAL(v)    __db_global_values.v
359
360/* Forward structure declarations. */
361struct __db_reginfo_t;  typedef struct __db_reginfo_t REGINFO;
362struct __mutex_t;       typedef struct __mutex_t MUTEX;
363struct __vrfy_childinfo; typedef struct __vrfy_childinfo VRFY_CHILDINFO;
364struct __vrfy_dbinfo;   typedef struct __vrfy_dbinfo VRFY_DBINFO;
365struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO;
366
367#if defined(__cplusplus)
368}
369#endif
370
371/*******************************************************
372 * More general includes.
373 *******************************************************/
374#include "debug.h"
375#include "mutex.h"
376#include "mutex_ext.h"
377#include "region.h"
378#include "env_ext.h"
379#include "os.h"
380#include "os_ext.h"
381#include "common_ext.h"
382
383#endif /* !_DB_INTERNAL_H_ */
Note: See TracBrowser for help on using the repository browser.