|
Boost-Commit : |
From: john.groups_at_[hidden]
Date: 2007-11-03 18:53:49
Author: jtorjo
Date: 2007-11-03 18:53:48 EDT (Sat, 03 Nov 2007)
New Revision: 40732
URL: http://svn.boost.org/trac/boost/changeset/40732
Log:
[logging]
v0.10.7, 3 nov 2007
- finalized tss_resouce_with_cache
- added TSS tests
- test test_ts_resource_with_cache - not tested
- test test_tss SUCCESSFUL on win32
- test test_simple_tss SUCCESSFUL on win32
Text files modified:
sandbox/logging/boost/logging/defaults.hpp | 7 ++++---
sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 5 +++--
sandbox/logging/boost/logging/detail/ts/ts_resource.hpp | 34 ++++++++++++++++++++--------------
sandbox/logging/lib/logging/tests/test_ts_resouce_with_cache/test_ts_resource.cpp | 10 +++++++---
4 files changed, 34 insertions(+), 22 deletions(-)
Modified: sandbox/logging/boost/logging/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/defaults.hpp (original)
+++ sandbox/logging/boost/logging/defaults.hpp 2007-11-03 18:53:48 EDT (Sat, 03 Nov 2007)
@@ -90,7 +90,7 @@
namespace locker {
template<class type, class mutex > struct ts_resource ;
- template<class , int> struct tss_resource_with_cache ;
+ template<class , int, class> struct tss_resource_with_cache ;
}
@@ -110,8 +110,9 @@
struct lock_resource {
template<class lock_type> struct finder {
-//#ifndef BOOST_LOG_NO_TSS
- // typedef typename locker::tss_resource_with_cache<lock_type, 5> type;
+//#if !defined( BOOST_LOG_NO_TSS) && defined(BOOST_WINDOWS)
+ // on Windows, I've tested the threading
+// typedef typename locker::tss_resource_with_cache<lock_type, 5, boost::logging::threading::mutex > type;
//#else
typedef typename locker::ts_resource<lock_type, boost::logging::threading::mutex > type;
//#endif
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-03 18:53:48 EDT (Sat, 03 Nov 2007)
@@ -1,11 +1,12 @@
/**
@page page_changelog Changelog
-v0.10.6, 3 nov 2007
+v0.10.7, 3 nov 2007
+- finalized tss_resouce_with_cache
- added TSS tests
+ - test test_ts_resource_with_cache - not tested
- test test_tss SUCCESSFUL on win32
- test test_simple_tss SUCCESSFUL on win32
- - test test_ts_resource_with_cache - not tested
- added TSS - however, not tested (TSS is off, for now)
- compiles on VS2005, gcc 3.4.2 , gcc 4.1 and gcc 4.3
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-03 18:53:48 EDT (Sat, 03 Nov 2007)
@@ -75,11 +75,10 @@
struct write {
self_type & self ;
- write(self_type & self) : self(self) {
- self.m_cs.Lock();
+ typename mutex::scoped_lock locker;
+ write(self_type & self) : self(self), locker(self.m_cs) {
}
~write() {
- self.m_cs.Unlock();
}
type & use() { return self.m_val ; }
@@ -117,10 +116,7 @@
@sa locker
@sa default_cache_millis how many secs to cache the data. By default, 5
*/
- template<class type, int default_cache_secs = 5> struct tss_resource_with_cache {
- // FIXME - implement using TLS!!!
-// I NEED TO CREATE TESTS FOR tss_value / tss_resource_with_cache
-
+ template<class type, int default_cache_secs = 5, class mutex = boost::logging::threading::mutex > struct tss_resource_with_cache {
typedef tss_resource_with_cache<type, default_cache_secs> self_type;
private:
@@ -141,24 +137,33 @@
friend struct write;
struct write {
- self_type & self ;
- write(self_type & self) : self(self) {
+ type & val;
+ typename mutex::scoped_lock locker;
+ write(self_type & self) : val(self.m_val), locker(self.m_cs) {
}
~write() {
}
- type & use() { return self.m_val ; }
+ type & use() { return val ; }
type* operator->() { return &use(); }
};
struct read {
- const self_type & self ;
- read(const self_type & self) : self(self) {
+ 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;
+ 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;
+ }
}
~read() {
}
- const type & use() { return self.m_val ; }
+ const type & use() { return val ; }
const type* operator->() { return &use(); }
};
@@ -166,8 +171,9 @@
private:
int m_cache_secs;
- tss_value<value_and_time> m_cache;
+ mutable tss_value<value_and_time> m_cache;
type m_val;
+ mutable mutex m_cs;
};
#endif
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-03 18:53:48 EDT (Sat, 03 Nov 2007)
@@ -85,7 +85,8 @@
int last_val = 0;
if ( !cur.empty() )
last_val = cur.back();
- if ( change_idx % INCREASE_VECTOR_SIZE_PERIOD ) {
+
+ if ( change_idx % INCREASE_VECTOR_SIZE_PERIOD == 0 ) {
cur.resize( cur.size() + 1);
std::cout << "****** new vector size " << cur.size() + 1;
}
@@ -182,10 +183,12 @@
// how many threads that update the resource?
-int g_update_thread_count = 10;
+int g_update_thread_count = 1; //10;
// how many threads that test the resource?
-int g_test_thread_count = 10;
+int g_test_thread_count = 1; // 10;
+
+int g_run_period_secs = 1000; //100;
int main()
{
@@ -197,6 +200,7 @@
for ( int i = 0; i < g_test_thread_count; ++i)
thread t(&test_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