Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

macro_ForAllDebugObjects.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
19 #define LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include "config.h"
23 #endif
24 #ifndef LIBCWD_PRIVATE_ASSERT_H
25 #include "private_assert.h"
26 #endif
27 #ifndef LIBCWD_PRIVATE_INTERNAL_VECTOR_H
29 #endif
30 
31 //===================================================================================================
32 // Macro ForAllDebugObjects
33 //
34 
35 namespace libcwd {
36 
37  class debug_ct;
38 
39  namespace _private_ {
40 
41 class debug_objects_ct {
42 public:
43  typedef internal_vector<debug_ct*> container_type;
44 private:
45  container_type* WNS_debug_objects;
46 public:
47  void init(LIBCWD_TSD_PARAM);
48 #if LIBCWD_THREAD_SAFE
49  void init_and_rdlock();
50 #endif
51  void ST_uninit();
52  container_type& write_locked();
53  container_type const& read_locked() const;
54 
55  // debug_objects is a global object. If it is destructed then in principle
56  // all other global objects could already have been destructed, including
57  // debug_ct objects. Therefore, destructing the container with with pointers
58  // to the debug objects isn't wrong: accessing it (by using the macro
59  // ForAllDebugObjects) is wrong. Call ST_uninit to delete WNS_debug_objects.
60  ~debug_objects_ct() { ST_uninit(); }
61 };
62 
63 inline
64 debug_objects_ct::container_type&
65 debug_objects_ct::write_locked()
66 {
67 #if CWDEBUG_DEBUG
68  LIBCWD_ASSERT( WNS_debug_objects );
69 #endif
70  return *WNS_debug_objects;
71 }
72 
73 inline
74 debug_objects_ct::container_type const&
75 debug_objects_ct::read_locked() const
76 {
77 #if CWDEBUG_DEBUG
78  LIBCWD_ASSERT( WNS_debug_objects );
79 #endif
80  return *WNS_debug_objects;
81 }
82 
83 extern debug_objects_ct debug_objects;
84 
85  } // namespace _private_
86 } // namespace libcwd
87 
88 #if LIBCWD_THREAD_SAFE
89 #if CWDEBUG_DEBUGT
90 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
91 #else
92 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION
93 #endif
94 #define LIBCWD_ForAllDebugObjects_LOCK \
95  LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION; \
96  LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::cleanup, NULL); \
97  ::libcwd::_private_::debug_objects.init_and_rdlock()
98 #define LIBCWD_ForAllDebugObjects_UNLOCK \
99  ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::rdunlock(); \
100  LIBCWD_CLEANUP_POP_RESTORE(false);
101 #else // !LIBCWD_THREAD_SAFE
102 #define LIBCWD_ForAllDebugObjects_LOCK ::libcwd::_private_::debug_objects.init(LIBCWD_TSD)
103 #define LIBCWD_ForAllDebugObjects_UNLOCK
104 #endif // !LIBCWD_THREAD_SAFE
105 
106 #define LibcwdForAllDebugObjects(dc_namespace, STATEMENT...) \
107  do { \
108  LIBCWD_ForAllDebugObjects_LOCK; \
109  for( ::libcwd::_private_::debug_objects_ct::container_type::\
110  const_iterator __libcwd_i(::libcwd::_private_::debug_objects.read_locked().begin());\
111  __libcwd_i != ::libcwd::_private_::debug_objects.read_locked().end(); ++__libcwd_i) \
112  { \
113  using namespace ::libcwd; \
114  using namespace dc_namespace; \
115  ::libcwd::debug_ct& debugObject(*(*__libcwd_i)); \
116  { STATEMENT; } \
117  } \
118  LIBCWD_ForAllDebugObjects_UNLOCK \
119  } \
120  while(0)
121 
122 #endif // LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
namespace for libcwd.
Definition: debug.cc:87
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.