4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
11 ******************************************************************************
16 * This file contains macros and a little bit of code that is common to all of
17 * the platform-specific files (os_*.c) and is #included into those files.
19 * This file should be #included by the os_*.c files only. It is not a general
20 * purpose header file.
23 #ifndef SQLITE_OS_COMMON_H
24 #define SQLITE_OS_COMMON_H
27 * At least two bugs have slipped in because we changed the MEMORY_DEBUG macro
28 * to SQLITE_DEBUG and some older makefiles have not yet made the switch. The
29 * following code should catch this problem at compile-time.
32 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
36 int sqlite3_os_trace
= 0;
38 static int last_page
= 0;
39 #define SEEK(X) last_page=(X)
40 #define TRACE(...) if( sqlite3_os_trace ) sqlite3DebugPrintf(__VA_ARGS__)
41 #define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
42 #define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
43 #define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
44 #define TRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
45 #define TRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
46 #define TRACE6(X,Y,Z,A,B,C) if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
47 #define TRACE7(X,Y,Z,A,B,C,D) \
48 if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D)
55 #define TRACE4(X,Y,Z,A)
56 #define TRACE5(X,Y,Z,A,B)
57 #define TRACE6(X,Y,Z,A,B,C)
58 #define TRACE7(X,Y,Z,A,B,C,D)
62 * Macros for performance tracing. Normally turned off. Only works on i486
65 #ifdef SQLITE_PERFORMANCE_TRACE
66 __inline__
unsigned long long int hwtime(void)
68 unsigned long long int x
;
70 "mov %%edx, %%ecx\n\t"
74 static unsigned long long int g_start
;
75 static unsigned int elapse
;
76 # define TIMER_START g_start=hwtime()
77 # define TIMER_END elapse=hwtime()-g_start
78 # define TIMER_ELAPSED elapse
82 # define TIMER_ELAPSED 0
86 * If we compile with the SQLITE_TEST macro set, then the following block of
87 * code will give us the ability to simulate a disk I/O error. This is used for
88 * testing the I/O recovery logic.
91 int sqlite3_io_error_pending
= 0;
92 int sqlite3_diskfull_pending
= 0;
94 # define SimulateIOError(A) \
95 if( sqlite3_io_error_pending ) \
96 if( sqlite_io_error_pending-- == 1){ \
98 TRACE("SimulateIOError(): hit a pending error\n"); \
101 # define SimulateIOError(A) \
102 if( sqlite3_io_error_pending ) \
103 if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
105 static void local_ioerr()
107 sqlite3_io_error_pending
= 0; /* Really just a place to set a breakpoint */
109 # define SimulateDiskfullError \
110 if( sqlite3_diskfull_pending ) \
111 if( sqlite3_diskfull_pending-- == 1 ){ \
112 local_ioerr(); return SQLITE_FULL; }
113 #else /* !SQLITE_TEST */
114 # define SimulateIOError(A)
115 # define SimulateDiskfullError
119 ** When testing, keep a count of the number of open files.
122 int sqlite3_open_file_count
= 0;
123 # define OpenCounter(X) sqlite3_open_file_count+=(X)
124 #else /* !SQLITE_TEST */
125 # define OpenCounter(X)
128 #endif /* SQLITE_OS_COMMON_H */