00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
00019 #define LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
00020
00021 #ifndef LIBCWD_CONFIG_H
00022 #include <libcwd/config.h>
00023 #endif
00024 #ifndef LIBCWD_PRIVATE_ASSERT_H
00025 #include <libcwd/private_assert.h>
00026 #endif
00027 #ifndef LIBCWD_PRIVATE_INTERNAL_VECTOR_H
00028 #include <libcwd/private_internal_vector.h>
00029 #endif
00030
00031
00032
00033
00034
00035 namespace libcwd {
00036
00037 class debug_ct;
00038
00039 namespace _private_ {
00040
00041 class debug_objects_ct {
00042 public:
00043 typedef internal_vector<debug_ct*> container_type;
00044 private:
00045 container_type* WNS_debug_objects;
00046 public:
00047 void init(LIBCWD_TSD_PARAM);
00048 #if LIBCWD_THREAD_SAFE
00049 void init_and_rdlock(void);
00050 #endif
00051 void ST_uninit(void);
00052 container_type& write_locked(void);
00053 container_type const& read_locked(void) const;
00054
00055
00056
00057
00058
00059
00060 ~debug_objects_ct() { ST_uninit(); }
00061 };
00062
00063 inline
00064 debug_objects_ct::container_type&
00065 debug_objects_ct::write_locked(void)
00066 {
00067 #if CWDEBUG_DEBUG
00068 LIBCWD_ASSERT( WNS_debug_objects );
00069 #endif
00070 return *WNS_debug_objects;
00071 }
00072
00073 inline
00074 debug_objects_ct::container_type const&
00075 debug_objects_ct::read_locked(void) const
00076 {
00077 #if CWDEBUG_DEBUG
00078 LIBCWD_ASSERT( WNS_debug_objects );
00079 #endif
00080 return *WNS_debug_objects;
00081 }
00082
00083 extern debug_objects_ct debug_objects;
00084
00085 }
00086 }
00087
00088 #if LIBCWD_THREAD_SAFE
00089 #if CWDEBUG_DEBUGT
00090 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
00091 #else
00092 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION
00093 #endif
00094 #define LIBCWD_ForAllDebugObjects_LOCK \
00095 LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION; \
00096 LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::cleanup, NULL); \
00097 ::libcwd::_private_::debug_objects.init_and_rdlock()
00098 #define LIBCWD_ForAllDebugObjects_UNLOCK \
00099 ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::rdunlock(); \
00100 LIBCWD_CLEANUP_POP_RESTORE(false);
00101 #else // !LIBCWD_THREAD_SAFE
00102 #define LIBCWD_ForAllDebugObjects_LOCK ::libcwd::_private_::debug_objects.init(LIBCWD_TSD)
00103 #define LIBCWD_ForAllDebugObjects_UNLOCK
00104 #endif // !LIBCWD_THREAD_SAFE
00105
00106 #define LibcwdForAllDebugObjects(dc_namespace, STATEMENT...) \
00107 do { \
00108 LIBCWD_ForAllDebugObjects_LOCK; \
00109 for( ::libcwd::_private_::debug_objects_ct::container_type::\
00110 const_iterator __libcwd_i(::libcwd::_private_::debug_objects.read_locked().begin());\
00111 __libcwd_i != ::libcwd::_private_::debug_objects.read_locked().end(); ++__libcwd_i) \
00112 { \
00113 using namespace ::libcwd; \
00114 using namespace dc_namespace; \
00115 ::libcwd::debug_ct& debugObject(*(*__libcwd_i)); \
00116 { STATEMENT; } \
00117 } \
00118 LIBCWD_ForAllDebugObjects_UNLOCK \
00119 } \
00120 while(0)
00121
00122 #endif // LIBCWD_MACRO_FORALLDEBUGOBJECTS_H