Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57303 - sandbox/stm/branches/vbe/boost/stm/detail
From: vicente.botet_at_[hidden]
Date: 2009-11-03 07:48:59


Author: viboes
Date: 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
New Revision: 57303
URL: http://svn.boost.org/trac/boost/changeset/57303

Log:
TBoost.STM vbe: Cleanup on the use scoped locks

Text files modified:
   sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp | 325 ++++++++++++----------------
   sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp | 338 +++++++++++++----------------
   sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp | 381 +++++++++++++++------------------
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 325 ++++++++++++----------------
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp | 312 ++++++++++++---------------
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp | 445 +++++++++++++++++----------------------
   6 files changed, 930 insertions(+), 1196 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -52,56 +52,41 @@
 inline bool transaction::def_do_core_full_pthread_lock_mutex
 (latm::mutex_type* mutex, int lockWaitTime, int lockAborted)
 {
- //--------------------------------------------------------------------------
- // 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 (latm::instance().latmLockedLocks_.empty())
- {
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- //synchro::lock(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
- //synchro::lock(*inflight_lock());
-
- std::list<transaction*> txList;
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
-
- if (!t->irrevocable() &&
- cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
- {
- txList.push_back(t);
- }
- else
- {
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
- return false;
- }
- }
-
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- (*it)->force_to_abort();
- }
-
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
- }
-
- //try {
- latm::instance().latmLockedLocks_.insert(mutex);
- //}
- //catch (...)
- //{
- //synchro::unlock(*inflight_lock());
- // BUG ???
- // throw;
- //}
+ //--------------------------------------------------------------------------
+ // 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 (latm::instance().latmLockedLocks_.empty())
+ {
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
+
+ std::list<transaction*> txList;
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
+ {
+ transaction *t = (transaction*)*i;
+
+ if (!t->irrevocable() &&
+ cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ {
+ txList.push_back(t);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
+ {
+ (*it)->force_to_abort();
+ }
+ }
 
- return true;
+ latm::instance().latmLockedLocks_.insert(mutex);
+
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -109,67 +94,51 @@
 //----------------------------------------------------------------------------
 inline void transaction::def_full_pthread_lock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->make_isolated();
-
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
-
- t->commit_deferred_update_tx();
- { synchro::lock_guard<Mutex> lk_l(*latm_lock());
- //synchro::lock(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(*latm_lock());
- }
-
- if (hadLock) return;
- else synchro::lock(*mutex);
- return;
- }
-
- int waitTime = 0, aborted = 0;
- for (;;)
- {
- {
- //synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- //try
- //{
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (def_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->make_isolated();
+
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+
+ t->commit_deferred_update_tx();
+ {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+
+ if (hadLock) return;
+ else synchro::lock(*mutex);
+ return;
+ }
+
+ int waitTime = 0, aborted = 0;
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (def_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
             latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- lk.release();
- return;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- }
-
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
-
- //latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
- return;
+ lk.release();
+ return;
+ }
+
+ }
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
+
+ return;
 }
 
 //----------------------------------------------------------------------------
@@ -177,59 +146,42 @@
 //----------------------------------------------------------------------------
 inline bool transaction::def_full_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->make_isolated();
-
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
-
- t->commit_deferred_update_tx();
- { synchro::lock_guard<Mutex> lk_l(*latm_lock());
- //synchro::lock(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(*latm_lock());
- }
-
- if (hadLock) return true;
- else return synchro::try_lock(*mutex);
- }
-
- //if (!synchro::try_lock(*mutex)) return false;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->make_isolated();
+
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+
+ t->commit_deferred_update_tx();
+ {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+
+ if (hadLock) return true;
+ else return synchro::try_lock(*mutex);
+ }
 
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
 
- //synchro::lock(latmMutex_);
     synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
 
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!def_do_core_full_pthread_lock_mutex(mutex, 0, 0))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- //return -1;
- return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latmMutex_);
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- lk.release();
- return true;
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!def_do_core_full_pthread_lock_mutex(mutex, 0, 0))
+ {
+ return false;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -237,36 +189,33 @@
 //----------------------------------------------------------------------------
 inline void transaction::def_full_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- bool hasLock = true;
- { synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- //synchro::lock(latmMutex_);
-
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
-
- latm::instance().latmLockedLocks_.erase(mutex);
-
- if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
-
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- //synchro::unlock(latmMutex_);
- }
-
- // TBR if (hasLock) return unlock(mutex);
- // TBR else return 0;
- if (hasLock) synchro::unlock(*mutex);
- return;
+ bool hasLock = true;
+ {
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
+
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
+
+ latm::instance().latmLockedLocks_.erase(mutex);
+
+ if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
+
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ }
+
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
 
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -52,46 +52,46 @@
 inline bool transaction::def_do_core_tm_conflicting_lock_pthread_lock_mutex
 (latm::mutex_type* mutex, int lockWaitTime, int lockAborted)
 {
- //--------------------------------------------------------------------------
- // if this mutex is on the tmConflictingLocks_ set, then we need to stop
- // transactions which are in-flight.
- //
- // if it isn't we don't interrupt any in-flight transactions
- //--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
- {
- // 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 (latm::instance().latmLockedLocks_.empty())
- {
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
-
- std::list<transaction*> txList;
-
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
+ //--------------------------------------------------------------------------
+ // if this mutex is on the tmConflictingLocks_ set, then we need to stop
+ // transactions which are in-flight.
+ //
+ // if it isn't we don't interrupt any in-flight transactions
+ //--------------------------------------------------------------------------
+ if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ {
+ // 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 (latm::instance().latmLockedLocks_.empty())
+ {
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
 
- if (!t->irrevocable() &&
- cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ std::list<transaction*> txList;
+
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
             {
- txList.push_back(t);
+ transaction *t = (transaction*)*i;
+
+ if (!t->irrevocable() &&
+ cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ {
+ txList.push_back(t);
+ }
+ else return false;
             }
- else return false;
- }
 
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- (*it)->force_to_abort();
- }
- }
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
+ {
+ (*it)->force_to_abort();
+ }
+ }
 
- latm::instance().latmLockedLocks_.insert(mutex);
- }
+ latm::instance().latmLockedLocks_.insert(mutex);
+ }
 
- return true;
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -99,74 +99,53 @@
 //----------------------------------------------------------------------------
 inline void transaction::def_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
- t->make_isolated();
- t->commit_deferred_update_tx();
-
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
-
- {
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
- //synchro::lock(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(*latm_lock());
- }
-
- if (hadLock) return;
- else synchro::lock(*mutex);
- return;
- }
-
- int waitTime = 0, aborted = 0;
-
- for (;;)
- {
- {
- //synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
-
- //try
- //{
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (def_do_core_tm_conflicting_lock_pthread_lock_mutex
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ t->make_isolated();
+ t->commit_deferred_update_tx();
+
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+
+ {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+
+ if (hadLock) return;
+ else synchro::lock(*mutex);
+ return;
+ }
+
+ int waitTime = 0, aborted = 0;
+
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (def_do_core_tm_conflicting_lock_pthread_lock_mutex
             (mutex, waitTime, aborted)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
- lk.release();
- return;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- }
-
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
-
- //latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ lk.release();
+ return;
+ }
+ }
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
 
- return;
+ return;
 }
 
 //----------------------------------------------------------------------------
@@ -174,59 +153,42 @@
 //----------------------------------------------------------------------------
 inline bool transaction::def_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
- t->make_isolated();
- t->commit_deferred_update_tx();
-
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
-
- {
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
- //synchro::lock(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(*latm_lock());
- }
-
- if (hadLock) return true;
- else return synchro::try_lock(*mutex);
- }
-
- //if (!synchro::try_lock(*mutex)) return false;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
-
- //synchro::lock(latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!def_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- //return -1;
- return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latmMutex_);
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- lk.release();
- return true;
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ t->make_isolated();
+ t->commit_deferred_update_tx();
+
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+
+ {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+
+ if (hadLock) return true;
+ else return synchro::try_lock(*mutex);
+ }
+
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
+
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!def_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
+ {
+ return false;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -234,43 +196,41 @@
 //----------------------------------------------------------------------------
 inline void transaction::def_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- bool hasLock = true;
- {
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- //synchro::lock(latmMutex_);
-
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
-
- //--------------------------------------------------------------------------
- // if this mutex is on the tmConflictingLocks_ set, then we need to remove
- // it from the latmLocks and check to see if we allow transactions to
- // continue.
- //--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
- {
- latm::instance().latmLockedLocks_.erase(mutex);
-
- if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
- }
-
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- //synchro::unlock(latmMutex_);
- }
+ bool hasLock = true;
+ {
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
+
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
+
+ //--------------------------------------------------------------------------
+ // if this mutex is on the tmConflictingLocks_ set, then we need to remove
+ // it from the latmLocks and check to see if we allow transactions to
+ // continue.
+ //--------------------------------------------------------------------------
+ if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ {
+ latm::instance().latmLockedLocks_.erase(mutex);
+
+ if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ }
 
- if (hasLock) synchro::unlock(*mutex);
- return;
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
 
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -44,78 +44,78 @@
 inline bool transaction::def_do_core_tx_conflicting_lock_pthread_lock_mutex
 (latm::mutex_type* mutex, int lockWaitTime, int lockAborted, bool txIsIrrevocable)
 {
- //--------------------------------------------------------------------------
- // see if this mutex is part of any of the in-flight transactions conflicting
- // mutex set. if it is, stop that transaction and add it to the latm conflicting
- // set. do not keep in-flight transactions blocked once the transactions have
- // been processed.
- //--------------------------------------------------------------------------
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
+ //--------------------------------------------------------------------------
+ // see if this mutex is part of any of the in-flight transactions conflicting
+ // mutex set. if it is, stop that transaction and add it to the latm conflicting
+ // set. do not keep in-flight transactions blocked once the transactions have
+ // been processed.
+ //--------------------------------------------------------------------------
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
 
- std::list<transaction *> txList;
- std::set<thread_id_t> txThreadId;
+ std::list<transaction *> txList;
+ std::set<thread_id_t> txThreadId;
 
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
       i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
+ {
+ transaction *t = (transaction*)*i;
 
- // if this tx is part of this thread, skip it (it's an LiT)
- if (t->threadId_ == this_thread::get_id()) continue;
+ // if this tx is part of this thread, skip it (it's an LiT)
+ if (t->threadId_ == this_thread::get_id()) continue;
 
- // if this mutex has a conflict with an inflight tx
- 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)))
- {
- txList.push_back(t);
- }
- else return false;
- }
- }
+ // if this mutex has a conflict with an inflight tx
+ 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)))
+ {
+ txList.push_back(t);
+ }
+ else return false;
+ }
+ }
 
- if (!txList.empty())
- {
+ if (!txList.empty())
+ {
 #if LOGGING_BLOCKS
- logFile_ << "----------------------\nbefore locked mutex: " << mutex << endl << endl;
- logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
+ logFile_ << "----------------------\nbefore locked mutex: " << mutex << endl << endl;
+ logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
 #endif
 
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- transaction *t = (transaction*)*it;
-
- t->force_to_abort();
- t->block();
- txThreadId.insert(t->threadId_);
- }
-
- try {
- latm::instance().latmLockedLocksAndThreadIdsMap_.insert
- (std::make_pair<latm::mutex_type*, ThreadIdSet>(mutex, txThreadId));
- }
- catch (...)
- {
- for (std::set<thread_id_t>::iterator it = txThreadId.begin();
- txThreadId.end() != it; ++it)
- {
- if (0 == thread_id_occurance_in_locked_locks_map(*it))
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
+ {
+ transaction *t = (transaction*)*it;
+
+ t->force_to_abort();
+ t->block();
+ txThreadId.insert(t->threadId_);
+ }
+
+ try {
+ latm::instance().latmLockedLocksAndThreadIdsMap_.insert
+ (std::make_pair<latm::mutex_type*, ThreadIdSet>(mutex, txThreadId));
+ }
+ catch (...)
+ {
+ for (std::set<thread_id_t>::iterator it = txThreadId.begin();
+ txThreadId.end() != it; ++it)
             {
- blocked(*it) = false;
+ if (0 == thread_id_occurance_in_locked_locks_map(*it))
+ {
+ blocked(*it) = false;
+ }
             }
- }
- throw;
- }
+ throw;
+ }
 
 #if LOGGING_BLOCKS
- logFile_ << "----------------------\nafter locked mutex: " << mutex << endl << endl;
- logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
+ logFile_ << "----------------------\nafter locked mutex: " << mutex << endl << endl;
+ logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
 #endif
- }
+ }
 
- return true;
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -145,73 +145,53 @@
    // that it has blocked due to our claiming to have obtained the lock
    // (5) abort all the in-flight conflicting txes and return
    //--------------------------------------------------------------------------
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->must_be_in_conflicting_lock_set(mutex);
- t->make_irrevocable();
-
- if (!t->is_currently_locked_lock(mutex))
- {
- synchro::lock(*mutex);
- }
-
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
- t->commit_deferred_update_tx();
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- def_do_core_tx_conflicting_lock_pthread_lock_mutex
- (mutex, 0, 0, true);
- //synchro::unlock(latm::instance().latmMutex_);
-
- return;
- }
-
- for (;;)
- {
- {//synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (def_do_core_tx_conflicting_lock_pthread_lock_mutex
- (mutex, waitTime, aborted, false)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- lk.release();
- return;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- } //synchro::unlock(latm::instance().latmMutex_);
-
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
-
- //latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
-
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- return;
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->must_be_in_conflicting_lock_set(mutex);
+ t->make_irrevocable();
+
+ if (!t->is_currently_locked_lock(mutex))
+ {
+ synchro::lock(*mutex);
+ }
+
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+ t->commit_deferred_update_tx();
+
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+ def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, true);
+ return;
+ }
+
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, waitTime, aborted, false))
+ {
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ lk.release();
+ return;
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
+
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ return;
 }
 
 //----------------------------------------------------------------------------
@@ -219,55 +199,40 @@
 //----------------------------------------------------------------------------
 inline bool transaction::def_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- //--------------------------------------------------------------------------
+ //--------------------------------------------------------------------------
+
+ throw "might not be possible to implement trylock for this";
 
- throw "might not be possible to implement trylock for this";
+ bool txIsIrrevocable = false;
 
- bool txIsIrrevocable = false;
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
 
- //if (!synchro::try_lock(*mutex)) return false;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- txIsIrrevocable = true;
- t->must_be_in_conflicting_lock_set(mutex);
- t->make_irrevocable();
- t->add_to_obtained_locks(mutex);
- t->commit_deferred_update_tx();
- }
-
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- //return -1;
- return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
-
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- lk.release();
- return true;
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ txIsIrrevocable = true;
+ t->must_be_in_conflicting_lock_set(mutex);
+ t->make_irrevocable();
+ t->add_to_obtained_locks(mutex);
+ t->commit_deferred_update_tx();
+ }
+
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
+ {
+ return false;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -275,52 +240,50 @@
 //----------------------------------------------------------------------------
 inline void transaction::def_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
- bool hasLock = true;
-
- if (transaction* t = get_inflight_tx_of_same_thread(true))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
-
- //--------------------------------------------------------------------------
- // if this mutex is on the tmConflictingLocks_ set, then we need to remove
- // it from the latmLocks and any txs on the full thread list that are
- // blocked because of this lock being locked should be unblocked
- //--------------------------------------------------------------------------
- if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
- {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
+ bool hasLock = true;
+
+ if (transaction* t = get_inflight_tx_of_same_thread(true))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
+
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
+
+ //--------------------------------------------------------------------------
+ // if this mutex is on the tmConflictingLocks_ set, then we need to remove
+ // it from the latmLocks and any txs on the full thread list that are
+ // blocked because of this lock being locked should be unblocked
+ //--------------------------------------------------------------------------
+ if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
+ {
 #if LOGGING_BLOCKS
- logFile_ << "----------------------\nbefore unlocked mutex: " << mutex << endl << endl;
- logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
+ logFile_ << "----------------------\nbefore unlocked mutex: " << mutex << endl << endl;
+ logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
 #endif
- latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
- unblock_conflicting_threads(mutex);
+ latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
+ unblock_conflicting_threads(mutex);
 
 #if LOGGING_BLOCKS
- logFile_ << "----------------------\nafter unlocked mutex: " << mutex << endl << endl;
- logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
+ logFile_ << "----------------------\nafter unlocked mutex: " << mutex << endl << endl;
+ logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
 #endif
- }
+ }
 
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- unblock_threads_if_locks_are_empty();
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ unblock_threads_if_locks_are_empty();
 
- // TBR if (hasLock) return unlock(mutex);
- // TBR else return 0;
- if (hasLock) synchro::unlock(*mutex);
- return;
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
 
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -58,65 +58,59 @@
    //--------------------------------------------------------------------------
    if (latm::instance().latmLockedLocks_.empty())
    {
-
- {
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- //synchro::lock(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
- //synchro::lock(*inflight_lock());
-
- std::list<transaction*> txList;
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
-
- if (!t->irrevocable() &&
- cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
- {
- txList.push_back(t);
- }
- else
- {
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
- return false;
- }
- }
-
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- (*it)->force_to_abort();
- }
-
- //-----------------------------------------------------------------------
- // block all threads, since we have to unlock the in-flight mutex
- //-----------------------------------------------------------------------
- thread_conflicting_mutexes_set_all(true);
 
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
+ {
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
+
+ std::list<transaction*> txList;
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
+ {
+ transaction *t = (transaction*)*i;
+
+ if (!t->irrevocable() &&
+ cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ {
+ txList.push_back(t);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
+ {
+ (*it)->force_to_abort();
+ }
+
+ //-----------------------------------------------------------------------
+ // block all threads, since we have to unlock the in-flight mutex
+ //-----------------------------------------------------------------------
+ thread_conflicting_mutexes_set_all(true);
+
+ }
+
+ //-----------------------------------------------------------------------
+ // now we must stall until all in-flight transactions are gone, otherwise
+ // global memory may still be in an inconsistent state
+ //-----------------------------------------------------------------------
+ while (!transactionsInFlight_.empty()) { SLEEP(10); }
     }
 
- //-----------------------------------------------------------------------
- // now we must stall until all in-flight transactions are gone, otherwise
- // global memory may still be in an inconsistent state
- //-----------------------------------------------------------------------
- while (!transactionsInFlight_.empty()) { SLEEP(10); }
- }
-
- try {
- latm::instance().latmLockedLocks_.insert(mutex); }
- catch (...)
- {
+ try {
+ latm::instance().latmLockedLocks_.insert(mutex); }
+ catch (...)
+ {
        // BUG ???
       //synchro::unlock(*general_lock());
       //synchro::unlock(*inflight_lock());
        // BUG ???
- throw;
- }
+ throw;
+ }
 
- return true;
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -124,66 +118,49 @@
 //----------------------------------------------------------------------------
 inline void transaction::dir_full_pthread_lock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->make_isolated();
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->make_isolated();
 
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
-
- // this method locks LATM and keeps it locked upon returning if param true
- wait_until_all_locks_are_released(true);
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- synchro::unlock(*latm_lock());
-
- if (hadLock) return;
- else synchro::lock(*mutex);
- return;
- }
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+
+ // this method locks LATM and keeps it locked upon returning if param true
+ wait_until_all_locks_are_released(true);
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ synchro::unlock(*latm_lock());
+
+ if (hadLock) return;
+ else synchro::lock(*mutex);
+ return;
+ }
 
- int waitTime = 0, aborted = 0;
- for (;;)
- {
- //{
- // TBR int val = lock(mutex);
- // TBR if (0 != val) return val;
- {//synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (dir_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
+ int waitTime = 0, aborted = 0;
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (dir_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
             latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
- lk.release();
+ lk.release();
             return;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- }
-
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
+ }
+
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+ }
+
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
 
 }
 
@@ -192,56 +169,40 @@
 //----------------------------------------------------------------------------
 inline bool transaction::dir_full_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->make_isolated();
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->make_isolated();
+
+ bool hadLock = t->is_currently_locked_lock(mutex);
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+
+ // this method locks LATM and keeps it locked upon returning if param true
+ wait_until_all_locks_are_released(true);
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ synchro::unlock(*latm_lock());
 
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
-
- // this method locks LATM and keeps it locked upon returning if param true
- wait_until_all_locks_are_released(true);
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- synchro::unlock(*latm_lock());
-
- if (hadLock) return true;
- else return synchro::try_lock(*mutex);
- }
-
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
- //if (!synchro::try_lock(*mutex)) return false;
-
- //synchro::lock(latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!dir_do_core_full_pthread_lock_mutex(mutex, 0, 0))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- //return -1;
+ if (hadLock) return true;
+ else return synchro::try_lock(*mutex);
+ }
+
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!dir_do_core_full_pthread_lock_mutex(mutex, 0, 0))
+ {
          return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latmMutex_);
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- lk.release();
- return true;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -249,44 +210,36 @@
 //----------------------------------------------------------------------------
 inline void transaction::dir_full_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- bool hasLock = true;
+ bool hasLock = true;
     {
- //synchro::lock(latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
 
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
-
- latm::instance().latmLockedLocks_.erase(mutex);
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
 
- if (latm::instance().latmLockedLocks_.empty())
- {
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- //synchro::lock(*general_lock());
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
 
- thread_conflicting_mutexes_set_all(false);
+ latm::instance().latmLockedLocks_.erase(mutex);
 
- //synchro::unlock(*general_lock());
- }
+ if (latm::instance().latmLockedLocks_.empty())
+ {
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ thread_conflicting_mutexes_set_all(false);
+ }
 
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- //synchro::unlock(latmMutex_);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
     }
- // TBR if (hasLock) return unlock(mutex);
- // TBR else return 0;
- if (hasLock) synchro::unlock(*mutex);
- return;
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
 
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -58,62 +58,58 @@
    //
    // if it isn't we don't interrupt any in-flight transactions
    //--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
- {
+ if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ {
       //--------------------------------------------------------------------------
       // 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 (latm::instance().latmLockedLocks_.empty())
- {
- {//synchro::lock(*general_lock());
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- //synchro::lock(*inflight_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
-
- std::list<transaction*> txList;
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
+ if (latm::instance().latmLockedLocks_.empty())
+ {
+ {
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
 
- if (!t->irrevocable() &&
- cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ std::list<transaction*> txList;
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
             {
- txList.push_back(t);
+ transaction *t = (transaction*)*i;
+
+ if (!t->irrevocable() &&
+ cm_allow_lock_to_abort_tx(lockWaitTime, lockAborted, false, *t))
+ {
+ txList.push_back(t);
+ }
+ else
+ {
+ return false;
+ }
             }
- else
+
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
             {
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
- return false;
+ (*it)->force_to_abort();
+ }
+
+ //-----------------------------------------------------------------------
+ // block all threads, since we have to unlock the in-flight mutex
+ //-----------------------------------------------------------------------
+ thread_conflicting_mutexes_set_all(true);
+
             }
- }
 
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- (*it)->force_to_abort();
- }
-
- //-----------------------------------------------------------------------
- // block all threads, since we have to unlock the in-flight mutex
- //-----------------------------------------------------------------------
- thread_conflicting_mutexes_set_all(true);
-
- } //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
-
- //-----------------------------------------------------------------------
- // now we must stall until all in-flight transactions are gone, otherwise
- // global memory may still be in an inconsistent state
- //-----------------------------------------------------------------------
- while (!transactionsInFlight_.empty()) { SLEEP(10); }
- }
+ //-----------------------------------------------------------------------
+ // now we must stall until all in-flight transactions are gone, otherwise
+ // global memory may still be in an inconsistent state
+ //-----------------------------------------------------------------------
+ while (!transactionsInFlight_.empty()) { SLEEP(10); }
+ }
 
- latm::instance().latmLockedLocks_.insert(mutex);
- }
+ latm::instance().latmLockedLocks_.insert(mutex);
+ }
 
- return true;
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -121,53 +117,47 @@
 //----------------------------------------------------------------------------
 inline void transaction::dir_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
- t->make_isolated();
- {//synchro::lock(*latm_lock());
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- }//synchro::unlock(*latm_lock());
- synchro::lock(*mutex); // BUG: should't be before the map setting and making the tx isolated?
- return;
- }
-
- int waitTime = 0, aborted = 0;
-
- for (;;)
- {
- {//synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (dir_do_core_tm_conflicting_lock_pthread_lock_mutex
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ t->make_isolated();
+ {
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+ synchro::lock(*mutex); // BUG: should't be before the map setting and making the tx isolated?
+ return;
+ }
+
+ int waitTime = 0, aborted = 0;
+
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (dir_do_core_tm_conflicting_lock_pthread_lock_mutex
             (mutex, waitTime, aborted)) {
             latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- lk.release();
+ lk.release();
             return;
- }
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- } //synchro::unlock(latm::instance().latmMutex_);
-
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
+ }
 
- //latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
+ }
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
 
- return;
+ return;
 }
 
 //----------------------------------------------------------------------------
@@ -175,52 +165,34 @@
 //----------------------------------------------------------------------------
 inline bool transaction::dir_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
- t->make_isolated();
- {//synchro::lock(*latm_lock());
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- }//synchro::unlock(*latm_lock());
- return synchro::try_lock(*mutex); // BUG: : should't be before the map setting and making the tx isolated?
- }
-
- //int val = synchro::try_lock(*mutex);
- //if (0 != val) return val;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
- //if (!synchro::try_lock(*mutex)) return false;
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!dir_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- //return -1;
- return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- lk.release();
- return true;
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ t->make_isolated();
+ {
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+ return synchro::try_lock(*mutex); // BUG: : should't be before the map setting and making the tx isolated?
+ }
+
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!dir_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
+ {
+ return false;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -228,51 +200,45 @@
 //----------------------------------------------------------------------------
 inline void transaction::dir_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- bool hasLock = true;
- {//synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
-
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
+ bool hasLock = true;
+ {
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
+
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
+
+ //--------------------------------------------------------------------------
+ // if this mutex is on the tmConflictingLocks_ set, then we need to remove
+ // it from the latmLocks and check to see if we allow transactions to
+ // continue.
+ //--------------------------------------------------------------------------
+ if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ {
+ latm::instance().latmLockedLocks_.erase(mutex);
 
- //--------------------------------------------------------------------------
- // if this mutex is on the tmConflictingLocks_ set, then we need to remove
- // it from the latmLocks and check to see if we allow transactions to
- // continue.
- //--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
- {
- latm::instance().latmLockedLocks_.erase(mutex);
-
- if (latm::instance().latmLockedLocks_.empty())
- {
- //synchro::lock(*general_lock());
+ if (latm::instance().latmLockedLocks_.empty())
+ {
           synchro::lock_guard<Mutex> lk_g(*general_lock());
           thread_conflicting_mutexes_set_all(false);
+ }
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ }
 
- //synchro::unlock(*general_lock());
- }
- }
-
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- }//synchro::unlock(latm::instance().latmMutex_);
-
- //if (hasLock) return unlock(mutex);
- //else return 0;
- if (hasLock) synchro::unlock(*mutex);
- return;
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
 
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp 2009-11-03 07:48:58 EST (Tue, 03 Nov 2009)
@@ -45,129 +45,115 @@
 inline bool transaction::dir_do_core_tx_conflicting_lock_pthread_lock_mutex
 (latm::mutex_type* mutex, int lockWaitTime, int lockAborted, bool txIsIrrevocable)
 {
- //--------------------------------------------------------------------------
- // see if this mutex is part of any of the in-flight transactions conflicting
- // mutex set. if it is, stop that transaction and add it to the latm conflicting
- // set. do not keep in-flight transactions blocked once the transactions have
- // been processed.
- //--------------------------------------------------------------------------
- //synchro::lock(*general_lock());
+ //--------------------------------------------------------------------------
+ // see if this mutex is part of any of the in-flight transactions conflicting
+ // mutex set. if it is, stop that transaction and add it to the latm conflicting
+ // set. do not keep in-flight transactions blocked once the transactions have
+ // been processed.
+ //--------------------------------------------------------------------------
     synchro::unique_lock<Mutex> lk_g(*general_lock());
- //synchro::lock(*inflight_lock());
     synchro::unique_lock<Mutex> lk_i(*inflight_lock());
 
- std::list<transaction *> txList;
- std::set<thread_id_t> txThreadId;
- //transaction *txToMakeIsolated = 0;
-
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
- i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
-
- // if this tx is part of this thread, skip it (it's an LiT)
- if (t->threadId_ == this_thread::get_id()) continue;
-
- 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)))
- {
- txList.push_back(t);
- }
- else
- {
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
- return false;
- }
- }
- }
-
- if (!txList.empty())
- {
- for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
- {
- transaction *t = (transaction*)*it;
-
- t->force_to_abort();
- t->block();
- txThreadId.insert(t->threadId_);
- }
-
- try
- {
- latm::instance().latmLockedLocksAndThreadIdsMap_.insert
- (std::make_pair<latm::mutex_type*, ThreadIdSet>(mutex, txThreadId));
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- }
- catch (...)
- {
- for (std::set<thread_id_t>::iterator it = txThreadId.begin();
- txThreadId.end() != it; ++it)
- {
- if (0 == thread_id_occurance_in_locked_locks_map(*it))
- {
- blocked(*it) = false;
- }
- }
- throw;
- }
-
- //synchro::unlock(*general_lock());
- lk_g.unlock();
- //synchro::unlock(*inflight_lock());
- lk_i.unlock();
-
- //-----------------------------------------------------------------------
- // now wait until all the txs which conflict with this mutex are no longer
- // in-flight
- //-----------------------------------------------------------------------
- for (;;)
- {
- bool conflictingTxInFlight = false;
-
- {
- //synchro::lock(*general_lock());
- synchro::unique_lock<Mutex> lk_g(*general_lock());
- //synchro::lock(*inflight_lock());
- synchro::unique_lock<Mutex> lk_i(*inflight_lock());
+ std::list<transaction *> txList;
+ std::set<thread_id_t> txThreadId;
+ //transaction *txToMakeIsolated = 0;
 
- for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
             i != transactionsInFlight_.end(); ++i)
- {
- transaction *t = (transaction*)*i;
+ {
+ transaction *t = (transaction*)*i;
+
+ // if this tx is part of this thread, skip it (it's an LiT)
+ if (t->threadId_ == this_thread::get_id()) continue;
 
- if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().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)))
             {
- conflictingTxInFlight = true;
+ txList.push_back(t);
             }
- }
+ else
+ {
+ return false;
+ }
+ }
+ }
 
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
+ if (!txList.empty())
+ {
+ for (std::list<transaction*>::iterator it = txList.begin(); txList.end() != it; ++it)
+ {
+ transaction *t = (transaction*)*it;
+
+ t->force_to_abort();
+ t->block();
+ txThreadId.insert(t->threadId_);
         }
- if (conflictingTxInFlight) SLEEP(10);
- else return true;
- }
- } else {
 
- //synchro::unlock(*general_lock());
- //synchro::unlock(*inflight_lock());
+ try
+ {
+ latm::instance().latmLockedLocksAndThreadIdsMap_.insert
+ (std::make_pair<latm::mutex_type*, ThreadIdSet>(mutex, txThreadId));
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ }
+ catch (...)
+ {
+ for (std::set<thread_id_t>::iterator it = txThreadId.begin();
+ txThreadId.end() != it; ++it)
+ {
+ if (0 == thread_id_occurance_in_locked_locks_map(*it))
+ {
+ blocked(*it) = false;
+ }
+ }
+ throw;
+ }
+
+ lk_g.unlock();
+ lk_i.unlock();
+
+ //-----------------------------------------------------------------------
+ // now wait until all the txs which conflict with this mutex are no longer
+ // in-flight
+ //-----------------------------------------------------------------------
+ for (;;)
+ {
+ bool conflictingTxInFlight = false;
+
+ {
+ synchro::unique_lock<Mutex> lk_g(*general_lock());
+ synchro::unique_lock<Mutex> lk_i(*inflight_lock());
+
+ for (InflightTxes::iterator i = transactionsInFlight_.begin();
+ i != transactionsInFlight_.end(); ++i)
+ {
+ transaction *t = (transaction*)*i;
+
+ if (t->get_tx_conflicting_locks().find(mutex) != t->get_tx_conflicting_locks().end())
+ {
+ conflictingTxInFlight = true;
+ }
+ }
 
- return true;
- }
+ }
+ if (conflictingTxInFlight) SLEEP(10);
+ else return true;
+ }
+ } else {
+ return true;
+ }
 }
 
 //----------------------------------------------------------------------------
 // only allow one thread to execute any of these methods at a time
 //----------------------------------------------------------------------------
-// Protected by: mutex is locked
-// Postcondition: mutex is locked
+// Protected by: mutex is locked
+// Postcondition: mutex is locked
 //----------------------------------------------------------------------------
 inline void transaction::dir_tx_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
 {
- int waitTime = 0, aborted = 0;
+ int waitTime = 0, aborted = 0;
 
    //--------------------------------------------------------------------------
    // this is the most complex code in the entire system. it is highly order
@@ -189,74 +175,53 @@
    // that it has blocked due to our claiming to have obtained the lock
    // (5) abort all the in-flight conflicting txes and return
    //--------------------------------------------------------------------------
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- t->must_be_in_conflicting_lock_set(mutex);
- t->make_irrevocable();
-
- if (!t->is_currently_locked_lock(mutex))
- {
- // TBR if (0 != lock(mutex)) return -1;
- synchro::lock(*mutex);
- }
-
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, true);
- //synchro::unlock(latm::instance().latmMutex_);
-
- return;
- }
-
- for (;;)
- {
- // TBR int val = lock(mutex);
- // TBR if (0 != val) return val;
- {//synchro::lock(*mutex);
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- //try
- //{
- //--------------------------------------------------------------------
- // if we are able to do the core lock work, break
- //--------------------------------------------------------------------
- if (dir_do_core_tx_conflicting_lock_pthread_lock_mutex
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ t->must_be_in_conflicting_lock_set(mutex);
+ t->make_irrevocable();
+
+ if (!t->is_currently_locked_lock(mutex))
+ {
+ synchro::lock(*mutex);
+ }
+
+ t->add_to_currently_locked_locks(mutex);
+ t->add_to_obtained_locks(mutex);
+
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+ def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, true);
+
+ return;
+ }
+
+ for (;;)
+ {
+ {
+ synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ //--------------------------------------------------------------------
+ // if we are able to do the core lock work, break
+ //--------------------------------------------------------------------
+ if (dir_do_core_tx_conflicting_lock_pthread_lock_mutex
             (mutex, waitTime, aborted, false)) {
             latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
             lk.release();
- return;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- //-----------------------------------------------------------------------
- // we weren't able to do the core lock work, unlock our mutex and sleep
- //-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- }
- SLEEP(cm_lock_sleep_time());
- waitTime += cm_lock_sleep_time();
- ++aborted;
- }
-
- //latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
-
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- return;
+ return;
+ }
+
+ }
+ //-----------------------------------------------------------------------
+ // we weren't able to do the core lock work, unlock our mutex and sleep
+ //-----------------------------------------------------------------------
+ SLEEP(cm_lock_sleep_time());
+ waitTime += cm_lock_sleep_time();
+ ++aborted;
+ }
+
+ // note: we do not release the transactionsInFlightMutex - this will prevents
+ // new transactions from starting until this lock is released
+ return;
 }
 
 //----------------------------------------------------------------------------
@@ -264,55 +229,34 @@
 //----------------------------------------------------------------------------
 inline bool transaction::dir_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
 {
- //--------------------------------------------------------------------------
- throw "might not be possible to implement trylock for this";
+ //--------------------------------------------------------------------------
+ throw "might not be possible to implement trylock for this";
 
- bool txIsIrrevocable = false;
+ bool txIsIrrevocable = false;
 
- //int val = synchro::try_lock(*mutex);
- //if (0 != val) return val;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
- if (!lk) return false;
- //if (!synchro::try_lock(*mutex)) return false;
-
- //synchro::lock(latm::instance().latmMutex_);
- synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
-
- if (transaction* t = get_inflight_tx_of_same_thread(false))
- {
- txIsIrrevocable = true;
- t->must_be_in_conflicting_lock_set(mutex);
- t->make_irrevocable();
- t->add_to_obtained_locks(mutex);
- }
-
- //try
- //{
- //-----------------------------------------------------------------------
- // if !core done, since trylock, we cannot stall & retry - just exit
- //-----------------------------------------------------------------------
- if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
- {
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- //return -1;
- return false;
- }
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latm::instance().latmMutex_);
- // throw;
- //}
-
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
- //synchro::unlock(latm::instance().latmMutex_);
- lk.release();
-
- // note: we do not release the transactionsInFlightMutex - this will prevents
- // new transactions from starting until this lock is released
- return true;
+ synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ if (!lk) return false;
+ synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
+
+ if (transaction* t = get_inflight_tx_of_same_thread(false))
+ {
+ txIsIrrevocable = true;
+ t->must_be_in_conflicting_lock_set(mutex);
+ t->make_irrevocable();
+ t->add_to_obtained_locks(mutex);
+ }
+
+ //-----------------------------------------------------------------------
+ // if !core done, since trylock, we cannot stall & retry - just exit
+ //-----------------------------------------------------------------------
+ if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
+ {
+ return false;
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ lk.release();
+ return true;
 }
 
 //----------------------------------------------------------------------------
@@ -320,44 +264,43 @@
 //----------------------------------------------------------------------------
 inline void transaction::dir_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
 {
- synchro::lock_guard<Mutex> lk_l(*latm_lock());
- synchro::lock_guard<Mutex> lk_g(*general_lock());
- synchro::lock_guard<Mutex> lk_i(*inflight_lock());
- bool hasLock = true;
-
- if (transaction* t = get_inflight_tx_of_same_thread(true))
- {
- if (!t->is_on_obtained_locks_list(mutex))
- {
- // this is illegal, it means the transaction is unlocking a lock
- // it did not obtain (e.g., early release) while the transaction
- // is still in-flight. Throw exception
- throw "lock released for transaction that did not obtain it";
- }
-
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
- }
+ synchro::lock_guard<Mutex> lk_l(*latm_lock());
+ synchro::lock_guard<Mutex> lk_g(*general_lock());
+ synchro::lock_guard<Mutex> lk_i(*inflight_lock());
+ bool hasLock = true;
+
+ if (transaction* t = get_inflight_tx_of_same_thread(true))
+ {
+ if (!t->is_on_obtained_locks_list(mutex))
+ {
+ // this is illegal, it means the transaction is unlocking a lock
+ // it did not obtain (e.g., early release) while the transaction
+ // is still in-flight. Throw exception
+ throw "lock released for transaction that did not obtain it";
+ }
 
- //--------------------------------------------------------------------------
- // if this mutex is on the tmConflictingLocks_ set, then we need to remove
- // it from the latmLocks and any txs on the full thread list that are
- // blocked because of this lock being locked should be unblocked
- //--------------------------------------------------------------------------
- if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
- {
- latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
- unblock_conflicting_threads(mutex);
- }
-
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
- unblock_threads_if_locks_are_empty();
-
- // TBR if (hasLock) return unlock(mutex);
- // TBR else return 0;
- if (hasLock) synchro::unlock(*mutex);
- return;
+ if (!t->is_currently_locked_lock(mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(mutex);
+ }
+
+ //--------------------------------------------------------------------------
+ // if this mutex is on the tmConflictingLocks_ set, then we need to remove
+ // it from the latmLocks and any txs on the full thread list that are
+ // blocked because of this lock being locked should be unblocked
+ //--------------------------------------------------------------------------
+ if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
+ {
+ latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
+ unblock_conflicting_threads(mutex);
+ }
+
+ latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ unblock_threads_if_locks_are_empty();
+
+ if (hasLock) synchro::unlock(*mutex);
+ return;
 }
+
 }}
 
 #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