OLD | NEW |
(Empty) | |
| 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 #ifndef _OS_COMMON_H_ |
| 21 #define _OS_COMMON_H_ |
| 22 |
| 23 /* |
| 24 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG |
| 25 ** macro to SQLITE_DEBUG and some older makefiles have not yet made the |
| 26 ** switch. The following code should catch this problem at compile-time. |
| 27 */ |
| 28 #ifdef MEMORY_DEBUG |
| 29 # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." |
| 30 #endif |
| 31 |
| 32 #ifdef SQLITE_DEBUG |
| 33 int sqlite3OSTrace = 0; |
| 34 #define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 35 #else |
| 36 #define OSTRACE(X) |
| 37 #endif |
| 38 |
| 39 /* |
| 40 ** Macros for performance tracing. Normally turned off. Only works |
| 41 ** on i486 hardware. |
| 42 */ |
| 43 #ifdef SQLITE_PERFORMANCE_TRACE |
| 44 |
| 45 /* |
| 46 ** hwtime.h contains inline assembler code for implementing |
| 47 ** high-performance timing routines. |
| 48 */ |
| 49 #include "hwtime.h" |
| 50 |
| 51 static sqlite_uint64 g_start; |
| 52 static sqlite_uint64 g_elapsed; |
| 53 #define TIMER_START g_start=sqlite3Hwtime() |
| 54 #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start |
| 55 #define TIMER_ELAPSED g_elapsed |
| 56 #else |
| 57 #define TIMER_START |
| 58 #define TIMER_END |
| 59 #define TIMER_ELAPSED ((sqlite_uint64)0) |
| 60 #endif |
| 61 |
| 62 /* |
| 63 ** If we compile with the SQLITE_TEST macro set, then the following block |
| 64 ** of code will give us the ability to simulate a disk I/O error. This |
| 65 ** is used for testing the I/O recovery logic. |
| 66 */ |
| 67 #ifdef SQLITE_TEST |
| 68 int sqlite3_io_error_hit = 0; /* Total number of I/O Errors */ |
| 69 int sqlite3_io_error_hardhit = 0; /* Number of non-benign errors */ |
| 70 int sqlite3_io_error_pending = 0; /* Count down to first I/O error */ |
| 71 int sqlite3_io_error_persist = 0; /* True if I/O errors persist */ |
| 72 int sqlite3_io_error_benign = 0; /* True if errors are benign */ |
| 73 int sqlite3_diskfull_pending = 0; |
| 74 int sqlite3_diskfull = 0; |
| 75 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |
| 76 #define SimulateIOError(CODE) \ |
| 77 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |
| 78 || sqlite3_io_error_pending-- == 1 ) \ |
| 79 { local_ioerr(); CODE; } |
| 80 static void local_ioerr(){ |
| 81 IOTRACE(("IOERR\n")); |
| 82 sqlite3_io_error_hit++; |
| 83 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |
| 84 } |
| 85 #define SimulateDiskfullError(CODE) \ |
| 86 if( sqlite3_diskfull_pending ){ \ |
| 87 if( sqlite3_diskfull_pending == 1 ){ \ |
| 88 local_ioerr(); \ |
| 89 sqlite3_diskfull = 1; \ |
| 90 sqlite3_io_error_hit = 1; \ |
| 91 CODE; \ |
| 92 }else{ \ |
| 93 sqlite3_diskfull_pending--; \ |
| 94 } \ |
| 95 } |
| 96 #else |
| 97 #define SimulateIOErrorBenign(X) |
| 98 #define SimulateIOError(A) |
| 99 #define SimulateDiskfullError(A) |
| 100 #endif |
| 101 |
| 102 /* |
| 103 ** When testing, keep a count of the number of open files. |
| 104 */ |
| 105 #ifdef SQLITE_TEST |
| 106 int sqlite3_open_file_count = 0; |
| 107 #define OpenCounter(X) sqlite3_open_file_count+=(X) |
| 108 #else |
| 109 #define OpenCounter(X) |
| 110 #endif |
| 111 |
| 112 #endif /* !defined(_OS_COMMON_H_) */ |
OLD | NEW |