| 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 ** $Id: os_common.h,v 1.38 2009/02/24 18:40:50 danielk1977 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 #ifdef SQLITE_DEBUG |  | 
|   35 int sqlite3OSTrace = 0; |  | 
|   36 #define OSTRACE1(X)         if( sqlite3OSTrace ) sqlite3DebugPrintf(X) |  | 
|   37 #define OSTRACE2(X,Y)       if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y) |  | 
|   38 #define OSTRACE3(X,Y,Z)     if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z) |  | 
|   39 #define OSTRACE4(X,Y,Z,A)   if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A) |  | 
|   40 #define OSTRACE5(X,Y,Z,A,B) if( sqlite3OSTrace ) sqlite3DebugPrintf(X,Y,Z,A,B) |  | 
|   41 #define OSTRACE6(X,Y,Z,A,B,C) \ |  | 
|   42     if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C) |  | 
|   43 #define OSTRACE7(X,Y,Z,A,B,C,D) \ |  | 
|   44     if(sqlite3OSTrace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D) |  | 
|   45 #else |  | 
|   46 #define OSTRACE1(X) |  | 
|   47 #define OSTRACE2(X,Y) |  | 
|   48 #define OSTRACE3(X,Y,Z) |  | 
|   49 #define OSTRACE4(X,Y,Z,A) |  | 
|   50 #define OSTRACE5(X,Y,Z,A,B) |  | 
|   51 #define OSTRACE6(X,Y,Z,A,B,C) |  | 
|   52 #define OSTRACE7(X,Y,Z,A,B,C,D) |  | 
|   53 #endif |  | 
|   54  |  | 
|   55 /* |  | 
|   56 ** Macros for performance tracing.  Normally turned off.  Only works |  | 
|   57 ** on i486 hardware. |  | 
|   58 */ |  | 
|   59 #ifdef SQLITE_PERFORMANCE_TRACE |  | 
|   60  |  | 
|   61 /*  |  | 
|   62 ** hwtime.h contains inline assembler code for implementing  |  | 
|   63 ** high-performance timing routines. |  | 
|   64 */ |  | 
|   65 #include "hwtime.h" |  | 
|   66  |  | 
|   67 static sqlite_uint64 g_start; |  | 
|   68 static sqlite_uint64 g_elapsed; |  | 
|   69 #define TIMER_START       g_start=sqlite3Hwtime() |  | 
|   70 #define TIMER_END         g_elapsed=sqlite3Hwtime()-g_start |  | 
|   71 #define TIMER_ELAPSED     g_elapsed |  | 
|   72 #else |  | 
|   73 #define TIMER_START |  | 
|   74 #define TIMER_END |  | 
|   75 #define TIMER_ELAPSED     ((sqlite_uint64)0) |  | 
|   76 #endif |  | 
|   77  |  | 
|   78 /* |  | 
|   79 ** If we compile with the SQLITE_TEST macro set, then the following block |  | 
|   80 ** of code will give us the ability to simulate a disk I/O error.  This |  | 
|   81 ** is used for testing the I/O recovery logic. |  | 
|   82 */ |  | 
|   83 #ifdef SQLITE_TEST |  | 
|   84 int sqlite3_io_error_hit = 0;            /* Total number of I/O Errors */ |  | 
|   85 int sqlite3_io_error_hardhit = 0;        /* Number of non-benign errors */ |  | 
|   86 int sqlite3_io_error_pending = 0;        /* Count down to first I/O error */ |  | 
|   87 int sqlite3_io_error_persist = 0;        /* True if I/O errors persist */ |  | 
|   88 int sqlite3_io_error_benign = 0;         /* True if errors are benign */ |  | 
|   89 int sqlite3_diskfull_pending = 0; |  | 
|   90 int sqlite3_diskfull = 0; |  | 
|   91 #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) |  | 
|   92 #define SimulateIOError(CODE)  \ |  | 
|   93   if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ |  | 
|   94        || sqlite3_io_error_pending-- == 1 )  \ |  | 
|   95               { local_ioerr(); CODE; } |  | 
|   96 static void local_ioerr(){ |  | 
|   97   IOTRACE(("IOERR\n")); |  | 
|   98   sqlite3_io_error_hit++; |  | 
|   99   if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; |  | 
|  100 } |  | 
|  101 #define SimulateDiskfullError(CODE) \ |  | 
|  102    if( sqlite3_diskfull_pending ){ \ |  | 
|  103      if( sqlite3_diskfull_pending == 1 ){ \ |  | 
|  104        local_ioerr(); \ |  | 
|  105        sqlite3_diskfull = 1; \ |  | 
|  106        sqlite3_io_error_hit = 1; \ |  | 
|  107        CODE; \ |  | 
|  108      }else{ \ |  | 
|  109        sqlite3_diskfull_pending--; \ |  | 
|  110      } \ |  | 
|  111    } |  | 
|  112 #else |  | 
|  113 #define SimulateIOErrorBenign(X) |  | 
|  114 #define SimulateIOError(A) |  | 
|  115 #define SimulateDiskfullError(A) |  | 
|  116 #endif |  | 
|  117  |  | 
|  118 /* |  | 
|  119 ** When testing, keep a count of the number of open files. |  | 
|  120 */ |  | 
|  121 #ifdef SQLITE_TEST |  | 
|  122 int sqlite3_open_file_count = 0; |  | 
|  123 #define OpenCounter(X)  sqlite3_open_file_count+=(X) |  | 
|  124 #else |  | 
|  125 #define OpenCounter(X) |  | 
|  126 #endif |  | 
|  127  |  | 
|  128 #endif /* !defined(_OS_COMMON_H_) */ |  | 
| OLD | NEW |