00001 /* 00002 ** 2004 May 22 00003 ** 00004 ** The author disclaims copyright to this source code. In place of 00005 ** a legal notice, here is a blessing: 00006 ** 00007 ** May you do good and not evil. 00008 ** May you find forgiveness for yourself and forgive others. 00009 ** May you share freely, never taking more than you give. 00010 ** 00011 ****************************************************************************** 00012 ** 00013 ** This file contains macros and a little bit of code that is common to 00014 ** all of the platform-specific files (os_*.c) and is #included into those 00015 ** files. 00016 ** 00017 ** This file should be #included by the os_*.c files only. It is not a 00018 ** general purpose header file. 00019 ** 00020 ** $Id: os_common.h,v 1.37 2008/05/29 20:22:37 shane Exp $ 00021 */ 00022 #ifndef _OS_COMMON_H_ 00023 #define _OS_COMMON_H_ 00024 00025 /* 00026 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG 00027 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the 00028 ** switch. The following code should catch this problem at compile-time. 00029 */ 00030 #ifdef MEMORY_DEBUG 00031 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." 00032 #endif 00033 00034 00035 /* 00036 * When testing, this global variable stores the location of the 00037 * pending-byte in the database file. 00038 */ 00039 #ifdef SQLITE_TEST 00040 unsigned int sqlite3_pending_byte = 0x40000000; 00041 #endif 00042 00043 #ifdef SQLITE_DEBUG 00044 int sqlite3OSTrace = 0; 00045 #define OSTRACE1(X) if( sqlite3OSTrace ) sqlite3DebugPrintf(X) 00046 #define OSTRACE2(X,Y) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y) 00047 #define OSTRACE3(X,Y,Z) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z) 00048 #define OSTRACE4(X,Y,Z,A) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A) 00049 #define OSTRACE5(X,Y,Z,A,B) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A,B) 00050 #define OSTRACE6(X,Y,Z,A,B,C) \ 00051 if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C) 00052 #define OSTRACE7(X,Y,Z,A,B,C,D) \ 00053 if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D) 00054 #else 00055 #define OSTRACE1(X) 00056 #define OSTRACE2(X,Y) 00057 #define OSTRACE3(X,Y,Z) 00058 #define OSTRACE4(X,Y,Z,A) 00059 #define OSTRACE5(X,Y,Z,A,B) 00060 #define OSTRACE6(X,Y,Z,A,B,C) 00061 #define OSTRACE7(X,Y,Z,A,B,C,D) 00062 #endif 00063 00064 /* 00065 ** Macros for performance tracing. Normally turned off. Only works 00066 ** on i486 hardware. 00067 */ 00068 #ifdef SQLITE_PERFORMANCE_TRACE 00069 00070 /* 00071 ** hwtime.h contains inline assembler code for implementing 00072 ** high-performance timing routines. 00073 */ 00074 #include "hwtime.h" 00075 00076 static sqlite_uint64 g_start; 00077 static sqlite_uint64 g_elapsed; 00078 #define TIMER_START g_start=sqlite3Hwtime() 00079 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start 00080 #define TIMER_ELAPSED g_elapsed 00081 #else 00082 #define TIMER_START 00083 #define TIMER_END 00084 #define TIMER_ELAPSED ((sqlite_uint64)0) 00085 #endif 00086 00087 /* 00088 ** If we compile with the SQLITE_TEST macro set, then the following block 00089 ** of code will give us the ability to simulate a disk I/O error. This 00090 ** is used for testing the I/O recovery logic. 00091 */ 00092 #ifdef SQLITE_TEST 00093 int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */ 00094 int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */ 00095 int sqlite3_io_error_pending = 0; /* Count down to first I/O error */ 00096 int sqlite3_io_error_persist = 0; /* True if I/O errors persist */ 00097 int sqlite3_io_error_benign = 0; /* True if errors are benign */ 00098 int sqlite3_diskfull_pending = 0; 00099 int sqlite3_diskfull = 0; 00100 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) 00101 #define SimulateIOError(CODE) \ 00102 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ 00103 || sqlite3_io_error_pending-- == 1 ) \ 00104 { local_ioerr(); CODE; } 00105 static void local_ioerr(){ 00106 IOTRACE(("IOERR\n")); 00107 sqlite3_io_error_hit++; 00108 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; 00109 } 00110 #define SimulateDiskfullError(CODE) \ 00111 if( sqlite3_diskfull_pending ){ \ 00112 if( sqlite3_diskfull_pending == 1 ){ \ 00113 local_ioerr(); \ 00114 sqlite3_diskfull = 1; \ 00115 sqlite3_io_error_hit = 1; \ 00116 CODE; \ 00117 }else{ \ 00118 sqlite3_diskfull_pending--; \ 00119 } \ 00120 } 00121 #else 00122 #define SimulateIOErrorBenign(X) 00123 #define SimulateIOError(A) 00124 #define SimulateDiskfullError(A) 00125 #endif 00126 00127 /* 00128 ** When testing, keep a count of the number of open files. 00129 */ 00130 #ifdef SQLITE_TEST 00131 int sqlite3_open_file_count = 0; 00132 #define OpenCounter(X) sqlite3_open_file_count+=(X) 00133 #else 00134 #define OpenCounter(X) 00135 #endif 00136 00137 #endif /* !defined(_OS_COMMON_H_) */
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:55 2011 by Doxygen 1.6.1