Made UAE buildable again.
[AROS-Contrib.git] / sqlite3 / os_common.h
blobf4f1e803e1bbaec4bccab6d4880b511c4c35b7a2
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.
11 ******************************************************************************
13 /**
14 * @file os_common.h
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.
22 * */
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.
30 * */
31 #ifdef MEMORY_DEBUG
32 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
33 #endif
36 int sqlite3_os_trace = 0;
37 #ifdef SQLITE_DEBUG
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)
49 #else
50 #define SEEK(X)
51 #define TRACE(...)
52 #define TRACE1(X)
53 #define TRACE2(X,Y)
54 #define TRACE3(X,Y,Z)
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)
59 #endif
62 * Macros for performance tracing. Normally turned off. Only works on i486
63 * hardware!
64 * */
65 #ifdef SQLITE_PERFORMANCE_TRACE
66 __inline__ unsigned long long int hwtime(void)
68 unsigned long long int x;
69 __asm__("rdtsc\n\t"
70 "mov %%edx, %%ecx\n\t"
71 :"=A" (x));
72 return x;
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
79 #else
80 # define TIMER_START
81 # define TIMER_END
82 # define TIMER_ELAPSED 0
83 #endif
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.
89 * */
90 #ifdef SQLITE_TEST
91 int sqlite3_io_error_pending = 0;
92 int sqlite3_diskfull_pending = 0;
93 # ifdef SQLITE_DEBUG
94 # define SimulateIOError(A) \
95 if( sqlite3_io_error_pending ) \
96 if( sqlite_io_error_pending-- == 1){ \
97 local_ioerr(); \
98 TRACE("SimulateIOError(): hit a pending error\n"); \
99 return A; }
100 # else
101 # define SimulateIOError(A) \
102 if( sqlite3_io_error_pending ) \
103 if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
104 # endif
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
116 #endif
119 ** When testing, keep a count of the number of open files.
121 #ifdef SQLITE_TEST
122 int sqlite3_open_file_count = 0;
123 # define OpenCounter(X) sqlite3_open_file_count+=(X)
124 #else /* !SQLITE_TEST */
125 # define OpenCounter(X)
126 #endif
128 #endif /* SQLITE_OS_COMMON_H */