summaryrefslogtreecommitdiff
path: root/db/dur.h
blob: c139bedb59aadb09d41ee4e7a31a577ed6ce32ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// @file dur.h durability support

#pragma once

#include "diskloc.h"

namespace mongo { 

    namespace dur { 

        /** call writing...() to declare "i'm about to write to x and it should be logged for redo." 
            
            failure to call writing...() is checked in _DEBUG mode by using a read only mapped view
            (i.e., you'll segfault if you don't...)
        */


#if !defined(_DURABLE)

        inline void* writingPtr(void *x, size_t len) { return x; }
        inline DiskLoc& writingDiskLoc(DiskLoc& d) { return d; }
        inline int& writingInt(int& d) { return d; }
        template <typename T> inline T* writing(T *x) { return x; }
        inline void assertReading(void *p) { }
        inline void assertWriting(void *p) { }

#else

        void* writingPtr(void *x, size_t len);

        inline DiskLoc& writingDiskLoc(DiskLoc& d) {
#if defined(_DEBUG)
            return *((DiskLoc*) writingPtr(&d, sizeof(d)));
#else
            return d;
#endif
        }

        inline int& writingInt(int& d) {
#if defined(_DEBUG)
            return *((int*) writingPtr(&d, sizeof(d)));
#else
            return d;
#endif
        }

        template <typename T> 
        inline 
        T* writing(T *x) { 
#if defined(_DEBUG)
            return (T*) writingPtr(x, sizeof(T));
#else
            return x;
#endif
        }

        void assertReading(void *p);
        void assertWriting(void *p);

#endif

    }

    inline DiskLoc& DiskLoc::writing() { 
        return dur::writingDiskLoc(*this);
    }

}