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

libcwd/macro_ForAllDebugObjects.h

Go to the documentation of this file.
00001 // $Header: /cvsroot/libcwd/libcwd/include/libcwd/macro_ForAllDebugObjects.h,v 1.7 2004/07/14 00:29:35 libcw Exp $
00002 //
00003 // Copyright (C) 2000 - 2004, by
00004 // 
00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
00008 //
00009 // This file may be distributed under the terms of the Q Public License
00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
00011 // packaging of this file.
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 // Macro ForAllDebugObjects
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 inline
00057 debug_objects_ct::container_type&
00058 debug_objects_ct::write_locked(void)
00059 {
00060 #if CWDEBUG_DEBUG
00061   LIBCWD_ASSERT( WNS_debug_objects );
00062 #endif
00063   return *WNS_debug_objects;
00064 }
00065 
00066 inline
00067 debug_objects_ct::container_type const&
00068 debug_objects_ct::read_locked(void) const
00069 {
00070 #if CWDEBUG_DEBUG
00071   LIBCWD_ASSERT( WNS_debug_objects );
00072 #endif
00073   return *WNS_debug_objects;
00074 }
00075 
00076 extern debug_objects_ct debug_objects;
00077 
00078   } // namespace _private_
00079 } // namespace libcwd
00080 
00081 #if LIBCWD_THREAD_SAFE
00082 #if CWDEBUG_DEBUGT
00083 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
00084 #else
00085 #define LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION
00086 #endif
00087 #define LIBCWD_ForAllDebugObjects_LOCK \
00088     LIBCWD_ForAllDebugObjects_LOCK_TSD_DECLARATION; \
00089     LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::cleanup, NULL); \
00090     ::libcwd::_private_::debug_objects.init_and_rdlock()
00091 #define LIBCWD_ForAllDebugObjects_UNLOCK \
00092     ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_objects_instance>::rdunlock(); \
00093     LIBCWD_CLEANUP_POP_RESTORE(false);
00094 #else // !LIBCWD_THREAD_SAFE
00095 #define LIBCWD_ForAllDebugObjects_LOCK ::libcwd::_private_::debug_objects.init(LIBCWD_TSD)
00096 #define LIBCWD_ForAllDebugObjects_UNLOCK
00097 #endif // !LIBCWD_THREAD_SAFE
00098 
00099 #define LibcwdForAllDebugObjects(dc_namespace, STATEMENT...) \
00100        do { \
00101          LIBCWD_ForAllDebugObjects_LOCK; \
00102          for( ::libcwd::_private_::debug_objects_ct::container_type::\
00103              const_iterator __libcwd_i(::libcwd::_private_::debug_objects.read_locked().begin());\
00104              __libcwd_i != ::libcwd::_private_::debug_objects.read_locked().end(); ++__libcwd_i) \
00105          { \
00106            using namespace ::libcwd; \
00107            using namespace dc_namespace; \
00108            ::libcwd::debug_ct& debugObject(*(*__libcwd_i)); \
00109            { STATEMENT; } \
00110          } \
00111          LIBCWD_ForAllDebugObjects_UNLOCK \
00112        } \
00113        while(0)
00114 
00115 #endif // LIBCWD_MACRO_FORALLDEBUGOBJECTS_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.