-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathos_common_h.cs
More file actions
executable file
·225 lines (214 loc) · 6.64 KB
/
os_common_h.cs
File metadata and controls
executable file
·225 lines (214 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System.Diagnostics;
using va_list = System.Object;
namespace System.Data.SQLite
{
public partial class Sqlite3
{
/*
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains macros and a little bit of code that is common to
** all of the platform-specific files (os_*.c) and is #included into those
** files.
**
** This file should be #included by the os_*.c files only. It is not a
** general purpose header file.
*************************************************************************
** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
** C#-SQLite is an independent reimplementation of the SQLite software library
**
** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
**
*************************************************************************
*/
//#if !_OS_COMMON_H_
//#define _OS_COMMON_H_
/*
** At least two bugs have slipped in because we changed the MEMORY_DEBUG
** macro to SQLITE_DEBUG and some older makefiles have not yet made the
** switch. The following code should catch this problem at compile-time.
*/
#if MEMORY_DEBUG
//# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
#endif
#if SQLITE_DEBUG || TRACE
static bool sqlite3OsTrace = false;
//#define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
static void OSTRACE( string X, params va_list[] ap )
{
if ( sqlite3OsTrace )
sqlite3DebugPrintf( X, ap );
}
#else
//#define OSTRACE(X)
static void OSTRACE(string X, params object[] ap) { }
#endif
/*
** Macros for performance tracing. Normally turned off. Only works
** on i486 hardware.
*/
#if SQLITE_PERFORMANCE_TRACE
/*
** hwtime.h contains inline assembler code for implementing
** high-performance timing routines.
*/
//#include "hwtime.h"
static sqlite_u3264 g_start;
static sqlite_u3264 g_elapsed;
//#define TIMER_START g_start=sqlite3Hwtime()
//#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start
//#define TIMER_ELAPSED g_elapsed
#else
const int TIMER_START = 0; //#define TIMER_START
const int TIMER_END = 0; //#define TIMER_END
const int TIMER_ELAPSED = 0; //#define TIMER_ELAPSED ((sqlite_u3264)0)
#endif
/*
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error. This
** is used for testing the I/O recovery logic.
*/
#if SQLITE_TEST
#if !TCLSH
static int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */
static int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */
static int sqlite3_io_error_pending = 0; /* Count down to first I/O error */
static int sqlite3_io_error_persist = 0; /* True if I/O errors persist */
static int sqlite3_io_error_benign = 0; /* True if errors are benign */
static int sqlite3_diskfull_pending = 0;
static int sqlite3_diskfull = 0;
#else
static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_hit = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_hit" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_hardhit = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_hardhit" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_pending = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_pending" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_persist = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_persist" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_io_error_benign = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_io_error_benign" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_diskfull_pending = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_diskfull_pending" );
static tcl.lang.Var.SQLITE3_GETSET sqlite3_diskfull = new tcl.lang.Var.SQLITE3_GETSET( "sqlite_diskfull" );
#endif
static void SimulateIOErrorBenign( int X )
{
#if !TCLSH
sqlite3_io_error_benign = ( X );
#else
sqlite3_io_error_benign.iValue = ( X );
#endif
}
//#define SimulateIOError(CODE) \
// if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \
// || sqlite3_io_error_pending-- == 1 ) \
// { local_ioerr(); CODE; }
static bool SimulateIOError()
{
#if !TCLSH
if ( ( sqlite3_io_error_persist != 0 && sqlite3_io_error_hit != 0 )
|| sqlite3_io_error_pending-- == 1 )
#else
if ( ( sqlite3_io_error_persist.iValue != 0 && sqlite3_io_error_hit.iValue != 0 )
|| sqlite3_io_error_pending.iValue-- == 1 )
#endif
{
local_ioerr();
return true;
}
return false;
}
static void local_ioerr()
{
#if TRACE
IOTRACE( "IOERR\n" );
#endif
#if !TCLSH
sqlite3_io_error_hit++;
if ( sqlite3_io_error_benign == 0 )
sqlite3_io_error_hardhit++;
#else
sqlite3_io_error_hit.iValue++;
if ( sqlite3_io_error_benign.iValue == 0 )
sqlite3_io_error_hardhit.iValue++;
#endif
}
//#define SimulateDiskfullError(CODE) \
// if( sqlite3_diskfull_pending ){ \
// if( sqlite3_diskfull_pending == 1 ){ \
// local_ioerr(); \
// sqlite3_diskfull = 1; \
// sqlite3_io_error_hit = 1; \
// CODE; \
// }else{ \
// sqlite3_diskfull_pending--; \
// } \
// }
static bool SimulateDiskfullError()
{
#if !TCLSH
if ( sqlite3_diskfull_pending != 0 )
{
if ( sqlite3_diskfull_pending == 1 )
{
#else
if ( sqlite3_diskfull_pending.iValue != 0 )
{
if ( sqlite3_diskfull_pending.iValue == 1 )
{
#endif
local_ioerr();
#if !TCLSH
sqlite3_diskfull = 1;
sqlite3_io_error_hit = 1;
#else
sqlite3_diskfull.iValue = 1;
sqlite3_io_error_hit.iValue = 1;
#endif
return true;
}
else
{
#if !TCLSH
sqlite3_diskfull_pending--;
#else
sqlite3_diskfull_pending.iValue--;
#endif
}
}
return false;
}
#else
static bool SimulateIOError() { return false; }
//#define SimulateIOErrorBenign(X)
static void SimulateIOErrorBenign(int x) { }
//#define SimulateIOError(A)
//#define SimulateDiskfullError(A)
#endif
/*
** When testing, keep a count of the number of open files.
*/
#if SQLITE_TEST
#if !TCLSH
static int sqlite3_open_file_count = 0;
#else
static tcl.lang.Var.SQLITE3_GETSET sqlite3_open_file_count = new tcl.lang.Var.SQLITE3_GETSET( "sqlite3_open_file_count" );
#endif
static void OpenCounter( int X )
{
#if !TCLSH
sqlite3_open_file_count += ( X );
#else
sqlite3_open_file_count.iValue += ( X );
#endif
}
#else
//#define OpenCounter(X)
#endif
//#endif //* !_OS_COMMON_H_) */
}
}