00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef LIBCWD_MACRO_FORALLDEBUGCHANNELS_H
00019 #define LIBCWD_MACRO_FORALLDEBUGCHANNELS_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 channel_ct;
00038
00039 namespace _private_ {
00040
00041 class debug_channels_ct {
00042 public:
00043 typedef internal_vector<channel_ct*> container_type;
00044 container_type* WNS_debug_channels;
00045 public:
00046 void init(LIBCWD_TSD_PARAM);
00047 #if LIBCWD_THREAD_SAFE
00048 void init_and_rdlock(void);
00049 #endif
00050 container_type& write_locked(void);
00051 container_type const& read_locked(void) const;
00052 };
00053
00054 inline
00055 debug_channels_ct::container_type&
00056 debug_channels_ct::write_locked(void)
00057 {
00058 #if CWDEBUG_DEBUG
00059 LIBCWD_ASSERT( WNS_debug_channels );
00060 #endif
00061 return *WNS_debug_channels;
00062 }
00063
00064 inline
00065 debug_channels_ct::container_type const&
00066 debug_channels_ct::read_locked(void) const
00067 {
00068 #if CWDEBUG_DEBUG
00069 LIBCWD_ASSERT( WNS_debug_channels );
00070 #endif
00071 return *WNS_debug_channels;
00072 }
00073
00074 extern debug_channels_ct debug_channels;
00075
00076 }
00077 }
00078
00079 #if LIBCWD_THREAD_SAFE
00080 #if CWDEBUG_DEBUGT
00081 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
00082 #else
00083 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION
00084 #endif
00085 #define LIBCWD_ForAllDebugChannels_LOCK \
00086 LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION; \
00087 LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::cleanup, NULL); \
00088 ::libcwd::_private_::debug_channels.init_and_rdlock()
00089 #define LIBCWD_ForAllDebugChannels_UNLOCK \
00090 ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::rdunlock(); \
00091 LIBCWD_CLEANUP_POP_RESTORE(false);
00092 #else // !LIBCWD_THREAD_SAFE
00093 #define LIBCWD_ForAllDebugChannels_LOCK ::libcwd::_private_::debug_channels.init(LIBCWD_TSD)
00094 #define LIBCWD_ForAllDebugChannels_UNLOCK
00095 #endif // !LIBCWD_THREAD_SAFE
00096
00097 #define LibcwdForAllDebugChannels(dc_namespace, STATEMENT...) \
00098 do { \
00099 LIBCWD_ForAllDebugChannels_LOCK; \
00100 for( ::libcwd::_private_::debug_channels_ct::container_type::\
00101 const_iterator __libcwd_i(::libcwd::_private_::debug_channels.read_locked().begin());\
00102 __libcwd_i != ::libcwd::_private_::debug_channels.read_locked().end(); ++__libcwd_i) \
00103 { \
00104 using namespace ::libcwd; \
00105 using namespace dc_namespace; \
00106 ::libcwd::channel_ct& debugChannel(*(*__libcwd_i)); \
00107 { STATEMENT; } \
00108 } \
00109 LIBCWD_ForAllDebugChannels_UNLOCK \
00110 } \
00111 while(0)
00112
00113 #endif // LIBCWD_MACRO_FORALLDEBUGCHANNELS_H