Stxxl  1.2.1
debug.h
1 /***************************************************************************
2  * include/stxxl/bits/common/debug.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2004 Roman Dementiev <dementiev@ira.uka.de>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_DEBUG_HEADER
14 #define STXXL_DEBUG_HEADER
15 
16 #ifdef STXXL_BOOST_CONFIG
17  #include <boost/config.hpp>
18 #endif
19 
20 #include <stxxl/bits/namespace.h>
21 #include <stxxl/bits/singleton.h>
22 #include <stxxl/bits/common/mutex.h>
23 #include <stxxl/bits/compat_hash_map.h>
24 
25 
26 __STXXL_BEGIN_NAMESPACE
27 
28 #ifdef STXXL_DEBUGMON
29  #define STXXL_DEBUGMON_DO(action) debugmon::get_instance()->action
30 #else
31  #define STXXL_DEBUGMON_DO(action)
32 #endif
33 
34 class debugmon : public singleton<debugmon>
35 {
36  friend class singleton<debugmon>;
37 
38 #ifdef STXXL_DEBUGMON
39 
40  struct tag
41  {
42  bool ongoing;
43  char * end;
44  size_t size;
45  };
46  struct hash_fct
47  {
48  inline size_t operator () (char * arg) const
49  {
50  return long(arg);
51  }
52 #ifdef BOOST_MSVC
53  bool operator () (char * a, char * b) const
54  {
55  return (long(a) < long(b));
56  }
57  enum
58  { // parameters for hash table
59  bucket_size = 4, // 0 < bucket_size
60  min_buckets = 8 // min_buckets = 2 ^^ N, 0 < N
61  };
62 #endif
63  };
64 
65  compat_hash_map<char *, tag, hash_fct>::result tags;
66 
67  mutex mutex1;
68 
69 #endif // #ifdef STXXL_DEBUGMON
70 
71 public:
72  void block_allocated(char * ptr, char * end, size_t size);
73  void block_deallocated(char * ptr);
74  void io_started(char * ptr);
75  void io_finished(char * ptr);
76 };
77 
78 __STXXL_END_NAMESPACE
79 
80 #endif // !STXXL_DEBUG_HEADER