|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60583 - in sandbox/stm/branches/vbe/boost/synchro: . detail lockable lockers pthread thread
From: vicente.botet_at_[hidden]
Date: 2010-03-14 17:30:04
Author: viboes
Date: 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
New Revision: 60583
URL: http://svn.boost.org/trac/boost/changeset/60583
Log:
Boost.STM/vbe/synchro:
* Added call context to trace who is locking/unlocking which mutex
Added:
sandbox/stm/branches/vbe/boost/synchro/call_context.hpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp | 3 +
sandbox/stm/branches/vbe/boost/synchro/language_like.hpp | 62 +++++++++++++++++++++++++++++++++
sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp | 3 +
sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp | 4 +-
sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp | 2
sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp | 3 +
sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp | 3 +
sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp | 25 ++++++++----
sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp | 45 ++++++++++++++++-------
sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp | 74 ++++++++++++++++++++++++++++++++++-----
sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp | 2
11 files changed, 185 insertions(+), 41 deletions(-)
Added: sandbox/stm/branches/vbe/boost/synchro/call_context.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/call_context.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -0,0 +1,79 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CALL_CTX_HPP
+#define BOOST_CALL_CTX_HPP
+
+#include <boost/synchro/detail/config.hpp>
+
+
+#include <iostream>
+//-----------------------------------------------------------------------------
+#include <assert.h>
+//-----------------------------------------------------------------------------
+#include <boost/thread/mutex.hpp>
+namespace boost {
+extern boost::mutex log_mutex;
+}
+
+#ifdef BOOST_STM_USES_CALL_CONTEXT
+
+namespace boost {
+struct call_context {
+ const void * that;
+ const char* file;
+ std::size_t line;
+ const char* fct;
+ call_context(const void *inst, const char* f, std::size_t l, const char* function)
+ : that(inst), file(f), line(l), fct(function) {}
+ ~call_context() {}
+};
+}
+
+
+#define BOOST_STM_CALL_CONTEXT_DCL_VAR_INST(NAME, INST) boost::call_context NAME(INST, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
+#define BOOST_STM_CALL_CONTEXT_DCL_VAR(NAME) BOOST_STM_CALL_CONTEXT_DCL_VAR_INST(NAME, this)
+#define BOOST_STM_CALL_CONTEXT_DCL_INST(INST) BOOST_STM_CALL_CONTEXT_DCL_VAR_INST(__call_context, INST)
+#define BOOST_STM_CALL_CONTEXT_DCL() BOOST_STM_CALL_CONTEXT_DCL_VAR(__call_context)
+
+#define BOOST_STM_CALL_CONTEXT(NAME) ,&__call_context,NAME
+
+#define BOOST_STM_CALL_CONTEXT_2_DCL() call_context* cctx_; const char* name_
+#define BOOST_STM_CALL_CONTEXT_2_PARAMS() ,call_context* cctx=0, const char* name=0
+#define BOOST_STM_CALL_CONTEXT_2_PARAMS1() call_context* cctx=0, const char* name=0
+#define BOOST_STM_CALL_CONTEXT_2_TMPL_PARAMS() ,call_context* cctx, const char* name
+#define BOOST_STM_CALL_CONTEXT_2_ACT_PARAMS() ,cctx, name
+#define BOOST_STM_CALL_CONTEXT_2_ACT_CTX() ,cctx_, name_
+
+#define BOOST_STM_CALL_CONTEXT_2_INIT() , cctx_(cctx), name_(name)
+
+#else // !BOOST_STM_USES_CALL_CONTEXT
+
+#define BOOST_STM_CALL_CONTEXT_DCL_VAR_INST(NAME, INST) ((void)0)
+#define BOOST_STM_CALL_CONTEXT_DCL_VAR(NAME) ((void)0)
+#define BOOST_STM_CALL_CONTEXT_DCL_INST(INST) ((void)0)
+#define BOOST_STM_CALL_CONTEXT_DCL() ((void)0)
+
+
+#define BOOST_STM_CALL_CONTEXT(NAME)
+
+#define BOOST_STM_CALL_CONTEXT_2_DCL()
+#define BOOST_STM_CALL_CONTEXT_2_PARAMS()
+#define BOOST_STM_CALL_CONTEXT_2_PARAMS1()
+#define BOOST_STM_CALL_CONTEXT_2_TMPL_PARAMS()
+#define BOOST_STM_CALL_CONTEXT_2_ACT_PARAMS()
+#define BOOST_STM_CALL_CONTEXT_2_ACT_CTX()
+#define BOOST_STM_CALL_CONTEXT_2_INIT()
+#endif
+#endif // BOOST_CALL_CTX_HPP
+
+
Modified: sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -17,6 +17,9 @@
//-----------------------------------------------------------------------------
#include <boost/config.hpp>
#include <boost/thread/detail/platform.hpp>
+
+#define BOOST_STM_USES_CALL_CONTEXT 1
+
//-----------------------------------------------------------------------------
#endif // BOOST_SYNCHO_DETAIL_CONFIG_HPP
Modified: sandbox/stm/branches/vbe/boost/synchro/language_like.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/language_like.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/language_like.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -84,4 +84,66 @@
#define synchronize_type_until(TYPE, VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL(TYPE, VAR, ABS_TIME, LOCKABLE)
+#define BOOST_SYNCHRO_SYNCHRONIZE_TYPE_NAMED(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, __call_context, ##LOCKABLE))
+
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_TYPE_NAMED(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT_NAMED(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::adopt_lock, __call_context, ##LOCKABLE))
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE_TYPE_NAMED(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT_NAMED(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::defer_lock, __call_context, ##LOCKABLE))
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_NAMED(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT_NAMED(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::try_to_lock, __call_context, ##LOCKABLE))
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_UNTIL_NAMED(TYPE, VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT_NAMED(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, ABS_TIME, __call_context, ##LOCKABLE))
+#define BOOST_SYNCHRO_SYNCHRONIZE_TYPE_UNTIL_NAMED(TYPE, VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT_NAMED(boost::synchro::unique_lock<TYPE> VAR(ABS_TIME, LOCKABLE, __call_context, ##LOCKABLE))
+
+#define BOOST_SYNCHRO_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_TYPE_NAMED(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_TYPE_NAMED(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_DEFER_SYNCHRONIZE_TYPE_NAMED(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_NAMED(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL_NAMED(VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_TYPE_UNTIL_NAMED(boost::mutex, VAR, LOCKABLE, ABS_TIME)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL_NAMED(VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_UNTIL_NAMED(boost::mutex, VAR, LOCKABLE, ABS_TIME)
+
+#define BOOST_SYNCHRO_SYNCHRONIZE_NAMED(LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_VAR_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE)
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_NAMED(LOCKABLE) \
+ BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE)
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE_NAMED(LOCKABLE) \
+ BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_NAMED(LOCKABLE) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE)
+#define BOOST_SYNCHRO_SYNCHRONIZE_UNTIL_NAMED(LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE, ABS_TIME)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_UNTIL_NAMED(LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL_NAMED(BOOST_JOIN(_,__LINE__), LOCKABLE, ABS_TIME)
+
+#define named_synchronize(LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE_NAMED(LOCKABLE)
+#define named_adopt_synchronize(LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_NAMED(LOCKABLE)
+#define named_defer_synchronize(LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE_NAMED(LOCKABLE)
+#define named_try_to_synchronize(LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_NAMED(LOCKABLE)
+#define named_try_to_synchronize_until(LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_UNTIL_NAMED(LOCKABLE, ABS_TIME)
+#define named_synchronize_until(LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_UNTIL_NAMED(LOCKABLE, ABS_TIME)
+
+#define named_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE)
+#define named_adopt_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE)
+#define named_defer_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE)
+#define named_try_to_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_NAMED(VAR, LOCKABLE)
+#define named_try_to_synchronize_var_until(VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL_NAMED(VAR, LOCKABLE, ABS_TIME)
+#define named_synchronize_var_until(VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL_NAMED(VAR, ABS_TIME, LOCKABLE)
+
+#define named_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE_TYPE_NAMED(TYPE, VAR, LOCKABLE)
+#define named_adopt_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR_NAMED(TYPE, VAR, LOCKABLE)
+#define named_defer_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR_NAMED(TYPE, VAR, LOCKABLE)
+#define named_try_to_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_NAMED(TYPE, VAR, LOCKABLE)
+#define named_try_to_synchronize_type_until(TYPE, VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL_NAMED(TYPE, VAR, LOCKABLE, ABS_TIME)
+#define named_synchronize_type_until(TYPE, VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL_NAMED(TYPE, VAR, ABS_TIME, LOCKABLE)
+
+
#endif
Modified: sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -15,6 +15,7 @@
#define BOOST_SYNCHO_LOCKABLE_LOCK_HPP
#include <assert.h>
+#include <boost/synchro/call_context.hpp>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -22,7 +23,7 @@
namespace boost { namespace synchro {
template< typename Lockable >
- inline void lock(Lockable& lockable) {
+ inline void lock(Lockable& lockable BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
try {
lockable.lock();
} catch (...) {
Modified: sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -22,8 +22,8 @@
namespace boost { namespace synchro {
template <typename Lockable, typename TimeDuration >
- bool lock_for(Lockable& lockable, const TimeDuration& rel_time) {
- return lock_until(&lockable, get_system_time()+rel_time);
+ bool lock_for(Lockable& lockable, const TimeDuration& rel_time BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
+ return lock_until(&lockable, get_system_time()+rel_time BOOST_STM_CALL_CONTEXT_2_ACT_PARAMS());
}
}}
Modified: sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -21,7 +21,7 @@
namespace boost { namespace synchro {
template< typename Lockable>
- inline bool lock_until(Lockable& lockable, system_time const& target_time) {
+ inline bool lock_until(Lockable& lockable, system_time const& target_time BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
return lockable.lock_until(target_time);
}
Modified: sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -15,6 +15,7 @@
#define BOOST_SYNCHO_LOCKABLE_TRY_LOCK_HPP
#include <assert.h>
+#include <boost/synchro/call_context.hpp>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -22,7 +23,7 @@
namespace boost { namespace synchro {
template< typename Lockable >
- inline bool try_lock(Lockable& lockable) {
+ inline bool try_lock(Lockable& lockable BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
try {
return lockable.try_lock();
} catch (...) {
Modified: sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -15,6 +15,7 @@
#define BOOST_SYNCHO_LOCKABLE_UNLOCK_HPP
#include <assert.h>
+#include <boost/synchro/call_context.hpp>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -22,7 +23,7 @@
namespace boost { namespace synchro {
template< typename Lockable >
- inline void unlock(Lockable& lockable) {
+ inline void unlock(Lockable& lockable BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
try {
lockable.unlock();
} catch (...) {
Modified: sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -20,6 +20,7 @@
#include <boost/synchro/lockable/lock.hpp>
#include <boost/synchro/lockable/unlock.hpp>
//-----------------------------------------------------------------------------
+#include <boost/synchro/call_context.hpp>
namespace boost {
namespace synchro {
@@ -31,7 +32,7 @@
explicit static_lock_guard(static_lock_guard&);
static_lock_guard& operator=(static_lock_guard&);
public:
- static_lock_guard()
+ static_lock_guard()
{
lock(m);
}
@@ -46,20 +47,23 @@
class lock_guard {
private:
Mutex& m;
+ BOOST_STM_CALL_CONTEXT_2_DCL();
explicit lock_guard(lock_guard&);
lock_guard& operator=(lock_guard&);
public:
- explicit lock_guard(Mutex& m_)
+ explicit lock_guard(Mutex& m_ BOOST_STM_CALL_CONTEXT_2_PARAMS())
: m(m_)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
- lock(m);
+ lock(m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
}
- lock_guard(Mutex& m_, bool cnd, adopt_lock_t)
+ lock_guard(Mutex& m_, bool cnd, adopt_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS())
: m(m_)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{}
~lock_guard() {
- unlock(m);
+ unlock(m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
}
};
@@ -89,22 +93,25 @@
private:
Mutex& m;
bool cnd_;
+ BOOST_STM_CALL_CONTEXT_2_DCL();
explicit lock_guard_if(lock_guard_if&);
lock_guard_if& operator=(lock_guard_if&);
public:
- lock_guard_if(Mutex& m_, bool cnd)
+ lock_guard_if(Mutex& m_, bool cnd BOOST_STM_CALL_CONTEXT_2_PARAMS())
: m(m_)
, cnd_(cnd)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
- if (cnd_) lock(m);
+ if (cnd_) lock(m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
}
- lock_guard_if(Mutex& m_, bool cnd, adopt_lock_t)
+ lock_guard_if(Mutex& m_, bool cnd, adopt_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS())
: m(m_)
, cnd_(cnd)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{}
~lock_guard_if() {
- if (cnd_) unlock(m);
+ if (cnd_) unlock(m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
}
};
Modified: sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -21,6 +21,8 @@
#include <boost/synchro/exceptions.hpp>
#include <boost/synchro/lockable.hpp>
//-----------------------------------------------------------------------------
+#include <boost/synchro/call_context.hpp>
+
namespace boost {
namespace synchro {
@@ -31,48 +33,59 @@
private:
Mutex* m;
bool is_locked;
+ BOOST_STM_CALL_CONTEXT_2_DCL();
+
unique_lock(unique_lock&);
unique_lock& operator=(unique_lock&);
public:
- unique_lock():
+ unique_lock( BOOST_STM_CALL_CONTEXT_2_PARAMS1() ):
m(0),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{}
- explicit unique_lock(Mutex& m_):
+ explicit unique_lock(Mutex& m_ BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
lock();
}
- unique_lock(Mutex& m_,bool b):
+ unique_lock(Mutex& m_,bool b BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
if (b) lock();
}
- unique_lock(Mutex& m_,force_lock_t):
+ unique_lock(Mutex& m_,force_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
lock();
}
- unique_lock(Mutex& m_,adopt_lock_t):
+ unique_lock(Mutex& m_,adopt_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(true)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{}
- unique_lock(Mutex& m_,defer_lock_t):
+ unique_lock(Mutex& m_,defer_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{}
- unique_lock(Mutex& m_,try_to_lock_t):
+ unique_lock(Mutex& m_,try_to_lock_t BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
try_lock();
}
template<typename TimeDuration>
- unique_lock(Mutex& m_,TimeDuration const& target_time):
+ unique_lock(Mutex& m_,TimeDuration const& target_time BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
lock_for(target_time);
}
- unique_lock(Mutex& m_,system_time const& target_time):
+ unique_lock(Mutex& m_,system_time const& target_time BOOST_STM_CALL_CONTEXT_2_PARAMS()):
m(&m_),is_locked(false)
+ BOOST_STM_CALL_CONTEXT_2_INIT()
{
lock_until(target_time);
}
@@ -137,6 +150,10 @@
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
+#ifdef BOOST_STM_USES_CALL_CONTEXT
+ std::swap(cctx_,other.cctx_);
+ std::swap(name_,other.name_);
+#endif
}
#endif
@@ -153,7 +170,7 @@
{
throw lock_error();
}
- synchro::lock(*m);
+ synchro::lock(*m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
is_locked=true;
}
bool try_lock()
@@ -162,19 +179,19 @@
{
throw lock_error();
}
- is_locked=synchro::try_lock(*m);
+ is_locked=synchro::try_lock(*m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
return is_locked;
}
template<typename TimeDuration>
bool lock_for(TimeDuration const& relative_time)
{
- is_locked=synchro::lock_for(*m, relative_time);
+ is_locked=synchro::lock_for(*m, relative_time BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
return is_locked;
}
bool lock_until(system_time const& absolute_time)
{
- is_locked=synchro::lock_until(*m, absolute_time);
+ is_locked=synchro::lock_until(*m, absolute_time BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
return is_locked;
}
void unlock()
@@ -183,7 +200,7 @@
{
throw lock_error();
}
- synchro::unlock(*m);
+ synchro::unlock(*m BOOST_STM_CALL_CONTEXT_2_ACT_CTX());
is_locked=false;
}
Modified: sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -24,8 +24,11 @@
#include <boost/synchro/exceptions.hpp>
#include <boost/synchro/time.hpp>
#include <boost/synchro/lockable.hpp>
+#include <boost/synchro/call_context.hpp>
+#include <boost/thread.hpp>
//-----------------------------------------------------------------------------
+
#define BOOST_SYNCHRO_CHECK
#ifdef BOOST_SYNCHRO_CHECK
@@ -39,25 +42,74 @@
#define BOOST_STM_VERIFY(expr) ((void)(expr))
#endif
namespace boost { namespace synchro {
-
+
+#ifdef BOOST_STM_USES_CALL_CONTEXT
+ inline void trace_lock(int res, pthread_mutex_t& lockable,call_context* cctx=0, const char* name=0) {
+ if (cctx==0) return;
+ if (name==0) name="";
+ boost::lock_guard<boost::mutex> lk(log_mutex);
+ if (res!=0)
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " [[[[[ERROR[ "<< res <<"] on lock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+ else
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " [[[[[INFO "<< " on lock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+
+ }
+ inline void trace_unlock(int res, pthread_mutex_t& lockable,call_context* cctx=0, const char* name=0) {
+ if (cctx==0) return;
+ if (name==0) name="";
+ boost::lock_guard<boost::mutex> lk(log_mutex);
+ if (res!=0)
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " ]]]]]ERROR[ "<< res <<"] on unlock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+ else
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " ]]]]]]INFO "<< " on unlock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+ }
+ inline void trace_try_lock(int res, pthread_mutex_t& lockable ,call_context* cctx=0, const char* name=0) {
+ if (cctx==0) return;
+ if (name==0) name="";
+ boost::lock_guard<boost::mutex> lk(log_mutex);
+ if (res!=0)
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " [[[[[ERROR[ "<< res <<"] on try_lock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+ else
+ std::cout << cctx->that << " : " << std::dec << boost::this_thread::get_id()
+ << " [[[[[INFO "<< " on try_lock ["<<name<<"]("<< & lockable <<") "<< cctx->file << "[" << cctx->line << "] " << cctx->fct << std::endl;
+ }
+
+#define BOOST_STM_TRACE_LOCK(RES,LOCK) trace_lock(RES,LOCK,cctx,name)
+#define BOOST_STM_TRACE_UNLOCK(RES,LOCK) trace_unlock(RES,LOCK,cctx,name)
+#define BOOST_STM_TRACE_TRY_LOCK(RES,LOCK) trace_try_lock(RES,LOCK,cctx,name)
+#else
+#define BOOST_STM_TRACE_LOCK(RES,LOCK) ((void)0)
+#define BOOST_STM_TRACE_UNLOCK(RES,LOCK) ((void)0)
+#define BOOST_STM_TRACE_TRY_LOCK(RES,LOCK) ((void)0)
+#endif
template<>
- inline void lock<pthread_mutex_t>(pthread_mutex_t& lockable) {
- //~ std::cout << __FILE__<< __LINE__ << " mutex::lock " << & lockable << std::endl;
- BOOST_STM_VERIFY(pthread_mutex_lock(&lockable)==0&&"synchro::lock<pthread_mutex_t>");
- //if (res!=0) throw lock_error();
+ inline void lock<pthread_mutex_t>(pthread_mutex_t& lockable BOOST_STM_CALL_CONTEXT_2_TMPL_PARAMS()) {
+ int res=pthread_mutex_lock(&lockable);
+ BOOST_STM_TRACE_LOCK(res,lockable);
+ //std::cout << __FILE__<< __LINE__ << " mutex::lock " << & lockable << std::endl;
+ BOOST_STM_ASSERT(res==0&&"synchro::lock<pthread_mutex_t>");
+ if (res!=0) throw lock_error();
}
template<>
- inline void unlock<pthread_mutex_t>(pthread_mutex_t& lockable) {
- //~ std::cout << __FILE__<< __LINE__ << " mutex::unlock " << & lockable << std::endl;
- BOOST_STM_VERIFY(pthread_mutex_unlock(&lockable)==0&&"synchro::unlock<pthread_mutex_t>");
- //if (res!=0) throw lock_error();
+ inline void unlock<pthread_mutex_t>(pthread_mutex_t& lockable BOOST_STM_CALL_CONTEXT_2_TMPL_PARAMS()) {
+ int res=pthread_mutex_unlock(&lockable);
+ BOOST_STM_TRACE_UNLOCK(res,lockable);
+ //std::cout << __FILE__<< __LINE__ << " mutex::unlock " << & lockable << std::endl;
+ BOOST_STM_ASSERT(res==0&&"synchro::unlock<pthread_mutex_t>");
+ if (res!=0) throw lock_error();
}
template<>
- inline bool try_lock<pthread_mutex_t>(pthread_mutex_t& lockable) {
+ inline bool try_lock<pthread_mutex_t>(pthread_mutex_t& lockable BOOST_STM_CALL_CONTEXT_2_TMPL_PARAMS()) {
int const res=pthread_mutex_trylock(&lockable);
- //BOOST_STM_VERIFY(!res || res==EBUSY);
+ BOOST_STM_TRACE_TRY_LOCK(res,lockable);
+ //BOOST_STM_ASSERT(!res || res==EBUSY);
return (!res);
}
Modified: sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp (original)
+++ sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp 2010-03-14 17:30:03 EDT (Sun, 14 Mar 2010)
@@ -27,7 +27,7 @@
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
template<>
inline bool lock_until<boost::timed_mutex>(
- boost::timed_mutex& lockable, system_time const& abs_time) {
+ boost::timed_mutex& lockable, system_time const& abs_time BOOST_STM_CALL_CONTEXT_2_PARAMS()) {
return lockable.timed_lock(abs_time);
}
#endif
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