00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _DB_INTERNAL_H_
00011 #define _DB_INTERNAL_H_
00012
00013
00014
00015
00016 #include "db.h"
00017
00018 #ifndef NO_SYSTEM_INCLUDES
00019 #if defined(__STDC__) || defined(__cplusplus)
00020 #include <stdarg.h>
00021 #else
00022 #include <varargs.h>
00023 #endif
00024 #endif
00025
00026
00027
00028
00029
00030
00031
00032 #undef LIST_INIT
00033 #undef LIST_INSERT_HEAD
00034 #undef LIST_REMOVE
00035 #include "queue.h"
00036 #include "shqueue.h"
00037
00038 #if defined(__cplusplus)
00039 extern "C" {
00040 #endif
00041
00042
00043
00044
00045 #define UINT16_T_MAX 0xffff
00046 #define UINT32_T_MAX 0xffffffff
00047
00048 #define MEGABYTE 1048576
00049 #define GIGABYTE 1073741824
00050
00051 #define MS_PER_SEC 1000
00052 #define USEC_PER_MS 1000
00053
00054 #define DB_MIN_PGSIZE 0x000200
00055 #define DB_MAX_PGSIZE 0x010000
00056
00057 #define RECNO_OOB 0
00058
00059
00060
00061
00062
00063 #define DB_DEF_IOSIZE (8 * 1024)
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 typedef unsigned long long db_align_t;
00086 typedef unsigned long db_alignp_t;
00087
00088
00089 #undef ALIGN
00090 #define ALIGN(value, bound) \
00091 (((value) + (bound) - 1) & ~(((u_int)bound) - 1))
00092
00093
00094 #undef ALIGNP
00095 #define ALIGNP(value, bound) ALIGN((db_alignp_t)value, bound)
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 #undef SSZ
00111 #define SSZ(name, field) ((int)&(((name *)0)->field))
00112
00113 #undef SSZA
00114 #define SSZA(name, field) ((int)&(((name *)0)->field[0]))
00115
00116
00117
00118
00119
00120
00121 #define P_TO_ULONG(p) ((u_long)(db_alignp_t)(p))
00122
00123
00124 typedef struct __fn {
00125 u_int32_t mask;
00126 const char *name;
00127 } FN;
00128
00129
00130 #define FLD_CLR(fld, f) (fld) &= ~(f)
00131 #define FLD_ISSET(fld, f) ((fld) & (f))
00132 #define FLD_SET(fld, f) (fld) |= (f)
00133 #define F_CLR(p, f) (p)->flags &= ~(f)
00134 #define F_ISSET(p, f) ((p)->flags & (f))
00135 #define F_SET(p, f) (p)->flags |= (f)
00136 #define LF_CLR(f) (flags &= ~(f))
00137 #define LF_ISSET(f) (flags & (f))
00138 #define LF_SET(f) (flags |= (f))
00139
00140
00141 #undef DB_LINE
00142 #define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
00143
00144
00145 #define COMPQUIET(n, v) (n) = (v)
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #undef MAXPATHLEN
00156 #define MAXPATHLEN 1024
00157
00158 #define PATH_DOT "."
00159 #define PATH_SEPARATOR "/"
00160
00161
00162
00163
00164 #define DB_OSO_CREATE 0x001
00165 #define DB_OSO_EXCL 0x002
00166 #define DB_OSO_LOG 0x004
00167 #define DB_OSO_RDONLY 0x008
00168 #define DB_OSO_SEQ 0x010
00169 #define DB_OSO_TEMP 0x020
00170 #define DB_OSO_TRUNC 0x040
00171
00172
00173
00174
00175 typedef enum {
00176 DB_OS_SEEK_CUR,
00177 DB_OS_SEEK_END,
00178 DB_OS_SEEK_SET
00179 } DB_OS_SEEK;
00180
00181
00182
00183
00184
00185 typedef enum {
00186 DB_APP_NONE=0,
00187 DB_APP_DATA,
00188 DB_APP_LOG,
00189 DB_APP_TMP
00190 } APPNAME;
00191
00192
00193
00194
00195
00196
00197
00198
00199 #define LOCKING(dbenv) F_ISSET(dbenv, DB_ENV_CDB)
00200 #define LOCKING_ON(dbenv) ((dbenv)->lk_handle != NULL)
00201 #define LOGGING_ON(dbenv) ((dbenv)->lg_handle != NULL)
00202 #define MPOOL_ON(dbenv) ((dbenv)->mp_handle != NULL)
00203 #define TXN_ON(dbenv) ((dbenv)->tx_handle != NULL)
00204
00205
00206
00207
00208
00209
00210 #define STD_LOCKING(dbc) \
00211 (!F_ISSET(dbc, DBC_OPD) && \
00212 !LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv))
00213
00214
00215
00216
00217 #define IS_RECOVERING(dbenv) \
00218 (LOGGING_ON(dbenv) && \
00219 F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER))
00220
00221
00222 #define ENV_ILLEGAL_AFTER_OPEN(dbenv, name) \
00223 if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED)) \
00224 return (CDB___db_mi_open(dbenv, name, 1));
00225
00226
00227 #define ENV_REQUIRES_CONFIG(dbenv, handle, subsystem) \
00228 if (handle == NULL) \
00229 return (CDB___db_env_config(dbenv, subsystem));
00230
00231
00232
00233
00234
00235
00236
00237
00238 #define DB_IS_THREADED(dbp) \
00239 ((dbp)->mutexp != NULL)
00240
00241
00242 #define DB_ILLEGAL_AFTER_OPEN(dbp, name) \
00243 if (F_ISSET((dbp), DB_OPEN_CALLED)) \
00244 return (CDB___db_mi_open(dbp->dbenv, name, 1));
00245 #define DB_ILLEGAL_BEFORE_OPEN(dbp, name) \
00246 if (!F_ISSET((dbp), DB_OPEN_CALLED)) \
00247 return (CDB___db_mi_open(dbp->dbenv, name, 0));
00248
00249 #define DB_ILLEGAL_IN_ENV(dbp, name) \
00250 if (!F_ISSET(dbp->dbenv, DB_ENV_DBLOCAL)) \
00251 return (CDB___db_mi_env(dbp->dbenv, name));
00252 #define DB_ILLEGAL_METHOD(dbp, flags) { \
00253 int __ret; \
00254 if ((__ret = CDB___dbh_am_chk(dbp, flags)) != 0) \
00255 return (__ret); \
00256 }
00257
00258
00259
00260
00261
00262 #define __DBC_INTERNAL \
00263 DBC *opd; \
00264 \
00265 void *page; \
00266 db_pgno_t root; \
00267 db_pgno_t pgno; \
00268 db_indx_t indx; \
00269 \
00270 DB_LOCK lock; \
00271 db_lockmode_t lock_mode;
00272
00273 struct __dbc_internal {
00274 __DBC_INTERNAL
00275 };
00276
00277
00278
00279
00280
00281
00282
00283 #define DB_FTYPE_SET -1
00284 #define DB_FTYPE_NOTSET 0
00285
00286
00287 typedef struct __dbpginfo {
00288 size_t db_pagesize;
00289 int needswap;
00290 } DB_PGINFO;
00291
00292
00293
00294
00295
00296 #define ZERO_LSN(LSN) do { \
00297 (LSN).file = 0; \
00298 (LSN).offset = 0; \
00299 } while (0)
00300
00301
00302 #define IS_ZERO_LSN(LSN) ((LSN).file == 0)
00303
00304
00305 #define DB_LOGGING(dbc) \
00306 (LOGGING_ON((dbc)->dbp->dbenv) && !F_ISSET(dbc, DBC_RECOVER))
00307
00308
00309 #define DB_LOGONLY 0x01
00310
00311
00312
00313 #define DB_NONBLOCK(C) ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT))
00314
00315
00316
00317
00318 #ifdef HAVE_VXWORKS
00319 #include "semLib.h"
00320 #endif
00321
00322
00323
00324
00325
00326 typedef struct __db_globals {
00327 u_int32_t db_mutexlocks;
00328 u_int32_t db_pageyield;
00329 u_int32_t db_panic;
00330 u_int32_t db_region_init;
00331 u_int32_t db_tas_spins;
00332 #ifdef HAVE_VXWORKS
00333 u_int32_t db_global_init;
00334 SEM_ID db_global_lock;
00335 #endif
00336
00337 TAILQ_HEAD(__db_envq, __db_env) db_envq;
00338 } DB_GLOBALS;
00339
00340 #ifdef DB_INITIALIZE_DB_GLOBALS
00341 DB_GLOBALS CDB___db_global_values = {
00342 1,
00343 0,
00344 1,
00345 0,
00346 0,
00347 #ifdef HAVE_VXWORKS
00348 0,
00349 NULL,
00350 #endif
00351
00352 {NULL, &CDB___db_global_values.db_envq.tqh_first}
00353 };
00354 #else
00355 extern DB_GLOBALS CDB___db_global_values;
00356 #endif
00357 #define DB_GLOBAL(v) CDB___db_global_values.v
00358
00359
00360 struct __db_reginfo_t; typedef struct __db_reginfo_t REGINFO;
00361 struct __mutex_t; typedef struct __mutex_t MUTEX;
00362 struct __vrfy_childinfo; typedef struct __vrfy_childinfo VRFY_CHILDINFO;
00363 struct __vrfy_dbinfo; typedef struct __vrfy_dbinfo VRFY_DBINFO;
00364 struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO;
00365
00366 #if defined(__cplusplus)
00367 }
00368 #endif
00369
00370
00371
00372
00373 #include "debug.h"
00374 #include "mutex.h"
00375 #include "mutex_ext.h"
00376 #include "region.h"
00377 #include "env_ext.h"
00378 #include "os.h"
00379 #include "os_ext.h"
00380 #include "common_ext.h"
00381
00382 #endif