1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996,2008 Oracle.  All rights reserved.
5 *
6 * $Id: globals.h,v 12.12 2008/01/17 03:26:48 bostic Exp $
7 */
8
9#ifndef _DB_GLOBALS_H_
10#define	_DB_GLOBALS_H_
11
12#if defined(__cplusplus)
13extern "C" {
14#endif
15
16/*******************************************************
17 * Global variables.
18 *
19 * Held in a single structure to minimize the name-space pollution.
20 *******************************************************/
21#ifdef HAVE_VXWORKS
22#include "semLib.h"
23#endif
24
25typedef struct __db_globals {
26#ifdef HAVE_BREW
27	struct tm ltm;			/* BREW localtime structure */
28#endif
29#ifdef HAVE_VXWORKS
30	u_int32_t db_global_init;	/* VxWorks: inited */
31	SEM_ID db_global_lock;		/* VxWorks: global semaphore */
32#endif
33					/* XA: list of opened environments. */
34	TAILQ_HEAD(__envq, __env) envq;
35
36	char *db_line;			/* DB display string. */
37
38	char error_buf[40];		/* Error string buffer. */
39
40	int uid_init;			/* srand set in UID generator */
41
42	u_long rand_next;		/* rand/srand value */
43
44	u_int32_t fid_serial;		/* file id counter */
45
46	int db_errno;			/* Errno value if not available */
47
48	int	(*j_close) __P((int));	/* Underlying OS interface jump table.*/
49	void	(*j_dirfree) __P((char **, int));
50	int	(*j_dirlist) __P((const char *, char ***, int *));
51	int	(*j_exists) __P((const char *, int *));
52	void	(*j_free) __P((void *));
53	int	(*j_fsync) __P((int));
54	int	(*j_ftruncate) __P((int, off_t));
55	int	(*j_ioinfo) __P((const char *,
56		    int, u_int32_t *, u_int32_t *, u_int32_t *));
57	void   *(*j_malloc) __P((size_t));
58	int	(*j_file_map) __P((DB_ENV *, char *, size_t, int, void **));
59	int	(*j_file_unmap) __P((DB_ENV *, void *));
60	int	(*j_open) __P((const char *, int, ...));
61	ssize_t	(*j_pread) __P((int, void *, size_t, off_t));
62	ssize_t	(*j_pwrite) __P((int, const void *, size_t, off_t));
63	ssize_t	(*j_read) __P((int, void *, size_t));
64	void   *(*j_realloc) __P((void *, size_t));
65	int	(*j_region_map) __P((DB_ENV *, char *, size_t, int *, void **));
66	int	(*j_region_unmap) __P((DB_ENV *, void *));
67	int	(*j_rename) __P((const char *, const char *));
68	int	(*j_seek) __P((int, off_t, int));
69	int	(*j_unlink) __P((const char *));
70	ssize_t	(*j_write) __P((int, const void *, size_t));
71	int	(*j_yield) __P((u_long, u_long));
72} DB_GLOBALS;
73
74#ifdef HAVE_BREW
75#define	DB_GLOBAL(v)							\
76	((DB_GLOBALS *)(((BDBApp *)GETAPPINSTANCE())->db_global_values))->v
77#else
78#ifdef DB_INITIALIZE_DB_GLOBALS
79DB_GLOBALS __db_global_values = {
80#ifdef HAVE_VXWORKS
81	0,				/* VxWorks: initialized */
82	NULL,				/* VxWorks: global semaphore */
83#endif
84					/* XA: list of opened environments. */
85	{NULL, &__db_global_values.envq.tqh_first},
86
87	"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=",
88	{ 0 },
89	0,
90	0,
91	0,
92	0,
93	NULL,
94	NULL,
95	NULL,
96	NULL,
97	NULL,
98	NULL,
99	NULL,
100	NULL,
101	NULL,
102	NULL,
103	NULL,
104	NULL,
105	NULL,
106	NULL,
107	NULL,
108	NULL,
109	NULL,
110	NULL,
111	NULL,
112	NULL,
113	NULL,
114	NULL,
115	NULL
116};
117#else
118extern	DB_GLOBALS	__db_global_values;
119#endif
120
121#define	DB_GLOBAL(v)	__db_global_values.v
122#endif /* HAVE_BREW */
123
124#if defined(__cplusplus)
125}
126#endif
127#endif /* !_DB_GLOBALS_H_ */
128