blob: 70d0dd9d9e454f7041893817cf04c89194ac9c6b [file] [log] [blame]
drhbbd42a62004-05-22 17:41:58 +00001/*
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#if 0
27static int last_page = 0;
28__inline__ unsigned long long int hwtime(void){
29 unsigned long long int x;
30 __asm__("rdtsc\n\t"
31 "mov %%edx, %%ecx\n\t"
32 :"=A" (x));
33 return x;
34}
35static unsigned long long int g_start;
36static unsigned int elapse;
37#define TIMER_START g_start=hwtime()
38#define TIMER_END elapse=hwtime()-g_start
39#define SEEK(X) last_page=(X)
40#define TRACE1(X) fprintf(stderr,X)
41#define TRACE2(X,Y) fprintf(stderr,X,Y)
42#define TRACE3(X,Y,Z) fprintf(stderr,X,Y,Z)
43#define TRACE4(X,Y,Z,A) fprintf(stderr,X,Y,Z,A)
44#define TRACE5(X,Y,Z,A,B) fprintf(stderr,X,Y,Z,A,B)
45#else
46#define TIMER_START
47#define TIMER_END
48#define SEEK(X)
49#define TRACE1(X)
50#define TRACE2(X,Y)
51#define TRACE3(X,Y,Z)
52#define TRACE4(X,Y,Z,A)
53#define TRACE5(X,Y,Z,A,B)
54#endif
55
56
57/*
58** If we compile with the SQLITE_TEST macro set, then the following block
59** of code will give us the ability to simulate a disk I/O error. This
60** is used for testing the I/O recovery logic.
61*/
62#ifdef SQLITE_TEST
63int sqlite3_io_error_pending = 0;
64#define SimulateIOError(A) \
65 if( sqlite3_io_error_pending ) \
66 if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
67static void local_ioerr(){
68 sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */
69}
70#else
71#define SimulateIOError(A)
72#endif
73
74/*
75** When testing, keep a count of the number of open files.
76*/
77#ifdef SQLITE_TEST
78int sqlite3_open_file_count = 0;
79#define OpenCounter(X) sqlite3_open_file_count+=(X)
80#else
81#define OpenCounter(X)
82#endif