xref: /sqlite-3.40.0/src/os_common.h (revision ef5ecb41)
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 
21 
22 /*
23 ** Macros for performance tracing.  Normally turned off.  Only works
24 ** on i486 hardware.
25 */
26 int sqlite3_os_trace = 0;
27 #if 1
28 static int last_page = 0;
29 __inline__ unsigned long long int hwtime(void){
30   unsigned long long int x;
31   __asm__("rdtsc\n\t"
32           "mov %%edx, %%ecx\n\t"
33           :"=A" (x));
34   return x;
35 }
36 static unsigned long long int g_start;
37 static unsigned int elapse;
38 #define TIMER_START       g_start=hwtime()
39 #define TIMER_END         elapse=hwtime()-g_start
40 #define SEEK(X)           last_page=(X)
41 #define TRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
42 #define TRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
43 #define TRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
44 #define TRACE4(X,Y,Z,A)   if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
45 #define TRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
46 #define TRACE6(X,Y,Z,A,B,C) if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
47 #else
48 #define TIMER_START
49 #define TIMER_END
50 #define SEEK(X)
51 #define TRACE1(X)
52 #define TRACE2(X,Y)
53 #define TRACE3(X,Y,Z)
54 #define TRACE4(X,Y,Z,A)
55 #define TRACE5(X,Y,Z,A,B)
56 #define TRACE6(X,Y,Z,A,B,C)
57 #endif
58 
59 
60 /*
61 ** If we compile with the SQLITE_TEST macro set, then the following block
62 ** of code will give us the ability to simulate a disk I/O error.  This
63 ** is used for testing the I/O recovery logic.
64 */
65 #ifdef SQLITE_TEST
66 int sqlite3_io_error_pending = 0;
67 #define SimulateIOError(A)  \
68    if( sqlite3_io_error_pending ) \
69      if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
70 static void local_ioerr(){
71   sqlite3_io_error_pending = 0;  /* Really just a place to set a breakpoint */
72 }
73 #else
74 #define SimulateIOError(A)
75 #endif
76 
77 /*
78 ** When testing, keep a count of the number of open files.
79 */
80 #ifdef SQLITE_TEST
81 int sqlite3_open_file_count = 0;
82 #define OpenCounter(X)  sqlite3_open_file_count+=(X)
83 #else
84 #define OpenCounter(X)
85 #endif
86