1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/extensions/sqlite/sqlite-source/os_common.h Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,127 @@
1.4 +/*
1.5 +** 2004 May 22
1.6 +**
1.7 +** The author disclaims copyright to this source code. In place of
1.8 +** a legal notice, here is a blessing:
1.9 +**
1.10 +** May you do good and not evil.
1.11 +** May you find forgiveness for yourself and forgive others.
1.12 +** May you share freely, never taking more than you give.
1.13 +**
1.14 +******************************************************************************
1.15 +**
1.16 +** This file contains macros and a little bit of code that is common to
1.17 +** all of the platform-specific files (os_*.c) and is #included into those
1.18 +** files.
1.19 +**
1.20 +** This file should be #included by the os_*.c files only. It is not a
1.21 +** general purpose header file.
1.22 +*/
1.23 +
1.24 +/*
1.25 +** At least two bugs have slipped in because we changed the MEMORY_DEBUG
1.26 +** macro to SQLITE_DEBUG and some older makefiles have not yet made the
1.27 +** switch. The following code should catch this problem at compile-time.
1.28 +*/
1.29 +#ifdef MEMORY_DEBUG
1.30 +# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
1.31 +#endif
1.32 +
1.33 +
1.34 +/*
1.35 + * When testing, this global variable stores the location of the
1.36 + * pending-byte in the database file.
1.37 + */
1.38 +#ifdef SQLITE_TEST
1.39 +unsigned int sqlite3_pending_byte = 0x40000000;
1.40 +#endif
1.41 +
1.42 +#ifdef SQLITE_DEBUG
1.43 +int sqlite3_os_trace = 0;
1.44 +#define OSTRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
1.45 +#define OSTRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
1.46 +#define OSTRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
1.47 +#define OSTRACE4(X,Y,Z,A) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
1.48 +#define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
1.49 +#define OSTRACE6(X,Y,Z,A,B,C) \
1.50 + if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
1.51 +#define OSTRACE7(X,Y,Z,A,B,C,D) \
1.52 + if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C,D)
1.53 +#else
1.54 +#define OSTRACE1(X)
1.55 +#define OSTRACE2(X,Y)
1.56 +#define OSTRACE3(X,Y,Z)
1.57 +#define OSTRACE4(X,Y,Z,A)
1.58 +#define OSTRACE5(X,Y,Z,A,B)
1.59 +#define OSTRACE6(X,Y,Z,A,B,C)
1.60 +#define OSTRACE7(X,Y,Z,A,B,C,D)
1.61 +#endif
1.62 +
1.63 +/*
1.64 +** Macros for performance tracing. Normally turned off. Only works
1.65 +** on i486 hardware.
1.66 +*/
1.67 +#ifdef SQLITE_PERFORMANCE_TRACE
1.68 +__inline__ unsigned long long int hwtime(void){
1.69 + unsigned long long int x;
1.70 + __asm__("rdtsc\n\t"
1.71 + "mov %%edx, %%ecx\n\t"
1.72 + :"=A" (x));
1.73 + return x;
1.74 +}
1.75 +static unsigned long long int g_start;
1.76 +static unsigned int elapse;
1.77 +#define TIMER_START g_start=hwtime()
1.78 +#define TIMER_END elapse=hwtime()-g_start
1.79 +#define TIMER_ELAPSED elapse
1.80 +#else
1.81 +#define TIMER_START
1.82 +#define TIMER_END
1.83 +#define TIMER_ELAPSED 0
1.84 +#endif
1.85 +
1.86 +/*
1.87 +** If we compile with the SQLITE_TEST macro set, then the following block
1.88 +** of code will give us the ability to simulate a disk I/O error. This
1.89 +** is used for testing the I/O recovery logic.
1.90 +*/
1.91 +#ifdef SQLITE_TEST
1.92 +int sqlite3_io_error_hit = 0;
1.93 +int sqlite3_io_error_pending = 0;
1.94 +int sqlite3_io_error_persist = 0;
1.95 +int sqlite3_diskfull_pending = 0;
1.96 +int sqlite3_diskfull = 0;
1.97 +#define SimulateIOError(CODE) \
1.98 + if( sqlite3_io_error_pending || sqlite3_io_error_hit ) \
1.99 + if( sqlite3_io_error_pending-- == 1 \
1.100 + || (sqlite3_io_error_persist && sqlite3_io_error_hit) ) \
1.101 + { local_ioerr(); CODE; }
1.102 +static void local_ioerr(){
1.103 + IOTRACE(("IOERR\n"));
1.104 + sqlite3_io_error_hit = 1;
1.105 +}
1.106 +#define SimulateDiskfullError(CODE) \
1.107 + if( sqlite3_diskfull_pending ){ \
1.108 + if( sqlite3_diskfull_pending == 1 ){ \
1.109 + local_ioerr(); \
1.110 + sqlite3_diskfull = 1; \
1.111 + sqlite3_io_error_hit = 1; \
1.112 + CODE; \
1.113 + }else{ \
1.114 + sqlite3_diskfull_pending--; \
1.115 + } \
1.116 + }
1.117 +#else
1.118 +#define SimulateIOError(A)
1.119 +#define SimulateDiskfullError(A)
1.120 +#endif
1.121 +
1.122 +/*
1.123 +** When testing, keep a count of the number of open files.
1.124 +*/
1.125 +#ifdef SQLITE_TEST
1.126 +int sqlite3_open_file_count = 0;
1.127 +#define OpenCounter(X) sqlite3_open_file_count+=(X)
1.128 +#else
1.129 +#define OpenCounter(X)
1.130 +#endif