|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53457 - in sandbox/stm: boost/stm boost/stm/detail libs/stm/doc libs/stm/src libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-05-30 10:03:32
Author: viboes
Date: 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
New Revision: 53457
URL: http://svn.boost.org/trac/boost/changeset/53457
Log:
TBoost.Stm Add getters to transaction data members
Text files modified:
sandbox/stm/boost/stm/base_transaction.hpp | 37 ++
sandbox/stm/boost/stm/detail/config.hpp | 6
sandbox/stm/boost/stm/detail/datatypes.hpp | 2
sandbox/stm/boost/stm/detail/latm_def_tx_impl.hpp | 6
sandbox/stm/boost/stm/detail/latm_dir_full_impl.hpp | 21
sandbox/stm/boost/stm/detail/latm_dir_tm_impl.hpp | 21
sandbox/stm/boost/stm/detail/latm_dir_tx_impl.hpp | 8
sandbox/stm/boost/stm/detail/latm_general_impl.hpp | 82 +---
sandbox/stm/boost/stm/detail/transaction_impl.hpp | 126 ++++---
sandbox/stm/boost/stm/detail/tx_ptr.hpp | 16
sandbox/stm/boost/stm/transaction.hpp | 664 ++++++++++++++++++++++++++++-----------
sandbox/stm/libs/stm/doc/appendices.qbk | 2
sandbox/stm/libs/stm/src/transaction.cpp | 148 ++++++--
sandbox/stm/libs/stm/test/smart.cpp | 6
14 files changed, 738 insertions(+), 407 deletions(-)
Modified: sandbox/stm/boost/stm/base_transaction.hpp
==============================================================================
--- sandbox/stm/boost/stm/base_transaction.hpp (original)
+++ sandbox/stm/boost/stm/base_transaction.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -415,6 +415,43 @@
virtual void perform_irrevocable_tx_wait_priority_promotion(boost::stm::transaction &);
};
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+ template<typename Lockable>
+ class lock_guard2
+ {
+ private:
+ Lockable& m;
+ //bool owns_;
+
+ explicit lock_guard2(lock_guard2&);
+ lock_guard2& operator=(lock_guard2&);
+ public:
+ inline explicit lock_guard2(Lockable& m_):
+ m(m_)
+ {
+ lock();
+ }
+ inline ~lock_guard2()
+ {
+ //unlock();
+ }
+ //inline bool owns_lock() { return owns_;}
+ inline void lock() {
+ //if (owns_)
+ stm::lock(m);
+ //owns_=true;
+ }
+ inline void unlock() {
+ //if (owns_)
+ stm::unlock(m);
+ //owns_=false;
+ }
+ //inline void release() {
+ // owns_=false;
+ //}
+ };
+
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Modified: sandbox/stm/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/boost/stm/detail/config.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -39,9 +39,11 @@
#define PERFORMING_WRITE_BLOOM 1
//#define ALWAYS_ALLOW_ABORT 1
//#define LOGGING_BLOCKS 1
-//#define USE_SINGLE_THREAD_CONTEXT_MAP 1
-//#define BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP 1
+#define USE_SINGLE_THREAD_CONTEXT_MAP 1
#define BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS 1
+#define BOOST_STM_USES_AS_NEW 1
+#define BOOST_STM_USES_PARAM 1
+//#define BOOST_STM_LL_USES_NODE
#ifdef USE_BLOOM_FILTER
#define DISABLE_READ_SETS 1
Modified: sandbox/stm/boost/stm/detail/datatypes.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/datatypes.hpp (original)
+++ sandbox/stm/boost/stm/detail/datatypes.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -33,7 +33,6 @@
#ifndef BOOST_STM_dataTypes_header_file
#define BOOST_STM_dataTypes_header_file
-//#include <boost/thread/thread.hpp>
/////////////////////////////////////////////////////////////////////////////
#ifdef WIN32
@@ -45,7 +44,6 @@
#endif
#include <stdlib.h>
-//#include <boost/thread/thread.hpp>
#include <pthread.h>
#ifndef BOOST_STM_USE_BOOST_THREAD_ID
Modified: sandbox/stm/boost/stm/detail/latm_def_tx_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/latm_def_tx_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/latm_def_tx_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -80,7 +80,7 @@
if (t->threadId_ == THREAD_ID) continue;
// if this mutex has a conflict with an inflight tx
- if (t->conflictingMutexRef_.find(mutex) != t->conflictingMutexRef_.end())
+ if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().end())
{
if (txIsIrrevocable || (!t->irrevocable() &&
cm_->allow_lock_to_abort_tx(lockWaitTime, lockAborted, txIsIrrevocable, *t)))
@@ -91,7 +91,7 @@
}
}
- if (0 != txList.size())
+ if (!txList.empty())
{
#if LOGGING_BLOCKS
logFile_ << "----------------------\nbefore locked mutex: " << mutex << endl << endl;
@@ -118,7 +118,7 @@
{
if (0 == thread_id_occurance_in_locked_locks_map(*it))
{
- *threadBlockedLists_.find(*it)->second = false;
+ blocked(*it) = false;
}
}
throw;
Modified: sandbox/stm/boost/stm/detail/latm_dir_full_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/latm_dir_full_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/latm_dir_full_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -72,7 +72,7 @@
// if the lock-aware tm lock set is empty, lock the in-flight trans mutex
// so we can abort all the in-flight transactions
//--------------------------------------------------------------------------
- if (0 == latmLockedLocks_.size())
+ if (latmLockedLocks_.empty())
{
lock_general_access();
lock_inflight_access();
@@ -104,13 +104,7 @@
//-----------------------------------------------------------------------
// block all threads, since we have to unlock the in-flight mutex
//-----------------------------------------------------------------------
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- // no more locked LATM locks, clear everyone
- *threadBlockedLists_.find(iter->first)->second = true;
- //*threadBlockedLists_[iter->first] = true;
- }
+ thread_conflicting_mutexes_set_all(true);
unlock_general_access();
unlock_inflight_access();
@@ -119,7 +113,7 @@
// now we must stall until all in-flight transactions are gone, otherwise
// global memory may still be in an inconsistent state
//-----------------------------------------------------------------------
- while (transactionsInFlight_.size() != 0) { SLEEP(10); }
+ while (!transactionsInFlight_.empty()) { SLEEP(10); }
}
try { latmLockedLocks_.insert(mutex); }
@@ -272,16 +266,11 @@
latmLockedLocks_.erase(mutex);
- if (0 == latmLockedLocks_.size())
+ if (latmLockedLocks_.empty())
{
lock_general_access();
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- // no more locked LATM locks, clear everyone
- *threadBlockedLists_.find(iter->first)->second = false;
- }
+ thread_conflicting_mutexes_set_all(false);
unlock_general_access();
}
Modified: sandbox/stm/boost/stm/detail/latm_dir_tm_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/latm_dir_tm_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/latm_dir_tm_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -81,7 +81,7 @@
// if the lock-aware tm lock set is empty, lock the in-flight trans mutex
// so we can abort all the in-flight transactions
//--------------------------------------------------------------------------
- if (0 == latmLockedLocks_.size())
+ if (latmLockedLocks_.empty())
{
lock_general_access();
lock_inflight_access();
@@ -113,13 +113,7 @@
//-----------------------------------------------------------------------
// block all threads, since we have to unlock the in-flight mutex
//-----------------------------------------------------------------------
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- // no more locked LATM locks, clear everyone
- *threadBlockedLists_.find(iter->first)->second = true;
- //*threadBlockedLists_[iter->first] = true;
- }
+ thread_conflicting_mutexes_set_all(true);
unlock_general_access();
unlock_inflight_access();
@@ -128,7 +122,7 @@
// now we must stall until all in-flight transactions are gone, otherwise
// global memory may still be in an inconsistent state
//-----------------------------------------------------------------------
- while (transactionsInFlight_.size() != 0) { SLEEP(10); }
+ while (!transactionsInFlight_.empty()) { SLEEP(10); }
}
latmLockedLocks_.insert(mutex);
@@ -275,16 +269,11 @@
{
latmLockedLocks_.erase(mutex);
- if (0 == latmLockedLocks_.size())
+ if (latmLockedLocks_.empty())
{
lock_general_access();
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- // no more locked LATM locks, clear everyone
- *threadBlockedLists_.find(iter->first)->second = false;
- }
+ thread_conflicting_mutexes_set_all(false);
unlock_general_access();
}
Modified: sandbox/stm/boost/stm/detail/latm_dir_tx_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/latm_dir_tx_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/latm_dir_tx_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -84,7 +84,7 @@
// if this tx is part of this thread, skip it (it's an LiT)
if (t->threadId_ == THREAD_ID) continue;
- if (t->conflictingMutexRef_.find(mutex) != t->conflictingMutexRef_.end())
+ if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().end())
{
if (txIsIrrevocable || (!t->irrevocable() &&
cm_->allow_lock_to_abort_tx(lockWaitTime, lockAborted, txIsIrrevocable, *t)))
@@ -100,7 +100,7 @@
}
}
- if (0 != txList.size())
+ if (!txList.empty())
{
for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
{
@@ -124,7 +124,7 @@
{
if (0 == thread_id_occurance_in_locked_locks_map(*it))
{
- *threadBlockedLists_.find(*it)->second = false;
+ blocked(*it) = false;
}
}
throw;
@@ -149,7 +149,7 @@
{
transaction *t = (transaction*)*i;
- if (t->conflictingMutexRef_.find(mutex) != t->conflictingMutexRef_.end())
+ if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().end())
{
conflictingTxInFlight = true;
}
Modified: sandbox/stm/boost/stm/detail/latm_general_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/latm_general_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/latm_general_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -68,7 +68,7 @@
while (true)
{
lock_latm_access();
- if (0 == latmLockedLocks_.size()) break;
+ if (latmLockedLocks_.empty()) break;
unlock_latm_access();
SLEEP(10);
}
@@ -80,7 +80,7 @@
//----------------------------------------------------------------------------
inline void boost::stm::transaction::add_to_obtained_locks(Mutex* m)
{
- obtainedLocksRef_.insert(m);
+ obtainedLocksRef().insert(m);
#if LOGGING_BLOCKS
logFile_ << "----------------------\ntx has obtained mutex: " << m << endl << endl;
@@ -91,7 +91,7 @@
//----------------------------------------------------------------------------
inline bool boost::stm::transaction::is_on_obtained_locks_list(Mutex *m)
{
- return obtainedLocksRef_.find(m) != obtainedLocksRef_.end();
+ return obtainedLocksRef().find(m) != obtainedLocksRef().end();
}
@@ -99,32 +99,32 @@
//----------------------------------------------------------------------------
inline bool boost::stm::transaction::is_currently_locked_lock(Mutex *m)
{
- return currentlyLockedLocksRef_.find(m) != currentlyLockedLocksRef_.end();
+ return currentlyLockedLocksRef().find(m) != currentlyLockedLocksRef().end();
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline void boost::stm::transaction::add_to_currently_locked_locks(Mutex* m)
{
- currentlyLockedLocksRef_.insert(m);
+ currentlyLockedLocksRef().insert(m);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline void boost::stm::transaction::remove_from_currently_locked_locks(Mutex *m)
{
- currentlyLockedLocksRef_.erase(m);
+ currentlyLockedLocksRef().erase(m);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline void boost::stm::transaction::clear_latm_obtained_locks()
{
- for (MutexSet::iterator i = obtainedLocksRef_.begin(); i != obtainedLocksRef_.end();)
+ for (MutexSet::iterator i = obtainedLocksRef().begin(); i != obtainedLocksRef().end();)
{
Mutex* m = *i;
- obtainedLocksRef_.erase(i);
- i = obtainedLocksRef_.begin();
+ obtainedLocksRef().erase(i);
+ i = obtainedLocksRef().begin();
#if LOGGING_BLOCKS
logFile_ << "----------------------\nbefore tx release unlocked mutex: " << m << endl << endl;
@@ -141,7 +141,7 @@
unblock_threads_if_locks_are_empty();
- currentlyLockedLocksRef_.clear();
+ currentlyLockedLocksRef().clear();
}
//----------------------------------------------------------------------------
@@ -160,7 +160,6 @@
return true;
}
}
-
return false;
}
@@ -190,19 +189,7 @@
return;
}
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- // if this mutex is found in the transaction's conflicting mutexes
- // list, then allow the thread to make forward progress again
- // by turning its "blocked" but only if it does not appear in the
- // locked_locks_thread_id_map
- if (iter->second->find(mutex) != iter->second->end() &&
- 0 == thread_id_occurance_in_locked_locks_map(iter->first))
- {
- *threadBlockedLists_.find(iter->first)->second = false;
- }
- }
+ thread_conflicting_mutexes_set_all_cnd(mutex, false);
}
//----------------------------------------------------------------------------
@@ -211,19 +198,14 @@
{
#if 0
// if the size is 0, unblock everybody
- if (0 == latmLockedLocksOfThreadMap_.size())
+ if (latmLockedLocksOfThreadMap_.empty())
{
for (ThreadMutexSetContainer::iterator it = threadObtainedLocks_.begin();
it != threadObtainedLocks_.end(); ++it)
{
- if (0 != it->second->size()) return;
- }
-
- for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
- threadConflictingMutexes_.end() != iter; ++iter)
- {
- *threadBlockedLists_[iter->first] = false;
+ if (!it->second->empty()) return;
}
+ thread_conflicting_mutexes_set_all(false);
}
#endif
}
@@ -332,7 +314,7 @@
//----------------------------------------------------------------------------
inline void boost::stm::transaction::must_be_in_conflicting_lock_set(Mutex *inLock)
{
- if (conflictingMutexRef_.find(inLock) == conflictingMutexRef_.end())
+ if (get_tx_conflicting_locks().find(inLock) == get_tx_conflicting_locks().end())
{
throw "lock not in tx conflict lock set, use add_tx_conflicting_lock";
}
@@ -347,8 +329,8 @@
{
var_auto_lock<PLOCK> autol(latm_lock(), general_lock(), inflight_lock(), NULL);
- if (conflictingMutexRef_.find(inLock) != conflictingMutexRef_.end()) return;
- conflictingMutexRef_.insert(inLock);
+ if (get_tx_conflicting_locks().find(inLock) != get_tx_conflicting_locks().end()) return;
+ get_tx_conflicting_locks().insert(inLock);
if (irrevocable()) return;
@@ -367,7 +349,7 @@
inline void boost::stm::transaction::clear_tx_conflicting_locks()
{
lock_general_access();
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
unlock_general_access();
}
@@ -471,37 +453,15 @@
// the currently locked locks is in this tx's conflicting mutex set,
// we need to block this tx
//-----------------------------------------------------------------------
- if (conflictingMutexRef_.find(iter->first) != conflictingMutexRef_.end())
+ if (get_tx_conflicting_locks().find(iter->first) != get_tx_conflicting_locks().end())
{
this->block(); break;
}
}
- //--------------------------------------------------------------------------
- // iterate through all currently locked locks
- //--------------------------------------------------------------------------
- for (ThreadMutexSetContainer::iterator i = threadObtainedLocks_.begin();
- threadObtainedLocks_.end() != i; ++i)
- {
- // if these are locks obtained by this thread (in a parent tx), don't block
- if (i->first == THREAD_ID) continue;
-
- for (MutexSet::iterator j = i->second->begin(); j != i->second->end(); ++j)
- {
- //-----------------------------------------------------------------------
- // iterate through this transaction's conflicting mutex ref - if one of
- // the obtained locked locks is in this tx's conflicting mutex set,
- // we need to block this tx
- //-----------------------------------------------------------------------
- if (conflictingMutexRef_.find(*j) != conflictingMutexRef_.end())
- {
- this->block(); break;
- }
- }
- }
-
+ block_if_conflict_mutex();
- for (MutexSet::iterator k = conflictingMutexRef_.begin(); k != conflictingMutexRef_.end(); ++k)
+ for (MutexSet::iterator k = get_tx_conflicting_locks().begin(); k != get_tx_conflicting_locks().end(); ++k)
{
// if it is locked by our thread, it is ok ... otherwise it is not
MutexThreadMap::iterator l = latmLockedLocksOfThreadMap_.find(*k);
Modified: sandbox/stm/boost/stm/detail/transaction_impl.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/transaction_impl.hpp (original)
+++ sandbox/stm/boost/stm/detail/transaction_impl.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -348,23 +348,21 @@
//--------------------------------------------------------------------------
inline void boost::stm::transaction::lockThreadMutex(size_t threadId)
{
- ThreadMutexContainer::iterator i = threadMutexes_.find(threadId);
- lock(i->second);
+ lock(mutex(threadId));
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
inline void boost::stm::transaction::unlockThreadMutex(size_t threadId)
{
- ThreadMutexContainer::iterator i = threadMutexes_.find(threadId);
- unlock(i->second);
+ unlock(mutex(threadId));
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
inline void boost::stm::transaction::lock_all_mutexes_but_this(size_t threadId)
{
- for (ThreadMutexContainer::iterator i = threadMutexes_.begin();
+ for (ThreadMutexContainer::iterator i = threadMutexes_.begin();
i != threadMutexes_.end(); ++i)
{
if (i->first == threadId) continue;
@@ -392,7 +390,6 @@
{
lock(i->second);
}
-
hasMutex_ = 1;
}
@@ -409,8 +406,7 @@
{
unlock(i->second);
}
-
- hasMutex_ = 0;
+ hasMutex_ = 0;
}
//--------------------------------------------------------------------------
@@ -427,14 +423,43 @@
inline boost::stm::transaction::transaction() :
threadId_(THREAD_ID),
#if USE_SINGLE_THREAD_CONTEXT_MAP
- context_(*threadMemContainer_.find(threadId_)->second),
+////////////////////////////////////////
+ context_(*tss_context_map_.find(threadId_)->second),
+
+#ifdef BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS
+ write_list_ref_(&context_.writeMem),
+ bloomRef_(&context_.bloom),
+ wbloomRef_(&context_.wbloom),
+ newMemoryListRef_(&context_.newMem),
+ deletedMemoryListRef_(&context_.delMem),
+ txTypeRef_(&context_.txType),
+#ifdef USING_SHARED_FORCED_TO_ABORT
+ forcedToAbortRef_(&context_.abort),
+#else
+ forcedToAbortRef_(false),
+#endif
+#endif
+ mutexRef_(threadMutexes_.find(threadId_)->second),
+
+#if PERFORMING_LATM
+ blockedRef_(blocked(threadId_)),
+#endif
+
+#if PERFORMING_LATM
+#if USING_TRANSACTION_SPECIFIC_LATM
+ conflictingMutexRef_(*threadConflictingMutexes_.find(threadId_)->second),
+#endif
+ obtainedLocksRef_(*threadObtainedLocks_.find(threadId_)->second),
+ currentlyLockedLocksRef_(*threadCurrentlyLockedLocks_.find(threadId_)->second),
#endif
+
+////////////////////////////////////////
+#else
+////////////////////////////////////////
#ifndef DISABLE_READ_SETS
readListRef_(*threadReadLists_.find(threadId_)->second),
#endif
-
-#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
- writeListRef_(threadWriteLists_.find(threadId_)->second),
+ write_list_ref_(threadWriteLists_.find(threadId_)->second),
bloomRef_(threadBloomFilterLists_.find(threadId_)->second),
#if PERFORMING_WRITE_BLOOM
wbloomRef_(threadWBloomFilterLists_.find(threadId_)->second),
@@ -448,36 +473,31 @@
#else
forcedToAbortRef_(false),
#endif
-#else // USE_SINGLE_THREAD_CONTEXT_MAP
- writeListRef_(&context_.writeMem),
- wbloomRef_(&context_.wbloom),
- bloomRef_(&context_.bloom),
- newMemoryListRef_(&context_.newMem),
- deletedMemoryListRef_(&context_.delMem),
- txTypeRef_(&context_.txType),
- forcedToAbortRef_(&context_.abort),
-#endif
mutexRef_(threadMutexes_.find(threadId_)->second),
#if PERFORMING_LATM
- blockedRef_(*threadBlockedLists_.find(threadId_)->second),
+ blockedRef_(blocked(threadId_)),
#endif
+
#if PERFORMING_LATM
#if USING_TRANSACTION_SPECIFIC_LATM
conflictingMutexRef_(*threadConflictingMutexes_.find(threadId_)->second),
#endif
-#if PERFORMING_LATM
obtainedLocksRef_(*threadObtainedLocks_.find(threadId_)->second),
currentlyLockedLocksRef_(*threadCurrentlyLockedLocks_.find(threadId_)->second),
#endif
+
+////////////////////////////////////////
#endif
+
+
hasMutex_(0), priority_(0),
state_(e_no_state),
reads_(0),
startTime_(time(NULL))
{
- if (directUpdating_) doIntervalDeletions();
+ if (direct_updating()) doIntervalDeletions();
#if PERFORMING_LATM
while (blocked()) { SLEEP(10) ; }
#endif
@@ -515,7 +535,7 @@
// list, then allow the thread to make forward progress again
// by turning its "blocked" but only if it does not appear in the
// locked_locks_thread_id_map
- o << iter->first << " blocked: " << *threadBlockedLists_[iter->first] << endl;
+ o << iter->first << " blocked: " << blocked(iter->first) << endl;
o << "\t";
for (MutexSet::iterator inner = iter->second->begin(); inner != iter->second->end(); ++inner)
@@ -574,7 +594,7 @@
// restart() interface
//-----------------------------------------------------------------------
#if PERFORMING_COMPOSITION
-#if USING_SHARED_FORCED_TO_ABORT
+#ifdef USING_SHARED_FORCED_TO_ABORT
lock_inflight_access();
if (!otherInFlightTransactionsOfSameThreadNotIncludingThis(this))
{
@@ -702,7 +722,7 @@
// in case this is called multiple times
if (!in_flight()) return;
- if (directUpdating_)
+ if (direct_updating())
{
#if PERFORMING_VALIDATION
validating_direct_end_transaction();
@@ -730,7 +750,7 @@
//-----------------------------------------------------------------------------
inline void boost::stm::transaction::lock_and_abort()
{
- if (directUpdating_)
+ if (direct_updating())
{
bool wasWriting = isWriting() ? true : false;
@@ -859,12 +879,12 @@
{
tx_type(eNormalTx);
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
}
- ++globalClock_;
+ ++global_clock();
return;
}
@@ -920,7 +940,7 @@
invalidating_deferred_commit();
}
- ++globalClock_;
+ ++global_clock();
}
}
@@ -1063,7 +1083,7 @@
{
tx_type(eNormalTx);
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
@@ -1242,7 +1262,7 @@
transactionsInFlight_.erase(this);
}
-#if USING_SHARED_FORCED_TO_ABORT
+#ifdef USING_SHARED_FORCED_TO_ABORT
if (!other_in_flight_same_thread_transactions())
{
unforce_to_abort();
@@ -1291,7 +1311,7 @@
// if I'm the last transaction of this thread, reset abort to false
transactionsInFlight_.erase(this);
-#if USING_SHARED_FORCED_TO_ABORT
+#ifdef USING_SHARED_FORCED_TO_ABORT
if (!other_in_flight_same_thread_transactions())
{
unforce_to_abort();
@@ -1320,7 +1340,7 @@
bookkeeping_.inc_commits();
- if (0 != transactionsInFlight_.size())
+ if (!transactionsInFlight_.empty())
{
forceOtherInFlightTransactionsReadingThisWriteMemoryToAbort();
}
@@ -1336,7 +1356,7 @@
tx_type(eNormalTx);
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
@@ -1414,7 +1434,7 @@
{
static int stalling_ = 0;
- bool wait = stalling_ * stalls_ < globalClock_;
+ bool wait = stalling_ * stalls_ < global_clock();
transaction *stallingOn = NULL;
//int iter = 1;
@@ -1422,7 +1442,7 @@
while (!forceOtherInFlightTransactionsAccessingThisWriteMemoryToAbort(wait, stallingOn))
{
++stalling_;
- size_t local_clock = globalClock_;
+ size_t local_clock = global_clock();
unlock_inflight_access();
unlock_general_access();
@@ -1430,7 +1450,7 @@
for (;;)
{
- while (local_clock == globalClock_)// && sleepTime < maxSleep)
+ while (local_clock == global_clock())// && sleepTime < maxSleep)
{
SLEEP(1);
}
@@ -1449,8 +1469,8 @@
if (transactionsInFlight_.end() == transactionsInFlight_.find(stallingOn))
{
--stalling_;
- wait = stalling_ * stalls_ < globalClock_;
- //std::cout << "stalling : stalls : commits: " << stalling_ << " : " << stalls_ << " : " << globalClock_ << std::endl;
+ wait = stalling_ * stalls_ < global_clock();
+ //std::cout << "stalling : stalls : commits: " << stalling_ << " : " << stalls_ << " : " << global_clock() << std::endl;
//set_priority(priority() + reads());
break;
}
@@ -1481,7 +1501,7 @@
deferredCommitWriteState();
- if (0 != newMemoryList().size())
+ if (!newMemoryList().empty())
{
bookkeeping_.inc_new_mem_commits_by(newMemoryList().size());
deferredCommitTransactionNewMemory();
@@ -1498,7 +1518,7 @@
//-----------------------------------------------------------------------
unlock_all_mutexes();
- if (0 != deletedMemoryList().size())
+ if (!deletedMemoryList().empty())
{
bookkeeping_.inc_del_mem_commits_by(deletedMemoryList().size());
deferredCommitTransactionDeletedMemory();
@@ -1508,7 +1528,7 @@
bookkeeping_.inc_commits();
tx_type(eNormalTx);
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
@@ -1570,7 +1590,7 @@
bookkeeping_.inc_commits();
- if (0 != transactionsInFlight_.size())
+ if (!transactionsInFlight_.empty())
{
forceOtherInFlightTransactionsReadingThisWriteMemoryToAbort();
}
@@ -1582,9 +1602,9 @@
bookkeeping_.inc_new_mem_commits_by(newMemoryList().size());
directCommitTransactionNewMemory();
- txTypeRef_ = eNormalTx;
+ tx_type_ref() = eNormalTx;
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
@@ -1668,7 +1688,7 @@
deferredCommitWriteState();
}
- if (0 != newMemoryList().size())
+ if (!newMemoryList().empty())
{
bookkeeping_.inc_new_mem_commits_by(newMemoryList().size());
deferredCommitTransactionNewMemory();
@@ -1681,7 +1701,7 @@
//-----------------------------------------------------------------------
unlock_all_mutexes_but_this(threadId_);
- if (0 != deletedMemoryList().size())
+ if (!deletedMemoryList().empty())
{
bookkeeping_.inc_del_mem_commits_by(deletedMemoryList().size());
deferredCommitTransactionDeletedMemory();
@@ -1689,9 +1709,9 @@
// finally set the state to committed
bookkeeping_.inc_commits();
- txTypeRef_ = eNormalTx;
+ tx_type_ref() = eNormalTx;
#if PERFORMING_LATM
- conflictingMutexRef_.clear();
+ get_tx_conflicting_locks().clear();
clear_latm_obtained_locks();
#endif
state_ = e_committed;
@@ -1841,7 +1861,7 @@
{
using namespace boost::stm;
- if (deletedMemoryList().size() > 0)
+ if (!deletedMemoryList().empty())
{
var_auto_lock<PLOCK> a(&deletionBufferMutex_, NULL);
deletionBuffer_.insert( std::pair<size_t, MemoryContainerList>
@@ -2125,7 +2145,7 @@
#endif
}
- if (aborted.size() > 0)
+ if (!aborted.empty())
{
// ok, forced to aborts are allowed, do them
for (std::list<transaction*>::iterator k = aborted.begin(); k != aborted.end(); ++k)
Modified: sandbox/stm/boost/stm/detail/tx_ptr.hpp
==============================================================================
--- sandbox/stm/boost/stm/detail/tx_ptr.hpp (original)
+++ sandbox/stm/boost/stm/detail/tx_ptr.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -27,11 +27,11 @@
{
public:
- read_ptr(transaction &t, T const &tx_obj) :
+ inline read_ptr(transaction &t, T const &tx_obj) :
t_(t), tx_ptr_(&const_cast<T&>(t_.read(tx_obj))), written_(false)
{}
- T* get() const
+ const T* get() const
{
if (t_.forced_to_abort())
{
@@ -54,10 +54,10 @@
return tx_ptr_;
}
- T const & operator*() const { return *get(); }
- T const * operator->() const { return get(); }
+ inline T const & operator*() const { return *get(); }
+ inline T const * operator->() const { return get(); }
- transaction &trans() { return t_; }
+ inline transaction &trans() { return t_; }
T* write_ptr()
{
@@ -101,11 +101,11 @@
{
public:
- write_ptr(transaction &t, T & tx_obj) :
+ inline write_ptr(transaction &t, T & tx_obj) :
t_(t), tx_obj_(t_.write(tx_obj))
{}
- T& operator*()
+ inline T& operator*()
{
if (t_.forced_to_abort())
{
@@ -115,7 +115,7 @@
return tx_obj_;
}
- T* operator->()
+ inline T* operator->()
{
if (t_.forced_to_abort())
{
Modified: sandbox/stm/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/boost/stm/transaction.hpp (original)
+++ sandbox/stm/boost/stm/transaction.hpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -1,17 +1,17 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Justin E. Gottchlich 2009.
-// (C) Copyright Vicente J. Botet Escriba 2009.
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
// Distributed under the Boost
-// Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or
+// 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/synchro for documentation.
//
//////////////////////////////////////////////////////////////////////////////
-/* The DRACO Research Group (rogue.colorado.edu/draco) */
+/* The DRACO Research Group (rogue.colorado.edu/draco) */
/*****************************************************************************\
*
* Copyright Notices/Identification of Licensor(s) of
@@ -140,8 +140,11 @@
typedef std::map<size_t, MutexSet* > ThreadMutexSetContainer;
typedef std::map<size_t, boost::stm::bloom_filter*> ThreadBloomFilterList;
- typedef std::map<size_t, boost::stm::bit_vector*> ThreadBitVectorList;
-
+#ifdef BOOST_STM_BLOOM_FILTER_USE_DYNAMIC_BITSET
+typedef std::map<size_t, boost::dynamic_bitset<>*> ThreadBitVectorList;
+#else
+typedef std::map<size_t, boost::stm::bit_vector*> ThreadBitVectorList;
+#endif
typedef std::pair<size_t, int*> thread_bool_pair;
#ifndef MAP_THREAD_BOOL_CONTAINER
typedef boost::stm::vector_map<size_t, int*> ThreadBoolContainer;
@@ -157,6 +160,7 @@
typedef InflightTxes in_flight_transaction_container;
typedef in_flight_transaction_container in_flight_trans_cont;
+#ifdef USE_SINGLE_THREAD_CONTEXT_MAP
struct tx_context
{
MemoryContainerList newMem;
@@ -169,7 +173,8 @@
int abort;
};
- typedef std::map<size_t, tx_context*> ThreadMemContainer;
+ typedef std::map<size_t, tx_context*> tss_context_map_type;
+#endif
//--------------------------------------------------------------------------
// transaction static methods
@@ -177,67 +182,67 @@
static void initialize();
static void initialize_thread();
static void terminate_thread();
- static void contention_manager(base_contention_manager *rhs) { delete cm_; cm_ = rhs; }
- static base_contention_manager* get_contention_manager() { return cm_; }
+ inline static void contention_manager(base_contention_manager *rhs) { delete cm_; cm_ = rhs; }
+ inline static base_contention_manager* get_contention_manager() { return cm_; }
- static void enableLoggingOfAbortAndCommitSetSize() { bookkeeping_.setIsLoggingAbortAndCommitSize(true); }
- static void disableLoggingOfAbortAndCommitSetSize() { bookkeeping_.setIsLoggingAbortAndCommitSize(false); }
+ inline static void enableLoggingOfAbortAndCommitSetSize() { bookkeeping_.setIsLoggingAbortAndCommitSize(true); }
+ inline static void disableLoggingOfAbortAndCommitSetSize() { bookkeeping_.setIsLoggingAbortAndCommitSize(false); }
- static const transaction_bookkeeping & bookkeeping() { return bookkeeping_; }
+ inline static const transaction_bookkeeping & bookkeeping() { return bookkeeping_; }
- static bool early_conflict_detection() { return !directLateWriteReadConflict_ && direct_updating(); }
- static bool late_conflict_detection() { return directLateWriteReadConflict_ || !direct_updating(); }
+ inline static bool early_conflict_detection() { return !directLateWriteReadConflict_ && direct_updating(); }
+ inline static bool late_conflict_detection() { return directLateWriteReadConflict_ || !direct_updating(); }
- static bool enable_dynamic_priority_assignment()
+ inline static bool enable_dynamic_priority_assignment()
{
return dynamicPriorityAssignment_ = true;
}
- static bool disable_dynamic_priority_assignment()
+ inline static bool disable_dynamic_priority_assignment()
{
return dynamicPriorityAssignment_ = false;
}
- static bool using_move_semantics() { return usingMoveSemantics_; }
- static bool using_copy_semantics() { return !using_move_semantics(); }
+ inline static bool using_move_semantics() { return usingMoveSemantics_; }
+ inline static bool using_copy_semantics() { return !using_move_semantics(); }
- static void enable_move_semantics()
+ inline static void enable_move_semantics()
{
- if (!kDracoMoveSemanticsCompiled)
+ if (!kDracoMoveSemanticsCompiled)
throw "move semantics off - rebuild with #define BUILD_MOVE_SEMANTICS 1";
usingMoveSemantics_ = true;
}
- static void disable_move_semantics()
+ inline static void disable_move_semantics()
{
usingMoveSemantics_ = false;
}
- static bool doing_dynamic_priority_assignment()
+ inline static bool doing_dynamic_priority_assignment()
{
return dynamicPriorityAssignment_;
}
static bool do_early_conflict_detection()
{
- if (transactionsInFlight_.size() > 0) return false;
+ if (!transactionsInFlight_.empty()) return false;
if (deferred_updating()) return false;
else return !(directLateWriteReadConflict_ = false);
}
static bool do_late_conflict_detection()
{
- if (transactionsInFlight_.size() > 0) return false;
+ if (!transactionsInFlight_.empty()) return false;
else return directLateWriteReadConflict_ = true;
}
- static std::string consistency_checking_string()
+ inline static std::string consistency_checking_string()
{
if (validating()) return "val";
else return "inval";
}
- static bool validating()
+ inline static bool validating()
{
#ifdef PERFORMING_VALIDATION
return true;
@@ -245,18 +250,20 @@
return false;
}
- static bool invalidating() { return !validating(); }
+ inline static bool invalidating() { return !validating(); }
- static bool direct_updating() { return directUpdating_; }
- static bool deferred_updating() { return !directUpdating_; }
+ inline static bool direct_updating() { return direct_updating_; }
+ inline static bool& direct_updating_ref() { return direct_updating_; }
+ inline static bool deferred_updating() { return !direct_updating_; }
//--------------------------------------------------------------------------
// make all transactions direct as long as no transactions are in flight
//--------------------------------------------------------------------------
static bool do_direct_updating()
{
- if (transactionsInFlight_.size() > 0) return false;
- else return directUpdating_ = true;
+ if (!transactionsInFlight_.empty()) return false;
+ else direct_updating_ref() = true;
+ return true;
}
//--------------------------------------------------------------------------
@@ -264,20 +271,20 @@
//--------------------------------------------------------------------------
static bool do_deferred_updating()
{
- if (transactionsInFlight_.size() > 0) return false;
- else directUpdating_ = false;
+ if (!transactionsInFlight_.empty()) return false;
+ else direct_updating_ref() = false;
return true;
}
static std::string update_policy_string()
{
- return directUpdating_ ? "dir" : "def";
+ return direct_updating() ? "dir" : "def";
}
//--------------------------------------------------------------------------
// Lock Aware Transactional Memory support methods
//--------------------------------------------------------------------------
- static LatmType const latm_protection() { return eLatmType_; }
+ inline static LatmType const latm_protection() { return eLatmType_; }
static std::string const latm_protection_str();
static void do_full_lock_protection();
static void do_tm_lock_protection();
@@ -286,63 +293,63 @@
static bool doing_full_lock_protection();
static bool doing_tm_lock_protection();
static bool doing_tx_lock_protection();
-
-
+
+
#ifdef WIN32
template <typename T>
- static int lock_(T *lock) { throw "unsupported lock type"; }
+ inline static int lock_(T *lock) { throw "unsupported lock type"; }
template <typename T>
- static int trylock_(T *lock) { throw "unsupported lock type"; }
+ inline static int trylock_(T *lock) { throw "unsupported lock type"; }
template <typename T>
- static int unlock_(T *lock) { throw "unsupported lock type"; }
+ inline static int unlock_(T *lock) { throw "unsupported lock type"; }
template <>
- static int lock_(Mutex &lock) { return pthread_lock(&lock); }
+ inline static int lock_(Mutex &lock) { return pthread_lock(&lock); }
template <>
- static int lock_(Mutex *lock) { return pthread_lock(lock); }
+ inline static int lock_(Mutex *lock) { return pthread_lock(lock); }
template <>
- static int trylock_(Mutex &lock) { return pthread_trylock(&lock); }
+ inline static int trylock_(Mutex &lock) { return pthread_trylock(&lock); }
template <>
- static int trylock_(Mutex *lock) { return pthread_trylock(lock); }
+ inline static int trylock_(Mutex *lock) { return pthread_trylock(lock); }
template <>
- static int unlock_(Mutex &lock) { return pthread_unlock(&lock); }
+ inline static int unlock_(Mutex &lock) { return pthread_unlock(&lock); }
template <>
- static int unlock_(Mutex *lock) { return pthread_unlock(lock); }
+ inline static int unlock_(Mutex *lock) { return pthread_unlock(lock); }
#else
- static int lock_(PLOCK &lock) { return pthread_lock(&lock); }
- static int lock_(PLOCK *lock) { return pthread_lock(lock); }
+ inline static int lock_(PLOCK &lock) { return pthread_lock(&lock); }
+ inline static int lock_(PLOCK *lock) { return pthread_lock(lock); }
- static int trylock_(PLOCK &lock) { return pthread_trylock(&lock); }
- static int trylock_(PLOCK *lock) { return pthread_trylock(lock); }
+ inline static int trylock_(PLOCK &lock) { return pthread_trylock(&lock); }
+ inline static int trylock_(PLOCK *lock) { return pthread_trylock(lock); }
- static int unlock_(PLOCK &lock) { return pthread_unlock(&lock); }
- static int unlock_(PLOCK *lock) { return pthread_unlock(lock); }
+ inline static int unlock_(PLOCK &lock) { return pthread_unlock(&lock); }
+ inline static int unlock_(PLOCK *lock) { return pthread_unlock(lock); }
#endif
-
+
static int pthread_lock(Mutex *lock);
static int pthread_trylock(Mutex *lock);
static int pthread_unlock(Mutex *lock);
-
+
//--------------------------------------------------------------------------
#if PERFORMING_LATM
//--------------------------------------------------------------------------
- static void tm_lock_conflict(Mutex &lock)
+ inline static void tm_lock_conflict(Mutex &lock)
{
tm_lock_conflict(&lock);
}
static void tm_lock_conflict(Mutex *lock);
static void clear_tm_conflicting_locks();
- static MutexSet get_tm_conflicting_locks() { return tmConflictingLocks_; }
+ inline static MutexSet get_tm_conflicting_locks() { return tmConflictingLocks_; }
void must_be_in_conflicting_lock_set(Mutex *inLock);
static void must_be_in_tm_conflicting_lock_set(Mutex *inLock);
@@ -350,20 +357,20 @@
#if USING_TRANSACTION_SPECIFIC_LATM
void see_if_tx_must_block_due_to_tx_latm();
- void lock_conflict(Mutex &lock)
+ inline void lock_conflict(Mutex &lock)
{ add_tx_conflicting_lock(&lock); }
- void lock_conflict(Mutex *lock)
+ inline void lock_conflict(Mutex *lock)
{ add_tx_conflicting_lock(lock); }
- void add_tx_conflicting_lock(Mutex &lock)
+ inline void add_tx_conflicting_lock(Mutex &lock)
{
add_tx_conflicting_lock(&lock);
}
void add_tx_conflicting_lock(Mutex *lock);
void clear_tx_conflicting_locks();
- MutexSet get_tx_conflicting_locks() { return conflictingMutexRef_; }
+ //MutexSet get_tx_conflicting_locks() { return conflictingMutexRef_; }
#endif
void add_to_obtained_locks(Mutex* );
@@ -383,7 +390,6 @@
transaction();
~transaction();
- int const forced_to_abort() const { return *forcedToAbortRef_; }
bool check_throw_before_restart() const
{
@@ -407,9 +413,9 @@
return true;
}
- bool committed() const { return state() == e_committed || state() == e_hand_off; }
- bool aborted() const { return state() == e_aborted; }
- bool in_flight() const { return state() == e_in_flight; }
+ inline bool committed() const { return state() == e_committed || state() == e_hand_off; }
+ inline bool aborted() const { return state() == e_aborted; }
+ inline bool in_flight() const { return state() == e_in_flight; }
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
@@ -456,26 +462,27 @@
//
//--------------------------------------------------------------------------
#ifndef DISABLE_READ_SETS
- size_t const read_set_size() const { return readListRef_.size(); }
+ inline size_t const read_set_size() const { return readListRef_.size(); }
#endif
- size_t const writes() const { return writeListRef_->size(); }
- size_t const reads() const { return reads_; }
+ inline size_t const writes() const { return write_list()->size(); }
+ inline size_t const reads() const { return reads_; }
- template <typename T> T const * read_ptr(T const * in)
- {
+ template <typename T> T const * read_ptr(T const * in)
+ {
if (NULL == in) return NULL;
- return &read(*in);
+ return &read(*in);
}
template <typename T> T const & r(T const & in) { return read(in); }
+
//--------------------------------------------------------------------------
- // attempts to find the written value of T based on
+ // attempts to find the written value of T based on
//--------------------------------------------------------------------------
template <typename T>
T* get_written(T const & in)
{
- if (directUpdating_)
+ if (direct_updating())
{
if (in.transaction_thread() == threadId_) return (T*)(&in);
else return NULL;
@@ -491,7 +498,7 @@
//--------------------------------------------------------------------------
template <typename T>
- bool has_been_read(T const & in)
+ inline bool has_been_read(T const & in)
{
#ifndef DISABLE_READ_SETS
ReadContainer::iterator i = readList().find
@@ -507,9 +514,9 @@
//--------------------------------------------------------------------------
template <typename T>
- T const & read(T const & in)
+ inline T const & read(T const & in)
{
- if (directUpdating_)
+ if (direct_updating())
{
#if PERFORMING_VALIDATION
throw "direct updating not implemented for validation yet";
@@ -524,18 +531,18 @@
}
//--------------------------------------------------------------------------
- template <typename T> T* write_ptr(T* in)
- {
+ template <typename T> T* write_ptr(T* in)
+ {
if (NULL == in) return NULL;
- return &write(*in);
+ return &write(*in);
}
template <typename T> T& w(T& in) { return write(in); }
//--------------------------------------------------------------------------
template <typename T>
- T& write(T& in)
+ inline T& write(T& in)
{
- if (directUpdating_)
+ if (direct_updating())
{
#if PERFORMING_VALIDATION
throw "direct updating not implemented for validation yet";
@@ -551,9 +558,9 @@
//--------------------------------------------------------------------------
template <typename T>
- void delete_memory(T &in)
+ inline void delete_memory(T &in)
{
- if (directUpdating_)
+ if (direct_updating())
{
#if PERFORMING_VALIDATION
throw "direct updating not implemented for validation yet";
@@ -576,9 +583,9 @@
template <typename T>
T* new_shared_memory(T*)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
- if (!directUpdating_)
+ if (!direct_updating())
{
deferred_abort(true);
throw aborted_tx("");
@@ -603,9 +610,9 @@
template <typename T>
T* new_memory(T*)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
- if (!directUpdating_)
+ if (!direct_updating())
{
deferred_abort(true);
throw aborted_tx("");
@@ -627,9 +634,9 @@
template <typename T>
T* new_memory_copy(T const &rhs)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
- if (!directUpdating_)
+ if (!direct_updating())
{
deferred_abort(true);
throw aborted_tx("");
@@ -646,10 +653,33 @@
return newNode;
}
+ void throw_if_forced_to_abort_on_new() {
+ if (forced_to_abort()) {
+ if (!direct_updating()) {
+ deferred_abort(true);
+ throw aborted_tx("");
+ }
+#ifndef DELAY_INVALIDATION_DOOMED_TXS_UNTIL_COMMIT
+ cm_->abort_on_new(*this);
+#endif
+ }
+ }
+
+ template <typename T>
+ T* as_new(T *newNode)
+ {
+ //std::auto_ptr<T> newNode(ptr);
+ newNode->transaction_thread(threadId_);
+ newNode->new_memory(1);
+ newMemoryList().push_back(newNode);
+
+ return newNode;
+ }
+
void begin();
bool restart();
- bool restart_if_not_inflight()
+ inline bool restart_if_not_inflight()
{
if (in_flight()) return true;
else return restart();
@@ -658,53 +688,54 @@
void end();
void no_throw_end();
- void force_to_abort()
+ void force_to_abort()
{
// can't abort irrevocable transactions
if (irrevocable()) return;
- *forcedToAbortRef_ = true;
+ forced_to_abort_ref() = true;
#ifdef PERFORMING_COMPOSITION
#ifndef USING_SHARED_FORCED_TO_ABORT
// now set all txes of this threadid that are in-flight to force to abort
- for (InflightTxes::iterator j = transactionsInFlight_.begin();
+ for (InflightTxes::iterator j = transactionsInFlight_.begin();
j != transactionsInFlight_.end(); ++j)
{
transaction *t = (transaction*)*j;
// if this is a parent or child tx, it must abort too
- if (t->threadId_ == this->threadId_) t->forcedToAbortRef_ = true;
+ if (t->threadId_ == this->threadId_) t->forced_to_abort_ref() = true;
}
#endif
#endif
}
- void unforce_to_abort() { *forcedToAbortRef_ = false; }
+ inline void unforce_to_abort() { forced_to_abort_ref() = false; }
//--------------------------------------------------------------------------
void lock_and_abort();
- size_t writeListSize() const { return writeListRef_->size(); }
+ inline size_t writeListSize() const { return write_list()->size(); }
- size_t const &priority() const { return priority_; }
- void set_priority(uint32 const &rhs) const { priority_ = rhs; }
- void raise_priority()
- {
- if (priority_ < size_t(-1))
+ inline size_t const &priority() const { return priority_; }
+ inline void set_priority(uint32 const &rhs) const { priority_ = rhs; }
+ inline void raise_priority()
+ {
+ if (priority_ < size_t(-1))
{
- ++priority_;
+ ++priority_;
}
}
- static InflightTxes const & in_flight_transactions() { return transactionsInFlight_; }
+ inline static InflightTxes const & in_flight_transactions() { return transactionsInFlight_; }
void make_irrevocable();
void make_isolated();
bool irrevocable() const;
bool isolated() const;
- size_t const & thread_id() const { return threadId_; }
+ typedef size_t thread_id_t;
+ inline size_t const & thread_id() const { return threadId_; }
private:
@@ -712,7 +743,7 @@
static std::string outputBlockedThreadsAndLockedLocks();
#endif
//--------------------------------------------------------------------------
- int const& hasLock() const { return hasMutex_; }
+ inline int const& hasLock() const { return hasMutex_; }
void lock_tx();
void unlock_tx();
@@ -725,14 +756,9 @@
static void lock_general_access();
static void unlock_general_access();
- static PLOCK* latm_lock() { return &latmMutex_; }
- static PLOCK* general_lock() { return &transactionMutex_; }
- static PLOCK* inflight_lock() { return &transactionsInFlightMutex_; }
-
-#if PERFORMING_LATM
- void block() { blockedRef_ = true; }
- void unblock() { blockedRef_ = false; }
-#endif
+ inline static PLOCK* latm_lock() { return &latmMutex_; }
+ inline static PLOCK* general_lock() { return &transactionMutex_; }
+ inline static PLOCK* inflight_lock() { return &transactionsInFlightMutex_; }
bool irrevocableTxInFlight();
bool isolatedTxInFlight();
@@ -787,14 +813,14 @@
if (in.transaction_thread() != boost::stm::kInvalidThread)
{
- lockThreadMutex(in.transaction_thread());
-
- ThreadWriteContainer::iterator writeIter =
- threadWriteLists_.find(in.transaction_thread());
-
- WriteContainer::iterator readMem = writeIter->second->find((base_transaction_object*)&in);
-
- if (readMem == writeIter->second->end())
+ //lockThreadMutex(in.transaction_thread());
+ //lock_guard2<Mutex> guard(mutex(in.transaction_thread()));
+ Mutex& m=mutex(in.transaction_thread());
+ stm::lock(m);
+
+ WriteContainer* c = write_lists(in.transaction_thread());
+ WriteContainer::iterator readMem = c->find((base_transaction_object*)&in);
+ if (readMem == c->end())
{
std::cout << "owner did not contain item in write list" << std::endl;
}
@@ -807,7 +833,9 @@
#endif
unlock(&transactionMutex_);
unlock_tx();
- unlockThreadMutex(in.transaction_thread());
+ //unlockThreadMutex(in.transaction_thread());
+ stm::unlock(m);
+ //guard.unlock();
++reads_;
return *static_cast<T*>(readMem->second);
@@ -825,7 +853,7 @@
++reads_;
return in;
}
- else
+ else
{
//--------------------------------------------------------------------
// if we want direct write-read conflict to be done early, bail
@@ -865,13 +893,13 @@
#endif
}
//-----------------------------------------------------------------------
- // first we globally lock all threads before we poke at this global
- // memory - since we need to ensure other threads don't try to
+ // first we globally lock all threads before we poke at this global
+ // memory - since we need to ensure other threads don't try to
// manipulate this at the same time we are going to
//-----------------------------------------------------------------------
lock(&transactionMutex_);
- // we currently don't allow write stealing in direct update. if another
+ // we currently don't allow write stealing in direct update. if another
// tx beat us to the memory, we abort
if (in.transaction_thread() != boost::stm::kInvalidThread)
{
@@ -911,7 +939,7 @@
unlock(&transactionMutex_);
cm_->abort_on_write(*this, (base_transaction_object&)(in));
}
- else
+ else
{
in.transaction_thread(threadId_);
unlock(&transactionMutex_);
@@ -931,28 +959,28 @@
template <typename T>
T const & deferred_read(T const & in)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
deferred_abort(true);
throw aborted_tx("");
}
//----------------------------------------------------------------
- // always check if the writeList size is 0 first, since if it is
+ // always check if the writeList size is 0 first, since if it is
// it can save construction of an iterator and search setup.
//----------------------------------------------------------------
#if PERFORMING_WRITE_BLOOM
- if (0 == writeList().size() ||
- (writeList().size() > 16 &&
+ if (writeList().empty() ||
+ (writeList().size() > 16 &&
!wbloom().exists((size_t)&in))) return insert_and_return_read_memory(in);
#else
- if (0 == writeList().size()) return insert_and_return_read_memory(in);
+ if (writeList().empty()) return insert_and_return_read_memory(in);
#endif
WriteContainer::iterator i = writeList().find
((base_transaction_object*)(&in));
//----------------------------------------------------------------
- // always check to see if read memory is in write list since it is
+ // always check to see if read memory is in write list since it is
// possible to have already written to memory being read now
//----------------------------------------------------------------
if (i == writeList().end()) return insert_and_return_read_memory(in);
@@ -992,13 +1020,13 @@
template <typename T>
T& deferred_write(T& in)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
deferred_abort(true);
throw aborted_tx("");
}
//----------------------------------------------------------------
- // if transactionThread_ is not invalid, then already writing to
+ // if transactionThread_ is not invalid, then already writing to
// non-global memory - so succeed.
//----------------------------------------------------------------
if (in.transaction_thread() != boost::stm::kInvalidThread) return in;
@@ -1036,13 +1064,13 @@
template <typename T>
void deferred_delete_memory(T &in)
{
- if (forced_to_abort())
+ if (forced_to_abort())
{
deferred_abort(true);
throw aborted_tx("");
}
//-----------------------------------------------------------------------
- // if this memory is true memory, not transactional, we add it to our
+ // if this memory is true memory, not transactional, we add it to our
// deleted list and we're done
//-----------------------------------------------------------------------
if (in.transaction_thread() != boost::stm::kInvalidThread)
@@ -1054,7 +1082,7 @@
}
//-----------------------------------------------------------------------
// this isn't real memory, it's transactional memory. But the good news is,
- // the real version has to be in our write list somewhere, find it, add
+ // the real version has to be in our write list somewhere, find it, add
// both items to the deletion list and exit
//-----------------------------------------------------------------------
else
@@ -1082,9 +1110,9 @@
void verifyWrittenMemoryIsValidWithGlobalMemory();
//--------------------------------------------------------------------------
- void abort() throw() { directUpdating_ ? direct_abort() : deferred_abort(); }
- void deferred_abort(bool const &alreadyRemovedFromInflightList = false) throw();
- void direct_abort(bool const &alreadyRemovedFromInflightList = false) throw();
+ inline void abort() throw() { direct_updating() ? direct_abort() : deferred_abort(); }
+ inline void deferred_abort(bool const &alreadyRemovedFromInflightList = false) throw();
+ inline void direct_abort(bool const &alreadyRemovedFromInflightList = false) throw();
//--------------------------------------------------------------------------
void validating_deferred_commit();
@@ -1100,42 +1128,19 @@
//--------------------------------------------------------------------------
// side-effect: this unlocks all mutexes including its own. this is a slight
- // optimization over unlock_all_mutexes_but_this() as it doesn't have an
- // additional "if" to slow down performance. however, as it will be
+ // optimization over unlock_all_mutexes_but_this() as it doesn't have an
+ // additional "if" to slow down performance. however, as it will be
// releasing its own mutex, it must reset hasMutex_
//--------------------------------------------------------------------------
void lock_all_mutexes();
void unlock_all_mutexes();
- transaction_state const & state() const { return state_; }
-#if PERFORMING_LATM
- int const blocked() const { return blockedRef_; }
-#endif
- WriteContainer& writeList() { return *writeListRef_; }
#ifndef DISABLE_READ_SETS
- ReadContainer& readList() { return readListRef_; }
-#endif
-
- bloom_filter& bloom() { return *bloomRef_; }
-#if PERFORMING_WRITE_BLOOM
- bloom_filter& wbloom() { return *wbloomRef_; }
- //bit_vector& sm_wbv() { return sm_wbv_; }
+ inline bool isReading() const { return !readListRef_.empty(); }
#endif
-
-#ifndef DISABLE_READ_SETS
- bool isReading() const { return 0 != readListRef_.size(); }
-#endif
- bool isWriting() const { return 0 != writeListRef_->size(); }
- bool is_only_reading() const { return !isWriting(); }
-
- MemoryContainerList& newMemoryList() { return *newMemoryListRef_; }
- MemoryContainerList& deletedMemoryList() { return *deletedMemoryListRef_; }
-
- TxType const tx_type() const { return *txTypeRef_; }
- void tx_type(TxType const &rhs) { *txTypeRef_ = rhs; }
-
- Mutex * mutex() { return mutexRef_; }
+ inline bool isWriting() const { return !write_list()->empty(); }
+ inline bool is_only_reading() const { return !isWriting(); }
// undefined and hidden - never allow these - bad things would happen
transaction& operator=(transaction const &);
@@ -1280,17 +1285,14 @@
static transaction_bookkeeping bookkeeping_;
static base_contention_manager *cm_;
-#if PERFORMING_LATM
- static ThreadMutexSetContainer threadConflictingMutexes_;
- static ThreadMutexSetContainer threadObtainedLocks_;
- static ThreadMutexSetContainer threadCurrentlyLockedLocks_;
-#endif
- static ThreadMutexContainer threadMutexes_;
- static ThreadBoolContainer threadBlockedLists_;
#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
- static ThreadWriteContainer threadWriteLists_;
+ static ThreadWriteContainer threadWriteLists_;
+ inline static WriteContainer* write_lists(thread_id_t id) {
+ ThreadWriteContainer::iterator iter = threadWriteLists_.find(id);
+ return iter->second;
+ }
static ThreadReadContainer threadReadLists_;
static ThreadBloomFilterList threadBloomFilterLists_;
static ThreadBloomFilterList threadWBloomFilterLists_;
@@ -1299,12 +1301,18 @@
static ThreadTxTypeContainer threadTxTypeLists_;
static ThreadBoolContainer threadForcedToAbortLists_;
#else
- static ThreadMemContainer threadMemContainer_;
+ static tss_context_map_type tss_context_map_;
+ inline static WriteContainer* write_lists(thread_id_t thid) {
+ tss_context_map_type::iterator iter = tss_context_map_.find(thid);
+ return &(iter->second->writeMem);
+ }
#endif
//--------------------------------------------------------------------------
- static bool directUpdating_;
- static size_t globalClock_;
+ static bool direct_updating_;
+ static size_t global_clock_;
+ inline static size_t& global_clock() {return global_clock_;}
+
static size_t stalls_;
//--------------------------------------------------------------------------
@@ -1321,23 +1329,180 @@
//--------------------------------------------------------------------------
// ******** WARNING ******** MOVING threadId_ WILL BREAK TRANSACTION.
- // threadId_ MUST ALWAYS THE FIRST MEMBER OF THIS CLASS. THE MEMBER
+ // threadId_ MUST ALWAYS THE FIRST MEMBER OF THIS CLASS. THE MEMBER
// INITIALIZATION IS ORDER DEPENDENT UPON threadId_!!
// ******** WARNING ******** MOVING threadId_ WILL BREAK TRANSACTION
//--------------------------------------------------------------------------
size_t threadId_;
-
-#ifdef USE_SINGLE_THREAD_CONTEXT_MAP
- tx_context &context_;
-#endif
//--------------------------------------------------------------------------
// ******** WARNING ******** MOVING threadId_ WILL BREAK TRANSACTION.
- // threadId_ MUST ALWAYS THE FIRST MEMBER OF THIS CLASS. THE MEMBER
+ // threadId_ MUST ALWAYS THE FIRST MEMBER OF THIS CLASS. THE MEMBER
// INITIALIZATION IS ORDER DEPENDENT UPON threadId_!!
// ******** WARNING ******** MOVING threadId_ WILL BREAK TRANSACTION
//--------------------------------------------------------------------------
- mutable WriteContainer *writeListRef_;
+
+#ifdef USE_SINGLE_THREAD_CONTEXT_MAP
+ tx_context &context_;
+
+#ifdef BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS
+ mutable WriteContainer *write_list_ref_;
+ inline WriteContainer *write_list() {return write_list_ref_;}
+ inline const WriteContainer *write_list() const {return write_list_ref_;}
+
+ mutable bloom_filter *bloomRef_;
+#if PERFORMING_WRITE_BLOOM
+ mutable bloom_filter *wbloomRef_;
+ //mutable bit_vector &sm_wbv_;
+#endif
+
+ inline bloom_filter& bloom() { return *bloomRef_; }
+#if PERFORMING_WRITE_BLOOM
+ inline bloom_filter& wbloom() { return *wbloomRef_; }
+ //bit_vector& sm_wbv() { return sm_wbv_; }
+#endif
+ MemoryContainerList *newMemoryListRef_;
+ inline MemoryContainerList& newMemoryList() { return *newMemoryListRef_; }
+
+ MemoryContainerList *deletedMemoryListRef_;
+ inline MemoryContainerList& deletedMemoryList() { return *deletedMemoryListRef_; }
+
+ TxType *txTypeRef_;
+ inline TxType const tx_type() const { return *txTypeRef_; }
+ inline void tx_type(TxType const &rhs) { *txTypeRef_ = rhs; }
+ inline TxType& tx_type_ref() { return *txTypeRef_; }
+#else // BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS
+ inline WriteContainer *write_list() {return &context_.writeMem;}
+ inline const WriteContainer *write_list() const {return &context_.writeMem;}
+
+ inline bloom_filter& bloom() { return context_.bloom; }
+#if PERFORMING_WRITE_BLOOM
+ inline bloom_filter& wbloom() { return context_.wbloom; }
+ //bit_vector& sm_wbv() { return sm_wbv_; }
+#endif
+ inline MemoryContainerList& newMemoryList() { return context_.newMem; }
+ inline MemoryContainerList& deletedMemoryList() { return context_.delMem; }
+ inline TxType const tx_type() const { return context_.txType; }
+ inline void tx_type(TxType const &rhs) { context_.txType = rhs; }
+ inline TxType& tx_type_ref() { return context_.txType; }
+#endif
+
+#ifdef USING_SHARED_FORCED_TO_ABORT
+#ifdef BOOST_STM_TX_CONTAINS_REFERENCES_TO_TSS_FIELDS
+ int *forcedToAbortRef_;
+public:
+ inline int const forced_to_abort() const { return *forcedToAbortRef_; }
+private:
+ inline int& forced_to_abort_ref() { return *forcedToAbortRef_; }
+#else
+public:
+ inline int const forced_to_abort() const { return context_.abort; }
+private:
+ inline int& forced_to_abort_ref() { return context_.abort; }
+#endif
+#else
+ int forcedToAbortRef_;
+public:
+ inline int const forced_to_abort() const { return forcedToAbortRef_; }
+private:
+ inline int& forced_to_abort_ref() { return forcedToAbortRef_; }
+#endif
+
+ static ThreadMutexContainer threadMutexes_;
+ Mutex *mutexRef_;
+ inline Mutex * mutex() { return mutexRef_; }
+ inline static Mutex& mutex(thread_id_t id) {
+ ThreadMutexContainer::iterator i = threadMutexes_.find(id);
+ return *(i->second);
+ }
+
+ static ThreadBoolContainer threadBlockedLists_;
+#if PERFORMING_LATM
+ int &blockedRef_;
+ inline void block() { blockedRef_ = true; }
+ inline void unblock() { blockedRef_ = false; }
+ inline int const blocked() const { return blockedRef_; }
+ inline static int& blocked(thread_id_t id) { return *threadBlockedLists_.find(id)->second; }
+#endif
+
+
+#if PERFORMING_LATM
+ static ThreadMutexSetContainer threadConflictingMutexes_;
+ static ThreadMutexSetContainer threadObtainedLocks_;
+ static ThreadMutexSetContainer threadCurrentlyLockedLocks_;
+
+#if USING_TRANSACTION_SPECIFIC_LATM
+ MutexSet &conflictingMutexRef_;
+ inline MutexSet& get_tx_conflicting_locks() { return conflictingMutexRef_; }
+ inline MutexSet& get_tx_conflicting_locks(thread_id_t id) {
+ return *threadConflictingMutexes_.find(threadId_)->second;
+ }
+ static void thread_conflicting_mutexes_set_all(int b) {
+ for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
+ threadConflictingMutexes_.end() != iter; ++iter)
+ {
+ blocked(iter->first) = b;
+ }
+ }
+
+ static void thread_conflicting_mutexes_set_all_cnd(Mutex *mutex, int b) {
+ for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
+ threadConflictingMutexes_.end() != iter; ++iter)
+ {
+ // if this mutex is found in the transaction's conflicting mutexes
+ // list, then allow the thread to make forward progress again
+ // by turning its "blocked" but only if it does not appear in the
+ // locked_locks_thread_id_map
+ if (iter->second->find(mutex) != iter->second->end() &&
+ 0 == thread_id_occurance_in_locked_locks_map(iter->first))
+ {
+ blocked(iter->first) = false;
+ }
+ }
+ }
+#endif
+
+ MutexSet &obtainedLocksRef_;
+ inline MutexSet &obtainedLocksRef() {return obtainedLocksRef_;}
+ inline static MutexSet &obtainedLocksRef(thread_id_t id) {return *threadObtainedLocks_.find(id)->second;}
+
+ void block_if_conflict_mutex() {
+ //--------------------------------------------------------------------------
+ // iterate through all currently locked locks
+ //--------------------------------------------------------------------------
+ for (ThreadMutexSetContainer::iterator i = threadObtainedLocks_.begin();
+ threadObtainedLocks_.end() != i; ++i)
+ {
+ // if these are locks obtained by this thread (in a parent tx), don't block
+ if (i->first == THREAD_ID) continue;
+
+ for (MutexSet::iterator j = i->second->begin(); j != i->second->end(); ++j)
+ {
+ //-----------------------------------------------------------------------
+ // iterate through this transaction's conflicting mutex ref - if one of
+ // the obtained locked locks is in this tx's conflicting mutex set,
+ // we need to block this tx
+ //-----------------------------------------------------------------------
+ if (get_tx_conflicting_locks().find(*j) != get_tx_conflicting_locks().end())
+ {
+ this->block(); break;
+ }
+ }
+ }
+ }
+
+ MutexSet ¤tlyLockedLocksRef_;
+ inline MutexSet ¤tlyLockedLocksRef() {return currentlyLockedLocksRef_;}
+ inline static MutexSet ¤tlyLockedLocksRef(thread_id_t id) {return *threadCurrentlyLockedLocks_.find(id)->second;}
+#endif
+
+////////////////////////////////////////
+#else // USE_SINGLE_THREAD_CONTEXT_MAP
+////////////////////////////////////////
+
+ mutable WriteContainer *write_list_ref_;
+ inline WriteContainer *write_list() {return write_list_ref_;}
+ inline const WriteContainer *write_list() const {return write_list_ref_;}
#ifndef DISABLE_READ_SETS
mutable ReadContainer &readListRef_;
#endif
@@ -1347,35 +1512,148 @@
//mutable bit_vector &sm_wbv_;
#endif
+ inline bloom_filter& bloom() { return *bloomRef_; }
+#if PERFORMING_WRITE_BLOOM
+ inline bloom_filter& wbloom() { return *wbloomRef_; }
+ //bit_vector& sm_wbv() { return sm_wbv_; }
+#endif
MemoryContainerList *newMemoryListRef_;
+ inline MemoryContainerList& newMemoryList() { return *newMemoryListRef_; }
+
MemoryContainerList *deletedMemoryListRef_;
+ inline MemoryContainerList& deletedMemoryList() { return *deletedMemoryListRef_; }
+
TxType *txTypeRef_;
+ inline TxType const tx_type() const { return *txTypeRef_; }
+ inline void tx_type(TxType const &rhs) { *txTypeRef_ = rhs; }
+ inline TxType& tx_type_ref() { return *txTypeRef_; }
-#if USING_SHARED_FORCED_TO_ABORT
+#ifdef USING_SHARED_FORCED_TO_ABORT
int *forcedToAbortRef_;
+public:
+ inline int const forced_to_abort() const { return *forcedToAbortRef_; }
+private:
+ inline int& forced_to_abort_ref() { return *forcedToAbortRef_; }
#else
int forcedToAbortRef_;
+public:
+ inline int const forced_to_abort() const { return forcedToAbortRef_; }
+private:
+ inline int& forced_to_abort_ref() { return forcedToAbortRef_; }
#endif
- Mutex *mutexRef_;
+ static ThreadMutexContainer threadMutexes_;
+ Mutex *mutexRef_;
+ inline Mutex * mutex() { return mutexRef_; }
+ inline static Mutex& mutex(thread_id_t id) {
+ ThreadMutexContainer::iterator i = threadMutexes_.find(id);
+ return *(i->second);
+ }
+ static ThreadBoolContainer threadBlockedLists_;
#if PERFORMING_LATM
int &blockedRef_;
+ inline void block() { blockedRef_ = true; }
+ inline void unblock() { blockedRef_ = false; }
+ inline int const blocked() const { return blockedRef_; }
+ inline static int& blocked(thread_id_t id) { return *threadBlockedLists_.find(id)->second; }
#endif
+
#if PERFORMING_LATM
+ static ThreadMutexSetContainer threadConflictingMutexes_;
+ static ThreadMutexSetContainer threadObtainedLocks_;
+ static ThreadMutexSetContainer threadCurrentlyLockedLocks_;
+
#if USING_TRANSACTION_SPECIFIC_LATM
- MutexSet &conflictingMutexRef_;
+ MutexSet &conflictingMutexRef_;
+ inline MutexSet& get_tx_conflicting_locks() { return conflictingMutexRef_; }
+ inline MutexSet& get_tx_conflicting_locks(thread_id_t id) {
+ return *threadConflictingMutexes_.find(threadId_)->second;
+ }
+ static void thread_conflicting_mutexes_set_all(int b) {
+ for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
+ threadConflictingMutexes_.end() != iter; ++iter)
+ {
+ blocked(iter->first) = b;
+ }
+ }
+
+ static void thread_conflicting_mutexes_set_all_cnd(Mutex *mutex, int b) {
+ for (ThreadMutexSetContainer::iterator iter = threadConflictingMutexes_.begin();
+ threadConflictingMutexes_.end() != iter; ++iter)
+ {
+ // if this mutex is found in the transaction's conflicting mutexes
+ // list, then allow the thread to make forward progress again
+ // by turning its "blocked" but only if it does not appear in the
+ // locked_locks_thread_id_map
+ if (iter->second->find(mutex) != iter->second->end() &&
+ 0 == thread_id_occurance_in_locked_locks_map(iter->first))
+ {
+ blocked(iter->first) = false;
+ }
+ }
+ }
#endif
- MutexSet &obtainedLocksRef_;
+
+ MutexSet &obtainedLocksRef_;
+ inline MutexSet &obtainedLocksRef() {return obtainedLocksRef_;}
+ inline static MutexSet &obtainedLocksRef(thread_id_t id) {return *threadObtainedLocks_.find(id)->second;}
+
+ void block_if_conflict_mutex() {
+ //--------------------------------------------------------------------------
+ // iterate through all currently locked locks
+ //--------------------------------------------------------------------------
+ for (ThreadMutexSetContainer::iterator i = threadObtainedLocks_.begin();
+ threadObtainedLocks_.end() != i; ++i)
+ {
+ // if these are locks obtained by this thread (in a parent tx), don't block
+ if (i->first == THREAD_ID) continue;
+
+ for (MutexSet::iterator j = i->second->begin(); j != i->second->end(); ++j)
+ {
+ //-----------------------------------------------------------------------
+ // iterate through this transaction's conflicting mutex ref - if one of
+ // the obtained locked locks is in this tx's conflicting mutex set,
+ // we need to block this tx
+ //-----------------------------------------------------------------------
+ if (get_tx_conflicting_locks().find(*j) != get_tx_conflicting_locks().end())
+ {
+ this->block(); break;
+ }
+ }
+ }
+ }
+
+
+
MutexSet ¤tlyLockedLocksRef_;
+ inline MutexSet ¤tlyLockedLocksRef() {return currentlyLockedLocksRef_;}
+ inline static MutexSet ¤tlyLockedLocksRef(thread_id_t id) {return *threadCurrentlyLockedLocks_.find(id)->second;}
#endif
+
+
+////////////////////////////////////////
+#endif
+
+
+
+ // transaction specific data
int hasMutex_;
mutable size_t priority_;
transaction_state state_;
size_t reads_;
-
mutable size_t startTime_;
+
+ inline transaction_state const & state() const { return state_; }
+
+ inline WriteContainer& writeList() { return *write_list(); }
+#ifndef DISABLE_READ_SETS
+ inline ReadContainer& readList() { return readListRef_; }
+#endif
+
+
+
};
#if 0
@@ -1407,7 +1685,7 @@
// optimize the if away
//---------------------------------------------------------------------------
#define use_atomic(T) if (0 != rand()+1) for (transaction T; !T.committed() && T.restart(); T.end())
-#define try_atomic(T) if (0 != rand()+1) for (transaction T; !T.committed() && T.restart(); T.no_throw_end()) try
+#define try_atomic(T) if (0 != rand()+1) for (transaction T; !T.committed() && T.restart(); T.no_throw_end()) try
#define atomic(T) if (0 != rand()+1) for (transaction T; !T.committed() && T.check_throw_before_restart() && T.restart_if_not_inflight(); T.no_throw_end()) try
Modified: sandbox/stm/libs/stm/doc/appendices.qbk
==============================================================================
--- sandbox/stm/libs/stm/doc/appendices.qbk (original)
+++ sandbox/stm/libs/stm/doc/appendices.qbk 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -41,7 +41,7 @@
* [*DONE] Replace Sleep by boost::this_thread::sleep
* [*DONE] Replace pthread_mutex by boost::mutex
* Replace THREAD_ID by boost::thread_id
-* Replace auto_lock by boost::interthreads::unique_locker and redefine use_lock macros
+* Replace auto_lock by boost::synchro::unique_locker and redefine use_lock macros
* Redifine var_auto_lock
* Add an scoped guard for transaction::lock/unlock
* use lock_guard when lock/unlock
Modified: sandbox/stm/libs/stm/src/transaction.cpp
==============================================================================
--- sandbox/stm/libs/stm/src/transaction.cpp (original)
+++ sandbox/stm/libs/stm/src/transaction.cpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -47,11 +47,11 @@
transaction::MutexSet transaction::tmConflictingLocks_;
transaction::DeletionBuffer transaction::deletionBuffer_;
-size_t transaction::globalClock_ = 0;
+size_t transaction::global_clock_ = 0;
size_t transaction::stalls_ = 0;
bool transaction::dynamicPriorityAssignment_ = false;
-bool transaction::directUpdating_ = false;
+bool transaction::direct_updating_ = false;
bool transaction::directLateWriteReadConflict_ = false;
bool transaction::usingMoveSemantics_ = false;
@@ -88,7 +88,8 @@
// new ExceptAndBackOffOnAbortNoticeCM(5, 2, 10);
transaction_bookkeeping transaction::bookkeeping_;
-transaction::ThreadMutexContainer transaction::threadMutexes_;
+
+#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
#if PERFORMING_LATM
#if USING_TRANSACTION_SPECIFIC_LATM
transaction::ThreadMutexSetContainer transaction::threadConflictingMutexes_;
@@ -96,8 +97,6 @@
transaction::ThreadMutexSetContainer transaction::threadObtainedLocks_;
transaction::ThreadMutexSetContainer transaction::threadCurrentlyLockedLocks_;
#endif
-
-#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
transaction::ThreadWriteContainer transaction::threadWriteLists_;
transaction::ThreadReadContainer transaction::threadReadLists_;
//transaction::ThreadEagerReadContainer transaction::threadEagerReadLists_;
@@ -107,12 +106,26 @@
transaction::ThreadBloomFilterList transaction::threadBloomFilterLists_;
transaction::ThreadBloomFilterList transaction::threadWBloomFilterLists_;
transaction::ThreadBoolContainer transaction::threadForcedToAbortLists_;
+
+transaction::ThreadMutexContainer transaction::threadMutexes_;
+transaction::ThreadBoolContainer transaction::threadBlockedLists_;
#else
-transaction::ThreadMemContainer transaction::threadMemContainer_;
+
+#if PERFORMING_LATM
+#if USING_TRANSACTION_SPECIFIC_LATM
+transaction::ThreadMutexSetContainer transaction::threadConflictingMutexes_;
+#endif
+transaction::ThreadMutexSetContainer transaction::threadObtainedLocks_;
+transaction::ThreadMutexSetContainer transaction::threadCurrentlyLockedLocks_;
#endif
+transaction::ThreadMutexContainer transaction::threadMutexes_;
transaction::ThreadBoolContainer transaction::threadBlockedLists_;
+transaction::tss_context_map_type transaction::tss_context_map_;
+#endif
+
+
///////////////////////////////////////////////////////////////////////////////
// static initialization method - must be called before the transaction
// class is used because it initializes our transactionMutex_ which is used
@@ -150,6 +163,7 @@
size_t threadId = THREAD_ID;
#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
+/////////////////////////////////
ThreadWriteContainer::iterator writeIter = threadWriteLists_.find(threadId);
ThreadReadContainer::iterator readIter = threadReadLists_.find(threadId);
ThreadBloomFilterList::iterator bloomIter = threadBloomFilterLists_.find(threadId);
@@ -158,14 +172,9 @@
ThreadMemoryContainerList::iterator newMemIter = threadNewMemoryLists_.find(threadId);
ThreadMemoryContainerList::iterator deletedMemIter = threadDeletedMemoryLists_.find(threadId);
ThreadTxTypeContainer::iterator txTypeIter = threadTxTypeLists_.find(threadId);
- ThreadBoolContainer::iterator abortIter = threadForcedToAbortLists_.find(threadId);
-#else
- ThreadMemContainer::iterator memIter = threadMemContainer_.find(threadId);
-#endif
-
- ThreadBoolContainer::iterator blockedIter = threadBlockedLists_.find(threadId);
+ ThreadBoolContainer::iterator abortIter = threadForcedToAbortLists_.find(threadId);
ThreadMutexContainer::iterator mutexIter = threadMutexes_.find(threadId);
-
+ ThreadBoolContainer::iterator blockedIter = threadBlockedLists_.find(threadId);
#if PERFORMING_LATM
#if USING_TRANSACTION_SPECIFIC_LATM
ThreadMutexSetContainer::iterator conflictingMutexIter = threadConflictingMutexes_.find(threadId);
@@ -188,8 +197,6 @@
}
#endif
-
-#ifndef USE_SINGLE_THREAD_CONTEXT_MAP
if (threadWriteLists_.end() == writeIter)
{
threadWriteLists_[threadId] = new WriteContainer();
@@ -232,21 +239,51 @@
{
threadForcedToAbortLists_.insert(thread_bool_pair(threadId, new int(0)));
}
+
+ if (threadMutexes_.end() == mutexIter)
+ {
+ Mutex *mutex = new Mutex;
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+#if WIN32
+ *mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+ pthread_mutex_init(mutex, NULL);
+#endif
+ threadMutexes_.insert(thread_mutex_pair(threadId, mutex));
+ mutexIter = threadMutexes_.find(threadId);
+ }
+
+ if (threadBlockedLists_.end() == blockedIter)
+ {
+ threadBlockedLists_.insert(thread_bool_pair(threadId, new int(0)));
+ }
+
+//////////////////////////////////////
#else
- if (threadMemContainer_.end() == memIter)
+
+ ThreadMutexContainer::iterator mutexIter = threadMutexes_.find(threadId);
+ ThreadBoolContainer::iterator blockedIter = threadBlockedLists_.find(threadId);
+#if PERFORMING_LATM
+#if USING_TRANSACTION_SPECIFIC_LATM
+ ThreadMutexSetContainer::iterator conflictingMutexIter = threadConflictingMutexes_.find(threadId);
+ if (threadConflictingMutexes_.end() == conflictingMutexIter)
{
- threadMemContainer_.insert(std::pair<size_t, tx_context*>(threadId, new tx_context));
- memIter = threadMemContainer_.find(threadId);
- memIter->second->txType = eNormalTx;
+ threadConflictingMutexes_[threadId] = new MutexSet;
}
#endif
+ ThreadMutexSetContainer::iterator obtainedLocksIter = threadObtainedLocks_.find(threadId);
+ if (threadObtainedLocks_.end() == obtainedLocksIter)
+ {
+ threadObtainedLocks_[threadId] = new MutexSet;
+ }
-
- if (threadBlockedLists_.end() == blockedIter)
+ ThreadMutexSetContainer::iterator currentlyLockedLocksIter = threadCurrentlyLockedLocks_.find(threadId);
+ if (threadCurrentlyLockedLocks_.end() == currentlyLockedLocksIter)
{
- threadBlockedLists_.insert(thread_bool_pair(threadId, new int(0)));
+ threadCurrentlyLockedLocks_[threadId] = new MutexSet;
}
+#endif
if (threadMutexes_.end() == mutexIter)
{
@@ -260,6 +297,21 @@
threadMutexes_.insert(thread_mutex_pair(threadId, mutex));
mutexIter = threadMutexes_.find(threadId);
}
+
+ if (threadBlockedLists_.end() == blockedIter)
+ {
+ threadBlockedLists_.insert(thread_bool_pair(threadId, new int(0)));
+ }
+
+ tss_context_map_type::iterator memIter = tss_context_map_.find(threadId);
+ if (tss_context_map_.end() == memIter)
+ {
+ tss_context_map_.insert(std::pair<size_t, tx_context*>(threadId, new tx_context));
+ memIter = tss_context_map_.find(threadId);
+ memIter->second->txType = eNormalTx;
+ }
+
+#endif
unlock_general_access();
}
@@ -301,15 +353,6 @@
threadDeletedMemoryLists_.erase(deletedMemIter);
threadTxTypeLists_.erase(txTypeIter);
threadForcedToAbortLists_.erase(abortIter);
-#else
- ThreadMemContainer::iterator memIter = threadMemContainer_.find(threadId);
- delete memIter->second;
- threadMemContainer_.erase(memIter);
-#endif
-
- ThreadBoolContainer::iterator blockedIter = threadBlockedLists_.find(threadId);
- delete blockedIter->second;
- threadBlockedLists_.erase(blockedIter);
ThreadMutexContainer::iterator mutexIter = threadMutexes_.find(threadId);
#ifndef BOOST_STM_USE_BOOST_MUTEX
@@ -326,25 +369,15 @@
{
transaction* t = *i;
- t->mutexRef_ = threadMutexes_.find(t->threadId_)->second;
+ t->mutexRef_ = &mutex(t->threadId_);
}
}
#endif
-#ifndef MAP_THREAD_BOOL_CONTAINER
- {
- // realign all in-flight transactions so they are accessing the correct mutex
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction* t = *i;
+ ThreadBoolContainer::iterator blockedIter = threadBlockedLists_.find(threadId);
+ delete blockedIter->second;
+ threadBlockedLists_.erase(blockedIter);
- t->forcedToAbortRef_ = threadForcedToAbortLists_.find(t->threadId_)->second;
- t->blockedRef_ = threadBlockedLists_.find(t->threadId_)->second;
- }
- }
-#endif
-
#if PERFORMING_LATM
#if USING_TRANSACTION_SPECIFIC_LATM
ThreadMutexSetContainer::iterator conflictingMutexIter = threadConflictingMutexes_.find(threadId);
@@ -361,6 +394,31 @@
threadCurrentlyLockedLocks_.erase(currentlyLockedLocksIter);
#endif
+
+#else
+ tss_context_map_type::iterator memIter = tss_context_map_.find(threadId);
+ delete memIter->second;
+ tss_context_map_.erase(memIter);
+#endif
+
+
+
+
+#ifndef MAP_THREAD_BOOL_CONTAINER
+ {
+ // realign all in-flight transactions so they are accessing the correct mutex
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
+ {
+ transaction* t = *i;
+
+ t->forcedToAbortRef_ = threadForcedToAbortLists_.find(t->threadId_)->second;
+ t->blockedRef_ = blocked(t->threadId_);
+ }
+ }
+#endif
+
+
unlock_inflight_access();
unlock_general_access();
}
Modified: sandbox/stm/libs/stm/test/smart.cpp
==============================================================================
--- sandbox/stm/libs/stm/test/smart.cpp (original)
+++ sandbox/stm/libs/stm/test/smart.cpp 2009-05-30 10:03:31 EDT (Sat, 30 May 2009)
@@ -19,8 +19,8 @@
using namespace boost::stm;
-static int kMaxOuterLoops = 10000;
-static int kMaxInnerLoops = 50000;
+static int kMaxOuterLoops = 2*1000;
+static int kMaxInnerLoops = 2*5000;
static native_trans<int> txInt = 0, txInt2, txInt3 = 0;
@@ -150,7 +150,7 @@
//test_2();
//test_parent();
- int const kMaxTestLoops = 4;
+ int const kMaxTestLoops = 1;
for (int i = 0; i < kMaxTestLoops; ++i)
{
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