AryaWu/sqlite
0
1/*2** 2004 May 223**4** The author disclaims copyright to this source code. In place of5** 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 to14** all of the platform-specific files (os_*.c) and is #included into those15** files.16**17** This file should be #included by the os_*.c files only. It is not a18** 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_DEBUG25** macro to SQLITE_DEBUG and some older makefiles have not yet made the26** switch. The following code should catch this problem at compile-time.27*/28#ifdef MEMORY_DEBUG29# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."30#endif31 32/*33** Macros for performance tracing. Normally turned off. Only works34** on i486 hardware.35*/36#ifdef SQLITE_PERFORMANCE_TRACE37 38static sqlite_uint64 g_start;39static sqlite_uint64 g_elapsed;40#define TIMER_START g_start=sqlite3Hwtime()41#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start42#define TIMER_ELAPSED g_elapsed43#else44#define TIMER_START45#define TIMER_END46#define TIMER_ELAPSED ((sqlite_uint64)0)47#endif48 49/*50** If we compile with the SQLITE_TEST macro set, then the following block51** of code will give us the ability to simulate a disk I/O error. This52** is used for testing the I/O recovery logic.53*/54#if defined(SQLITE_TEST)55extern int sqlite3_io_error_hit;56extern int sqlite3_io_error_hardhit;57extern int sqlite3_io_error_pending;58extern int sqlite3_io_error_persist;59extern int sqlite3_io_error_benign;60extern int sqlite3_diskfull_pending;61extern int sqlite3_diskfull;62#define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X)63#define SimulateIOError(CODE) \64 if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \65 || sqlite3_io_error_pending-- == 1 ) \66 { local_ioerr(); CODE; }67static void local_ioerr(){68 IOTRACE(("IOERR\n"));69 sqlite3_io_error_hit++;70 if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++;71}72#define SimulateDiskfullError(CODE) \73 if( sqlite3_diskfull_pending ){ \74 if( sqlite3_diskfull_pending == 1 ){ \75 local_ioerr(); \76 sqlite3_diskfull = 1; \77 sqlite3_io_error_hit = 1; \78 CODE; \79 }else{ \80 sqlite3_diskfull_pending--; \81 } \82 }83#else84#define SimulateIOErrorBenign(X)85#define SimulateIOError(A)86#define SimulateDiskfullError(A)87#endif /* defined(SQLITE_TEST) */88 89/*90** When testing, keep a count of the number of open files.91*/92#if defined(SQLITE_TEST)93extern int sqlite3_open_file_count;94#define OpenCounter(X) sqlite3_open_file_count+=(X)95#else96#define OpenCounter(X)97#endif /* defined(SQLITE_TEST) */98 99#endif /* !defined(_OS_COMMON_H_) */100 