1bbd42a6dSdrh /* 2bbd42a6dSdrh ** 2004 May 22 3bbd42a6dSdrh ** 4bbd42a6dSdrh ** The author disclaims copyright to this source code. In place of 5bbd42a6dSdrh ** a legal notice, here is a blessing: 6bbd42a6dSdrh ** 7bbd42a6dSdrh ** May you do good and not evil. 8bbd42a6dSdrh ** May you find forgiveness for yourself and forgive others. 9bbd42a6dSdrh ** May you share freely, never taking more than you give. 10bbd42a6dSdrh ** 11bbd42a6dSdrh ****************************************************************************** 12bbd42a6dSdrh ** 13bbd42a6dSdrh ** This file contains macros and a little bit of code that is common to 14bbd42a6dSdrh ** all of the platform-specific files (os_*.c) and is #included into those 15bbd42a6dSdrh ** files. 16bbd42a6dSdrh ** 17bbd42a6dSdrh ** This file should be #included by the os_*.c files only. It is not a 18bbd42a6dSdrh ** general purpose header file. 19bbd42a6dSdrh */ 209bcbdad2Sshane #ifndef _OS_COMMON_H_ 219bcbdad2Sshane #define _OS_COMMON_H_ 22bbd42a6dSdrh 23a9600bc6Sdrh /* 24a9600bc6Sdrh ** At least two bugs have slipped in because we changed the MEMORY_DEBUG 25a9600bc6Sdrh ** macro to SQLITE_DEBUG and some older makefiles have not yet made the 26a9600bc6Sdrh ** switch. The following code should catch this problem at compile-time. 27a9600bc6Sdrh */ 28a9600bc6Sdrh #ifdef MEMORY_DEBUG 29a9600bc6Sdrh # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." 30a9600bc6Sdrh #endif 31a9600bc6Sdrh 3234cf2583Smistachkin /* 33bbd42a6dSdrh ** Macros for performance tracing. Normally turned off. Only works 34bbd42a6dSdrh ** on i486 hardware. 35bbd42a6dSdrh */ 36a9600bc6Sdrh #ifdef SQLITE_PERFORMANCE_TRACE 379bcbdad2Sshane 389bcbdad2Sshane /* 399bcbdad2Sshane ** hwtime.h contains inline assembler code for implementing 409bcbdad2Sshane ** high-performance timing routines. 419bcbdad2Sshane */ 429bcbdad2Sshane #include "hwtime.h" 439bcbdad2Sshane 449bcbdad2Sshane static sqlite_uint64 g_start; 459bcbdad2Sshane static sqlite_uint64 g_elapsed; 469bcbdad2Sshane #define TIMER_START g_start=sqlite3Hwtime() 479bcbdad2Sshane #define TIMER_END g_elapsed=sqlite3Hwtime()-g_start 489bcbdad2Sshane #define TIMER_ELAPSED g_elapsed 49bbd42a6dSdrh #else 50bbd42a6dSdrh #define TIMER_START 51bbd42a6dSdrh #define TIMER_END 529bcbdad2Sshane #define TIMER_ELAPSED ((sqlite_uint64)0) 53bbd42a6dSdrh #endif 54bbd42a6dSdrh 55bbd42a6dSdrh /* 56bbd42a6dSdrh ** If we compile with the SQLITE_TEST macro set, then the following block 57bbd42a6dSdrh ** of code will give us the ability to simulate a disk I/O error. This 58bbd42a6dSdrh ** is used for testing the I/O recovery logic. 59bbd42a6dSdrh */ 60*c04c54b8Smistachkin #if defined(SQLITE_TEST) 61*c04c54b8Smistachkin extern int sqlite3_io_error_hit; 62*c04c54b8Smistachkin extern int sqlite3_io_error_hardhit; 63*c04c54b8Smistachkin extern int sqlite3_io_error_pending; 64*c04c54b8Smistachkin extern int sqlite3_io_error_persist; 65*c04c54b8Smistachkin extern int sqlite3_io_error_benign; 66*c04c54b8Smistachkin extern int sqlite3_diskfull_pending; 67*c04c54b8Smistachkin extern int sqlite3_diskfull; 681aa5af11Sdrh #define SimulateIOErrorBenign(X) sqlite3_io_error_benign=(X) 695968593bSdrh #define SimulateIOError(CODE) \ 701aa5af11Sdrh if( (sqlite3_io_error_persist && sqlite3_io_error_hit) \ 711aa5af11Sdrh || sqlite3_io_error_pending-- == 1 ) \ 72d5eb79ebSdrh { local_ioerr(); CODE; } local_ioerr()73bbd42a6dSdrhstatic void local_ioerr(){ 74538f570cSdrh IOTRACE(("IOERR\n")); 751aa5af11Sdrh sqlite3_io_error_hit++; 761aa5af11Sdrh if( !sqlite3_io_error_benign ) sqlite3_io_error_hardhit++; 77bbd42a6dSdrh } 785968593bSdrh #define SimulateDiskfullError(CODE) \ 79f307a4aaSdrh if( sqlite3_diskfull_pending ){ \ 80f307a4aaSdrh if( sqlite3_diskfull_pending == 1 ){ \ 81f307a4aaSdrh local_ioerr(); \ 82f307a4aaSdrh sqlite3_diskfull = 1; \ 83a7aea3ddSdrh sqlite3_io_error_hit = 1; \ 845968593bSdrh CODE; \ 85f307a4aaSdrh }else{ \ 86f307a4aaSdrh sqlite3_diskfull_pending--; \ 87f307a4aaSdrh } \ 88f307a4aaSdrh } 89bbd42a6dSdrh #else 901aa5af11Sdrh #define SimulateIOErrorBenign(X) 91bbd42a6dSdrh #define SimulateIOError(A) 924fc93083Sadamd #define SimulateDiskfullError(A) 93*c04c54b8Smistachkin #endif /* defined(SQLITE_TEST) */ 94bbd42a6dSdrh 95bbd42a6dSdrh /* 96bbd42a6dSdrh ** When testing, keep a count of the number of open files. 97bbd42a6dSdrh */ 98*c04c54b8Smistachkin #if defined(SQLITE_TEST) 99*c04c54b8Smistachkin extern int sqlite3_open_file_count; 100bbd42a6dSdrh #define OpenCounter(X) sqlite3_open_file_count+=(X) 101bbd42a6dSdrh #else 102bbd42a6dSdrh #define OpenCounter(X) 103*c04c54b8Smistachkin #endif /* defined(SQLITE_TEST) */ 1049bcbdad2Sshane 1059bcbdad2Sshane #endif /* !defined(_OS_COMMON_H_) */ 106