[go: up one dir, main page]

Menu

[e222c1]: / common / debug.cpp  Maximize  Restore  History

Download this file

120 lines (108 with data), 2.9 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
#include "debug.h"
__STXXL_BEGIN_NAMESPACE
debugmon * debugmon::instance = NULL;
#ifndef STXXL_DEBUGMON
void debugmon::block_allocated(char * ptr, char * end, size_t size)
{
}
void debugmon::block_deallocated(char * ptr)
{
}
void debugmon::io_started(char * ptr)
{
}
void debugmon::io_finished(char * ptr)
{
}
#else
void debugmon::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 debugmon::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 debugmon::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 debugmon::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
__STXXL_END_NAMESPACE