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

macro_ForAllDebugChannels.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_FORALLDEBUGCHANNELS_H
19 #define LIBCWD_MACRO_FORALLDEBUGCHANNELS_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include <libcwd/config.h>
23 #endif
24 #ifndef LIBCWD_PRIVATE_ASSERT_H
25 #include <libcwd/private_assert.h>
26 #endif
27 #ifndef LIBCWD_PRIVATE_INTERNAL_VECTOR_H
29 #endif
30 
31 //===================================================================================================
32 // Macro ForAllDebugChannels
33 //
34 
35 namespace libcwd {
36 
37  class channel_ct;
38 
39  namespace _private_ {
40 
41 class debug_channels_ct {
42 public:
43  typedef internal_vector<channel_ct*> container_type;
44  container_type* WNS_debug_channels;
45 public:
46  void init(LIBCWD_TSD_PARAM);
47 #if LIBCWD_THREAD_SAFE
48  void init_and_rdlock(void);
49 #endif
50  container_type& write_locked(void);
51  container_type const& read_locked(void) const;
52 };
53 
54 inline
55 debug_channels_ct::container_type&
56 debug_channels_ct::write_locked(void)
57 {
58 #if CWDEBUG_DEBUG
59  LIBCWD_ASSERT( WNS_debug_channels );
60 #endif
61  return *WNS_debug_channels;
62 }
63 
64 inline
65 debug_channels_ct::container_type const&
66 debug_channels_ct::read_locked(void) const
67 {
68 #if CWDEBUG_DEBUG
69  LIBCWD_ASSERT( WNS_debug_channels );
70 #endif
71  return *WNS_debug_channels;
72 }
73 
74 extern debug_channels_ct debug_channels;
75 
76  } // namespace _private_
77 } // namespace libcwd
78 
79 #if LIBCWD_THREAD_SAFE
80 #if CWDEBUG_DEBUGT
81 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
82 #else
83 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION
84 #endif
85 #define LIBCWD_ForAllDebugChannels_LOCK \
86  LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION; \
87  LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::cleanup, NULL); \
88  ::libcwd::_private_::debug_channels.init_and_rdlock()
89 #define LIBCWD_ForAllDebugChannels_UNLOCK \
90  ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::rdunlock(); \
91  LIBCWD_CLEANUP_POP_RESTORE(false);
92 #else // !LIBCWD_THREAD_SAFE
93 #define LIBCWD_ForAllDebugChannels_LOCK ::libcwd::_private_::debug_channels.init(LIBCWD_TSD)
94 #define LIBCWD_ForAllDebugChannels_UNLOCK
95 #endif // !LIBCWD_THREAD_SAFE
96 
97 #define LibcwdForAllDebugChannels(dc_namespace, STATEMENT...) \
98  do { \
99  LIBCWD_ForAllDebugChannels_LOCK; \
100  for( ::libcwd::_private_::debug_channels_ct::container_type::\
101  const_iterator __libcwd_i(::libcwd::_private_::debug_channels.read_locked().begin());\
102  __libcwd_i != ::libcwd::_private_::debug_channels.read_locked().end(); ++__libcwd_i) \
103  { \
104  using namespace ::libcwd; \
105  using namespace dc_namespace; \
106  ::libcwd::channel_ct& debugChannel(*(*__libcwd_i)); \
107  { STATEMENT; } \
108  } \
109  LIBCWD_ForAllDebugChannels_UNLOCK \
110  } \
111  while(0)
112 
113 #endif // LIBCWD_MACRO_FORALLDEBUGCHANNELS_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.