|
1 /* |
|
2 ** 2004 May 22 |
|
3 ** |
|
4 ** The author disclaims copyright to this source code. In place of |
|
5 ** a legal notice, here is a blessing: |
|
6 ** |
|
7 ** May you do good and not evil. |
|
8 ** May you find forgiveness for yourself and forgive others. |
|
9 ** May you share freely, never taking more than you give. |
|
10 ** |
|
11 ****************************************************************************** |
|
12 ** |
|
13 ** This file contains macros and a little bit of code that is common to |
|
14 ** all of the platform-specific files (os_*.c) and is #included into those |
|
15 ** files. |
|
16 ** |
|
17 ** This file should be #included by the os_*.c files only. It is not a |
|
18 ** general purpose header file. |
|
19 ** |
|
20 ** $Id: os_common.h,v 1.37 2008/05/29 20:22:37 shane Exp $ |
|
21 */ |
|
22 #ifndef _OS_COMMON_H_ |
|
23 #define _OS_COMMON_H_ |
|
24 |
|
25 /* |
|
26 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
|
27 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
|
28 ** switch. The following code should catch this problem at compile-time. |
|
29 */ |
|
30 #ifdef MEMORY_DEBUG |
|
31 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
|
32 #endif |
|
33 |
|
34 |
|
35 /* |
|
36 * When testing, this global variable stores the location of the |
|
37 * pending-byte in the database file. |
|
38 */ |
|
39 #ifdef SQLITE_TEST |
|
40 unsigned int sqlite3_pending_byte = 0x40000000; |
|
41 #endif |
|
42 |
|
43 #ifdef SQLITE_DEBUG |
|
44 int sqlite3OSTrace = 0; |
|
45 #define OSTRACE1(X) if( sqlite3OSTrace ) sqlite3DebugPrintf(X) |
|
46 #define OSTRACE2(X,Y) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y) |
|
47 #define OSTRACE3(X,Y,Z) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z) |
|
48 #define OSTRACE4(X,Y,Z,A) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A) |
|
49 #define OSTRACE5(X,Y,Z,A,B) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A,B) |
|
50 #define OSTRACE6(X,Y,Z,A,B,C) \ |
|
51 if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C) |
|
52 #define OSTRACE7(X,Y,Z,A,B,C,D) \ |
|
53 if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D) |
|
54 #else |
|
55 #define OSTRACE1(X) |
|
56 #define OSTRACE2(X,Y) |
|
57 #define OSTRACE3(X,Y,Z) |
|
58 #define OSTRACE4(X,Y,Z,A) |
|
59 #define OSTRACE5(X,Y,Z,A,B) |
|
60 #define OSTRACE6(X,Y,Z,A,B,C) |
|
61 #define OSTRACE7(X,Y,Z,A,B,C,D) |
|
62 #endif |
|
63 |
|
64 /* |
|
65 ** Macros for performance tracing. Normally turned off. Only works |
|
66 ** on i486 hardware. |
|
67 */ |
|
68 #ifdef SQLITE_PERFORMANCE_TRACE |
|
69 |
|
70 /* |
|
71 ** hwtime.h contains inline assembler code for implementing |
|
72 ** high-performance timing routines. |
|
73 */ |
|
74 #include "hwtime.h" |
|
75 |
|
76 static sqlite_uint64 g_start; |
|
77 static sqlite_uint64 g_elapsed; |
|
78 #define TIMER_START g_start=sqlite3Hwtime() |
|
79 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
|
80 #define TIMER_ELAPSED g_elapsed |
|
81 #else |
|
82 #define TIMER_START |
|
83 #define TIMER_END |
|
84 #define TIMER_ELAPSED ((sqlite_uint64)0) |
|
85 #endif |
|
86 |
|
87 /* |
|
88 ** If we compile with the SQLITE_TEST macro set, then the following block |
|
89 ** of code will give us the ability to simulate a disk I/O error. This |
|
90 ** is used for testing the I/O recovery logic. |
|
91 */ |
|
92 #ifdef SQLITE_TEST |
|
93 int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */ |
|
94 int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */ |
|
95 int sqlite3_io_error_pending = 0; /* Count down to first I/O error */ |
|
96 int sqlite3_io_error_persist = 0; /* True if I/O errors persist */ |
|
97 int sqlite3_io_error_benign = 0; /* True if errors are benign */ |
|
98 int sqlite3_diskfull_pending = 0; |
|
99 int sqlite3_diskfull = 0; |
|
100 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
|
101 #define SimulateIOError(CODE) \ |
|
102 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
|
103 || sqlite3_io_error_pending-- == 1 ) \ |
|
104 { local_ioerr(); CODE; } |
|
105 static void local_ioerr(){ |
|
106 IOTRACE(("IOERR\n")); |
|
107 sqlite3_io_error_hit++; |
|
108 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
|
109 } |
|
110 #define SimulateDiskfullError(CODE) \ |
|
111 if( sqlite3_diskfull_pending ){ \ |
|
112 if( sqlite3_diskfull_pending == 1 ){ \ |
|
113 local_ioerr(); \ |
|
114 sqlite3_diskfull = 1; \ |
|
115 sqlite3_io_error_hit = 1; \ |
|
116 CODE; \ |
|
117 }else{ \ |
|
118 sqlite3_diskfull_pending--; \ |
|
119 } \ |
|
120 } |
|
121 #else |
|
122 #define SimulateIOErrorBenign(X) |
|
123 #define SimulateIOError(A) |
|
124 #define SimulateDiskfullError(A) |
|
125 #endif |
|
126 |
|
127 /* |
|
128 ** When testing, keep a count of the number of open files. |
|
129 */ |
|
130 #ifdef SQLITE_TEST |
|
131 int sqlite3_open_file_count = 0; |
|
132 #define OpenCounter(X) sqlite3_open_file_count+=(X) |
|
133 #else |
|
134 #define OpenCounter(X) |
|
135 #endif |
|
136 |
|
137 #endif /* !defined(_OS_COMMON_H_) */ |