Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-11-05 04:42:56


Author: jtorjo
Date: 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
New Revision: 40772
URL: http://svn.boost.org/trac/boost/changeset/40772

Log:
[logging]
v0.10.8, 3 nov 2007
- added TSS tests
  - test test_ts_resource_with_cache SUCCESSFUL on win32, vs2005
  - test test_tss SUCCESSFUL on win32, vs2005
  - test test_simple_tss SUCCESSFUL on win32, vs2005

Text files modified:
   sandbox/logging/boost/logging/detail/format_write_detail.hpp | 4
   sandbox/logging/boost/logging/detail/manipulator.hpp | 4
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 1
   sandbox/logging/boost/logging/detail/raw_doc/old_examples.hpp | 2
   sandbox/logging/boost/logging/detail/raw_doc/workflow.hpp | 2
   sandbox/logging/boost/logging/detail/ts/ts_resource.hpp | 36 ++++++++----
   sandbox/logging/boost/logging/format.hpp | 8 +-
   sandbox/logging/boost/logging/format/formatter/defaults.hpp | 12 ++--
   sandbox/logging/lib/logging/samples/basic_usage/log.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp | 6 +-
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp | 6 +-
   sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp | 10 +-
   sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp | 2
   sandbox/logging/lib/logging/tests/do_not_use/format/test_manip_w_msgroute.cpp | 8 +-
   sandbox/logging/lib/logging/tests/do_not_use/format/test_simple_formatter.cpp | 6 +-
   sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp | 2
   sandbox/logging/lib/logging/tests/test_ts_resouce_with_cache/test_ts_resource.cpp | 110 +++++++++++++++++++++++++++++++++------
   19 files changed, 155 insertions(+), 70 deletions(-)

Modified: sandbox/logging/boost/logging/detail/format_write_detail.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/format_write_detail.hpp (original)
+++ sandbox/logging/boost/logging/detail/format_write_detail.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -71,7 +71,7 @@
 // add formatters : [idx] [time] message [enter]
 g_l->writer().add_formatter( formatter::idx() );
 g_l->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
-g_l->writer().add_formatter( formatter::append_enter() );
+g_l->writer().add_formatter( formatter::append_newline() );
 
 // write to cout and file
 g_l->writer().add_destination( destination::cout() );
@@ -82,7 +82,7 @@
 L_ << "testing " << i << i+1 << i+2;
 @endcode
 
-In the above case, @c formatter::idx() is called, then @c formatter::time(), then @c formatter::append_enter(). Now, the destinations are called:
+In the above case, @c formatter::idx() is called, then @c formatter::time(), then @c formatter::append_newline(). Now, the destinations are called:
 @c destinatino::cout(), and then @c destination::file().
 
 Most of the time this is ok, and this is what the @ref msg_route::simple "default router" does. However, there are other routers

Modified: sandbox/logging/boost/logging/detail/manipulator.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/manipulator.hpp (original)
+++ sandbox/logging/boost/logging/detail/manipulator.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -165,7 +165,7 @@
 // add formatters : [idx] [time] message [enter]
 g_l->writer().add_formatter( formatter::idx() );
 g_l->writer().add_formatter( formatter::time() );
-g_l->writer().add_formatter( formatter::append_enter() );
+g_l->writer().add_formatter( formatter::append_newline() );
 
 // write to cout and file
 g_l->writer().add_destination( destination::cout() );
@@ -191,7 +191,7 @@
 You can use the formatter and/or destination classes that come with the library:
 - formatters: in the formatter namespace. Here are a few examples:
   - formatter::idx - prepends an index
- - formatter::append_enter - appends an enter after the message
+ - formatter::append_newline - appends an enter after the message
   - formatter::time - prepends the time
   - formatter::thread_id - prepends the current thread id
 - destinations: in the destination namespace

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -2,6 +2,7 @@
 @page page_changelog Changelog
 
 v0.10.7, 3 nov 2007
+- append_enter -> append_newline
 - finalized tss_resouce_with_cache
 - added TSS tests
   - test test_ts_resource_with_cache - not tested

Modified: sandbox/logging/boost/logging/detail/raw_doc/old_examples.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/old_examples.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/old_examples.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -92,7 +92,7 @@
     // add formatters : [idx] [time] message [enter]
     g_l->writer().add_formatter( write_idx() );
     g_l->writer().add_formatter( write_time() );
- g_l->writer().add_formatter( append_enter() );
+ g_l->writer().add_formatter( append_newline() );
 
     // write to cout and file
     g_l->writer().add_destination( write_to_cout() );

Modified: sandbox/logging/boost/logging/detail/raw_doc/workflow.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/workflow.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/workflow.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -163,7 +163,7 @@
 // add formatters : [idx] [time] message <enter>
 g_l->writer().add_formatter( formatter::idx() );
 g_l->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
-g_l->writer().add_formatter( formatter::append_enter() );
+g_l->writer().add_formatter( formatter::append_newline() );
 // add destinations : console, output debug window, and a file called "out.txt"
 g_l->writer().add_destination( destination::cout() );
 g_l->writer().add_destination( destination::dbg_window() );

Modified: sandbox/logging/boost/logging/detail/ts/ts_resource.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/ts/ts_resource.hpp (original)
+++ sandbox/logging/boost/logging/detail/ts/ts_resource.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -24,6 +24,7 @@
 #include <boost/logging/detail/ts/ts.hpp>
 #include <boost/logging/detail/tss/tss.hpp>
 #include <time.h>
+#include <boost/assert.hpp>
 
 namespace boost { namespace logging {
     
@@ -87,11 +88,10 @@
 
         struct read {
             const self_type & self ;
- read(const self_type & self) : self(self) {
- self.m_cs.Lock();
+ typename mutex::scoped_lock locker;
+ read(const self_type & self) : self(self), locker(self.m_cs) {
             }
             ~read() {
- self.m_cs.Unlock();
             }
 
             const type & use() { return self.m_val ; }
@@ -121,11 +121,12 @@
 
     private:
         struct value_and_time {
- value_and_time(const type & val = type() ) : val(val) {
- time_ = time(0);
+ value_and_time()
+ // so that the first time it's used, it'll be refreshed
+ : time_(0) {
             }
             type val;
- time_t time_;
+ ::time_t time_;
         };
 
     public:
@@ -149,21 +150,32 @@
         };
 
         struct read {
- const type & val ;
- read(const self_type & self) : val(self.m_cache->val) {
+ const type *val ;
+ read(const self_type & self) : val( &(self.m_cache->val) ) {
                 ::time_t now = time(0);
- value_and_time & cached = *self.m_cache;
+ value_and_time & cached = *(self.m_cache);
                 if ( cached.time_ + self.m_cache_secs < now) {
                     // cache has expired
                     typename mutex::scoped_lock lk(self.m_cs);
- cached.val = self.m_val;
- cached.time_ = now;
+ // see if another thread has updated the cache...
+ if ( cached.time_ + self.m_cache_secs < now) {
+ cached.val = self.m_val;
+#ifndef BOOST_LOG_TEST_TSS
+ cached.time_ = now;
+#else
+ // for testing , make sure we always refresh at a fixed time
+ if ( cached.time_ != 0)
+ cached.time_ += self.m_cache_secs;
+ else
+ cached.time_ = now;
+#endif
+ }
                 }
             }
             ~read() {
             }
 
- const type & use() { return val ; }
+ const type & use() { return *val ; }
             const type* operator->() { return &use(); }
         };
 

Modified: sandbox/logging/boost/logging/format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format.hpp (original)
+++ sandbox/logging/boost/logging/format.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -240,7 +240,7 @@
 // add formatters : [idx] [time] message [enter]
 g_l->writer().add_formatter( write_idx() );
 g_l->writer().add_formatter( write_time() );
-g_l->writer().add_formatter( append_enter() );
+g_l->writer().add_formatter( append_newline() );
 
 // write to cout and file
 g_l->writer().add_destination( write_to_cout() );
@@ -251,7 +251,7 @@
 L_ << "testing " << i << i+1 << i+2;
 @endcode
 
- In the above case, @c write_idx() is called, then @c write_time(), then @c append_enter(). Now, the destinations are called:
+ In the above case, @c write_idx() is called, then @c write_time(), then @c append_newline(). Now, the destinations are called:
     @c write_to_cout(), and then @c write_to_file().
 
 
@@ -332,13 +332,13 @@
 
     g_l->writer().router().set_route()
         .fmt( write_time() )
- .fmt( append_enter() )
+ .fmt( append_newline() )
         .dest( write_to_dbg() )
         .fmt( write_idx() )
         .dest( write_to_cout() )
         .clear()
         .fmt( write_idx() )
- .fmt( append_enter() )
+ .fmt( append_newline() )
         .fmt( write_to_file())
         ;
     @endcode

Modified: sandbox/logging/boost/logging/format/formatter/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/defaults.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/defaults.hpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -65,12 +65,12 @@
 
 
 /**
-_at_brief Appends an enter
+@brief Appends a new line
 
 @param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
-template<class convert = do_convert_format::append> struct append_enter_t : is_generic, boost::logging::op_equal::always_equal {
+template<class convert = do_convert_format::append> struct append_newline_t : is_generic, boost::logging::op_equal::always_equal {
     template<class msg_type> void operator()(msg_type & str) const {
         convert::write( (const char_type*)BOOST_LOGGING_STR("\n"), str );
     }
@@ -78,12 +78,12 @@
 
 
 /**
-_at_brief Appends an enter, if not already there
+@brief Appends a new line, if not already there
 
 @param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
-template<class convert = do_convert_format::append> struct append_enter_if_needed_t : is_generic, boost::logging::op_equal::always_equal {
+template<class convert = do_convert_format::append> struct append_newline_if_needed_t : is_generic, boost::logging::op_equal::always_equal {
     template<class msg_type> void operator()(msg_type & str) const {
         bool is_needed = true;
         if ( !str.empty())
@@ -96,8 +96,8 @@
 };
 
 typedef idx_t<> idx;
-typedef append_enter_t<> append_enter;
-typedef append_enter_if_needed_t<> append_enter_if_needed;
+typedef append_newline_t<> append_newline;
+typedef append_newline_if_needed_t<> append_newline_if_needed;
 
 }}}
 

Modified: sandbox/logging/lib/logging/samples/basic_usage/log.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/basic_usage/log.cpp (original)
+++ sandbox/logging/lib/logging/samples/basic_usage/log.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -13,7 +13,7 @@
     // That is, how the message is to be formatted...
     g_l->writer().add_formatter( formatter::idx() );
     g_l->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
 
     // ... and where should it be written to
     g_l->writer().add_destination( destination::cout() );

Modified: sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -135,7 +135,7 @@
     // That is, how the message is to be formatted and where should it be written to
 
     g_l->writer().add_formatter( formatter::idx() );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
     g_l->writer().add_formatter( secs_since_start() );
 
     g_l->writer().add_destination( destination::cout() );

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -115,19 +115,19 @@
     // Err log
     g_log_err->writer().add_formatter( formatter::idx() );
     g_log_err->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_err->writer().add_formatter( formatter::append_enter() );
+ g_log_err->writer().add_formatter( formatter::append_newline() );
     g_log_err->writer().add_destination( destination::file("err.txt") );
 
     destination::file out("out.txt");
     // App log
     g_log_app->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_app->writer().add_formatter( formatter::append_enter() );
+ g_log_app->writer().add_formatter( formatter::append_newline() );
     g_log_app->writer().add_destination( out );
     g_log_app->writer().add_destination( destination::cout() );
 
     // Debug log
     g_log_dbg->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_dbg->writer().add_formatter( formatter::append_enter() );
+ g_log_dbg->writer().add_formatter( formatter::append_newline() );
     g_log_dbg->writer().add_destination( out );
     g_log_dbg->writer().add_destination( destination::dbg_window() );
 

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -72,7 +72,7 @@
     // That is, how the message is to be formatted...
     g_l->writer().add_formatter( formatter::idx() );
     g_l->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
 
     // ... and where should it be written to
     g_l->writer().add_destination( destination::cout() );

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -112,18 +112,18 @@
     // Err log
     g_log_err->writer().add_formatter( formatter::idx() );
     g_log_err->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_err->writer().add_formatter( formatter::append_enter() );
+ g_log_err->writer().add_formatter( formatter::append_newline() );
     g_log_err->writer().add_destination( destination::file("err.txt") );
 
     // App log
     g_log_app->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_app->writer().add_formatter( formatter::append_enter() );
+ g_log_app->writer().add_formatter( formatter::append_newline() );
     g_log_app->writer().add_destination( destination::file("out.txt") );
     g_log_app->writer().add_destination( destination::cout() );
 
     // Debug log
     g_log_dbg->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_dbg->writer().add_formatter( formatter::append_enter() );
+ g_log_dbg->writer().add_formatter( formatter::append_newline() );
     g_log_dbg->writer().add_destination( destination::dbg_window() );
     g_log_dbg->writer().add_destination( destination::cout() );
 

Modified: sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -99,7 +99,7 @@
     // That is, how the message is to be formatted...
     g_l->writer().add_formatter( formatter::idx() );
     g_l->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
 
     // ... and where should it be written to
     g_l->writer().add_destination( destination::cout() );
@@ -109,20 +109,20 @@
     // Now, specify the route
     g_l->writer().router().set_route()
         .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_enter() )
+ .fmt( formatter::append_newline() )
         .fmt( formatter::idx() )
         .clear()
         .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_enter() )
+ .fmt( formatter::append_newline() )
         .dest( destination::dbg_window() )
         .clear()
         .fmt( formatter::idx() )
         .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_enter() )
+ .fmt( formatter::append_newline() )
         .dest( destination::cout() )
         .clear()
         .fmt( formatter::idx() )
- .fmt( formatter::append_enter() )
+ .fmt( formatter::append_newline() )
         .dest( destination::file("out.txt") );
 
     // Step 8: use it...

Modified: sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -80,7 +80,7 @@
     // That is, how the message is to be formatted and where should it be written to
 
     g_l->writer().add_formatter( formatter::idx() );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
     g_l->writer().add_destination( destination::file("out.txt") );
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );

Modified: sandbox/logging/lib/logging/tests/do_not_use/format/test_manip_w_msgroute.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/do_not_use/format/test_manip_w_msgroute.cpp (original)
+++ sandbox/logging/lib/logging/tests/do_not_use/format/test_manip_w_msgroute.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -83,7 +83,7 @@
     }
 };
 
-struct append_enter : format_base {
+struct append_newline : format_base {
     void operator()(cache_string & str) const {
         str.append_string("\n");
     }
@@ -133,7 +133,7 @@
 void test_manipulator_with_msg_route() {
     g_l->writer().add_formatter( write_time() );
     g_l->writer().add_formatter( write_idx() );
- g_l->writer().add_formatter( append_enter() );
+ g_l->writer().add_formatter( append_newline() );
 
     g_l->writer().add_destination( write_to_cout() );
     g_l->writer().add_destination( write_to_dbg() );
@@ -152,12 +152,12 @@
     */
     g_l->writer().router().set_route()
         .fmt( write_time() )
- .fmt( append_enter() )
+ .fmt( append_newline() )
         .dest( write_to_dbg() )
         .fmt( write_idx() )
         .dest( write_to_cout() )
         .clear()
- .fmt( append_enter() )
+ .fmt( append_newline() )
         .dest( write_to_file())
         ;
 

Modified: sandbox/logging/lib/logging/tests/do_not_use/format/test_simple_formatter.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/do_not_use/format/test_simple_formatter.cpp (original)
+++ sandbox/logging/lib/logging/tests/do_not_use/format/test_simple_formatter.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -73,7 +73,7 @@
     }
 };
 
-struct append_enter : formatter::class_<append_enter, format_base, op_equal_no_context> {
+struct append_newline : formatter::class_<append_newline, format_base, op_equal_no_context> {
     void operator()(cache_string & str) const {
         str.append_string("\n");
     }
@@ -111,7 +111,7 @@
     // add formatters : [idx] [time] message [enter]
     g_l->writer().add_formatter( write_idx() );
     g_l->writer().add_formatter( write_time() );
- g_l->writer().add_formatter( append_enter() );
+ g_l->writer().add_formatter( append_newline() );
 
     // write to cout and file
     g_l->writer().add_destination( write_to_cout() );
@@ -123,7 +123,7 @@
     L_ << "must be prefixed by index and time , enter is appended as well " << i++;
 
     g_l->writer().del_formatter( write_idx() );
- g_l->writer().del_formatter( append_enter() );
+ g_l->writer().del_formatter( append_newline() );
     g_l->writer().del_destination( write_to_cout() );
 
     // will not be written to cout

Modified: sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp (original)
+++ sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -29,7 +29,7 @@
     // That is, how the message is to be formatted and where should it be written to
 
     g_l->writer().add_formatter( formatter::idx() );
- g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_formatter( formatter::append_newline() );
     g_l->writer().add_destination( destination::file("out.txt") );
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );

Modified: sandbox/logging/lib/logging/tests/test_ts_resouce_with_cache/test_ts_resource.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_ts_resouce_with_cache/test_ts_resource.cpp (original)
+++ sandbox/logging/lib/logging/tests/test_ts_resouce_with_cache/test_ts_resource.cpp 2007-11-05 04:42:54 EST (Mon, 05 Nov 2007)
@@ -19,6 +19,7 @@
       - I increase the size of the vector by 1
 */
 
+#define BOOST_LOG_TEST_TSS
 
 #define BOOST_LOG_TSS_USE_INTERNAL
 // this includes tss_value class
@@ -34,10 +35,35 @@
 #include <sstream>
 #include <iostream>
 
+#ifdef BOOST_WINDOWS
+#include <windows.h>
+#endif
+
 using namespace boost;
 typedef std::vector<int> array;
 typedef logging::locker::tss_resource_with_cache<array> resource;
 
+namespace boost { namespace logging { namespace detail {
+void on_end_delete_objects() {}
+}}}
+
+struct dump {
+ ~dump() {
+ std::string msg = out.str();
+ if ( msg.empty() )
+ return;
+ std::cout << msg;
+ std::cout.flush();
+#ifdef BOOST_WINDOWS
+ ::OutputDebugStringA( msg.c_str() );
+#endif
+ }
+ dump& ref() { return *this; }
+ std::ostringstream out;
+};
+
+#define LOG_ dump().ref().out
+
 template<class type> struct ts_value {
     void set(const type & src) {
         mutex::scoped_lock lk(cs);
@@ -54,10 +80,7 @@
     type m_val;
 };
 
-// for our resource, at what period is it updated on all threads?
-// note: this value should be at least 5 in order for the test to work:
-// we sleep a bit, then we do lots of modifications, then we sleep a lot - so that the snapshots can be accurately taken
-int g_cache_period_secs = 10;
+extern int g_cache_period_secs ;
 
 // the vector we're constantly changing
 resource g_resource( array(), g_cache_period_secs);
@@ -88,7 +111,7 @@
 
     if ( change_idx % INCREASE_VECTOR_SIZE_PERIOD == 0 ) {
         cur.resize( cur.size() + 1);
- std::cout << "****** new vector size " << cur.size() + 1;
+ LOG_ << "****** new vector size " << cur.size() << std::endl;
     }
 
     for ( int i = 0 ; i < (int)cur.size(); ++i)
@@ -106,15 +129,25 @@
 }
 
 
+void dump_array(const array & val, const std::string & array_name) {
+ LOG_ << array_name << "= " ;
+ for ( array::const_iterator b = val.begin(), e = val.end(); b != e; ++b)
+ LOG_ << *b << ", ";
+ LOG_ << std::endl;
+}
+
 void get_snapshot() {
     array snap = g_cur_val.get() ;
 
     array prev_snapshot = g_snapshot.get();
     g_snapshot.set(snap);
     g_prev_snapshot.set( prev_snapshot);
+
+ dump_array(snap, "got new snapshot");
 }
 
-void test_resource() {
+
+void test_resource(int idx) {
     array cur_val ;
     {
     resource::read res(g_resource);
@@ -122,9 +155,14 @@
     }
 
     array snap = g_snapshot.get();
- array prev_snap = g_snapshot.get();
+ array prev_snap = g_prev_snapshot.get();
 
- BOOST_ASSERT( cur_val == snap || cur_val == prev_snap);
+ if ( !(cur_val == snap || cur_val == prev_snap)) {
+ dump_array(cur_val, "resource");
+ dump_array(snap, "snapshot");
+ dump_array(prev_snap, "prev snapshot");
+ BOOST_ASSERT( false);
+ }
 }
 
 void do_sleep(int ms) {
@@ -142,9 +180,7 @@
 
 
 
-
-// how many times do we update the resource, in a given pass?
-int g_update_per_thread_count = 200;
+extern int g_update_per_thread_count ;
 
 ts_value<int> g_thread_idx;
 // start time - we need all update threads to syncronize - to know until when to sleep
@@ -156,39 +192,73 @@
     g_thread_idx.set(thread_idx + 1);
  
     while ( true) {
- next.sec += g_cache_period_secs;
- do_sleep(1000);
+ next.sec += 1;
+ thread::sleep( next);
+ next.sec += g_cache_period_secs - 1;
 
- std::cout << "thread " << thread_idx << " working" << std::endl;
+ LOG_ << "thread " << thread_idx << " working" << std::endl;
         for ( int i = 0; i < g_update_per_thread_count ; ++i) {
             update_resource();
             do_sleep(10);
         }
- std::cout << "thread " << thread_idx << " sleeping" << std::endl;
+ LOG_ << "thread " << thread_idx << " sleeping" << std::endl;
 
+ array cur_resource_val ;
+ {
+ resource::write res(g_resource);
+ cur_resource_val = res.use() ;
+ }
+ dump_array(cur_resource_val, "update_snapshot" );
         thread::sleep( next);
     }
 }
 
 void test_thread() {
+ int idx = 0;
     while ( true) {
+ // so that in case a test fails, we know when
+ ++idx;
         do_sleep(100);
- test_resource();
+ test_resource(idx);
     }
 }
 
+void get_snapshot_thread() {
+ xtime next = g_start;
+ get_snapshot();
+
+ while ( true) {
+ const int SECS_BEFORE_END_OF_PASS = 2;
+ next.sec += g_cache_period_secs - SECS_BEFORE_END_OF_PASS;
+
+ thread::sleep( next);
+ // get snapshot after all work has been done
+ get_snapshot();
+
+ next.sec += SECS_BEFORE_END_OF_PASS;
+ thread::sleep( next);
+ }
+}
 
 
 
 
 
+// for our resource, at what period is it updated on all threads?
+// note: this value should be at least 5 in order for the test to work:
+// we sleep a bit, then we do lots of modifications, then we sleep a lot - so that the snapshots can be accurately taken
+int g_cache_period_secs = 10;
+
+// how many times do we update the resource, in a given pass?
+int g_update_per_thread_count = 100;
+
 // how many threads that update the resource?
-int g_update_thread_count = 1; //10;
+int g_update_thread_count = 5;
 
 // how many threads that test the resource?
-int g_test_thread_count = 1; // 10;
+int g_test_thread_count = 10;
 
-int g_run_period_secs = 1000; //100;
+int g_run_period_secs = 200;
 
 int main()
 {
@@ -200,6 +270,8 @@
     for ( int i = 0; i < g_test_thread_count; ++i)
         thread t(&test_thread);
 
+ thread t(&get_snapshot_thread);
+
     do_sleep(g_run_period_secs * 1000);
         return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk