[go: up one dir, main page]

Menu

[408bb9]: / common / debug.h  Maximize  Restore  History

Download this file

173 lines (158 with data), 3.8 kB

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef HEADER_STXXL_DEBUG
#define HEADER_STXXL_DEBUG
/***************************************************************************
* debug.h
*
* Thu Dec 30 14:52:00 2004
* Copyright 2004 Roman Dementiev
* Email dementiev@ira.uka.de
****************************************************************************/
#include "../common/utils.h"
#include "../common/mutex.h"
#include <map>
#include <ext/hash_map>
__STXXL_BEGIN_NAMESPACE
class debugmon
{
struct tag
{
bool ongoing;
char * end;
size_t size;
};
struct hash_fct
{
size_t operator () (char * arg) const
{
return long(arg);
}
};
struct eqt
{
bool operator () (char * arg1, char * arg2) const
{
return arg1 == arg2;
}
};
__gnu_cxx::hash_map<char *, tag, hash_fct, eqt > tags;
#ifdef STXXL_BOOST_THREADS
boost::mutex mutex1;
#else
mutex mutex1;
#endif
static debugmon * instance;
debugmon() {}
public:
#ifndef STXXL_DEBUGMON
void block_allocated(char * ptr, char * end, size_t size)
{
}
void block_deallocated(char * ptr)
{
}
void io_started(char * ptr)
{
}
void io_finished(char * ptr)
{
}
#else
void block_allocated(char * ptr, char * end, size_t size)
{
#ifdef STXXL_BOOST_THREADS
boost::mutex::scoped_lock Lock(mutex1);
#else
mutex1.lock();
#endif
// checks are here
STXXL_VERBOSE1("debugmon: block "<<long(ptr)<<" allocated")
assert(tags.find(ptr) == tags.end()); // not allocated
tag t;
t.ongoing = false;
t.end = end;
t.size = size;
tags[ptr] = t;
#ifndef STXXL_BOOST_THREADS
mutex1.unlock();
#endif
}
void block_deallocated(char * ptr)
{
#ifdef STXXL_BOOST_THREADS
boost::mutex::scoped_lock Lock(mutex1);
#else
mutex1.lock();
#endif
STXXL_VERBOSE1("debugmon: block_deallocated from "<<long(ptr))
assert(tags.find(ptr) != tags.end()); // allocated
tag t = tags[ptr];
assert(t.ongoing == false); // not ongoing
tags.erase(ptr);
size_t size = t.size;
STXXL_VERBOSE1("debugmon: block_deallocated to "<<long(t.end))
char * endptr =(char *) t.end;
char * ptr1 = (char *) ptr;
ptr1 += size;
while(ptr1 < endptr)
{
STXXL_VERBOSE1("debugmon: block_deallocated next "<<long(ptr1))
assert(tags.find(ptr1) != tags.end()); // allocated
tag t = tags[ptr1];
assert(t.ongoing == false); // not ongoing
assert(t.size == size); // chunk size
assert(t.end == endptr); // array end address
tags.erase(ptr1);
ptr1 += size;
}
#ifndef STXXL_BOOST_THREADS
mutex1.unlock();
#endif
}
void io_started(char * ptr)
{
#ifdef STXXL_BOOST_THREADS
boost::mutex::scoped_lock Lock(mutex1);
#else
mutex1.lock();
#endif
STXXL_VERBOSE1("debugmon: I/O on block "<<long(ptr)<<" started")
assert(tags.find(ptr) != tags.end()); // allocated
tag t = tags[ptr];
//assert(t. false); // not ongoing
if(t.ongoing == true)
STXXL_ERRMSG("debugmon: I/O on block "<<long(ptr)<<" started, but block is already busy")
t.ongoing = true;
tags[ptr] = t;
#ifndef STXXL_BOOST_THREADS
mutex1.unlock();
#endif
}
void io_finished(char * ptr)
{
#ifdef STXXL_BOOST_THREADS
boost::mutex::scoped_lock Lock(mutex1);
#else
mutex1.lock();
#endif
STXXL_VERBOSE1("debugmon: I/O on block "<<long(ptr)<<" finished")
assert(tags.find(ptr) != tags.end()); // allocated
tag t = tags[ptr];
//assert(t. true); // ongoing
if(t.ongoing == false)
STXXL_ERRMSG("debugmon: I/O on block "<<long(ptr)<<" finished, but block was not busy")
t.ongoing = false;
tags[ptr] = t;
#ifndef STXXL_BOOST_THREADS
mutex1.unlock();
#endif
}
#endif
static debugmon *get_instance ()
{
if (!instance)
instance = new debugmon ();
return instance;
}
};
__STXXL_END_NAMESPACE
#endif