Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57343 - in sandbox/stm/branches/vbe/boost/stm: . detail
From: vicente.botet_at_[hidden]
Date: 2009-11-03 15:31:49


Author: viboes
Date: 2009-11-03 15:31:47 EST (Tue, 03 Nov 2009)
New Revision: 57343
URL: http://svn.boost.org/trac/boost/changeset/57343

Log:
TBoost.STM vbe: Added scoped locks on files transaction.hpp transaction_impl.hpp and latm_general_impl.hpp

Text files modified:
   sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 10 --
   sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp | 61 +++++++++++---------
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 119 +++++++++++++++++----------------------
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 29 ++-------
   4 files changed, 94 insertions(+), 125 deletions(-)

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 15:31:47 EST (Tue, 03 Nov 2009)
@@ -126,10 +126,7 @@
         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());
+ wait_until_all_locks_are_released_and_set(mutex);
 
         if (hadLock) return;
         else synchro::lock(*mutex);
@@ -177,10 +174,7 @@
         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());
+ wait_until_all_locks_are_released_and_set(mutex);
 
         if (hadLock) return true;
         else return synchro::try_lock(*mutex);

Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp 2009-11-03 15:31:47 EST (Tue, 03 Nov 2009)
@@ -46,19 +46,42 @@
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
-inline void boost::stm::transaction::wait_until_all_locks_are_released(bool keepLatmLocked)
+inline void boost::stm::transaction::wait_until_all_locks_are_released()
 {
- while (true)
- {
- synchro::lock(*latm_lock());
- if (latm::instance().latmLockedLocks_.empty()) break;
- synchro::unlock(*latm_lock());
- SLEEP(10);
+ while (true)
+ {
+ {
+ synchro::lock_guard<Mutex> lk(*latm_lock());
+ if (latm::instance().latmLockedLocks_.empty()) {
+ return;
+ }
+
+ }
+
+ SLEEP(10);
    }
 
- if (!keepLatmLocked) synchro::unlock(*latm_lock());
 }
 
+inline void boost::stm::transaction::wait_until_all_locks_are_released_and_set(latm::mutex_type* mutex)
+{
+ while (true)
+ {
+ {
+ synchro::lock_guard<Mutex> lk(*latm_lock());
+ if (latm::instance().latmLockedLocks_.empty()) {
+ latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ return;
+ }
+
+ }
+
+ SLEEP(10);
+ }
+
+}
+
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 inline void boost::stm::transaction::add_to_obtained_locks(latm::mutex_type* m)
@@ -211,25 +234,16 @@
 {
 #if 1
     latm::instance().tm_lock_conflict(inLock);
-#else
+#else
    if (!latm::instance().doing_tm_lock_protection()) return;
 
- //synchro::lock(latmMutex_);
    synchro::lock_guard<Mutex> lock_l(latmMutex_);
 
    //-------------------------------------------------------------------------
    // insert can throw an exception
    //-------------------------------------------------------------------------
- //try {
- tmConflictingLocks_.insert(inLock);
- //}
- //catch (...)
- //{
- // synchro::unlock(latmMutex_);
- //throw;
- //}
- //synchro::unlock(latmMutex_);
-#endif
+ tmConflictingLocks_.insert(inLock);
+#endif
 }
 
 #if 0
@@ -239,9 +253,7 @@
 inline void boost::stm::transaction::clear_tm_conflicting_locks()
 {
    synchro::lock_guard<Mutex> lock_l(latmMutex_);
- //synchro::lock(latmMutex_);
    tmConflictingLocks_.clear();
- //synchro::unlock(latmMutex_);
 }
 
 //----------------------------------------------------------------------------
@@ -296,9 +308,7 @@
 inline void boost::stm::transaction::clear_tx_conflicting_locks()
 {
    synchro::lock_guard<Mutex> lock_l(*general_lock());
- //synchro::lock(*general_lock());
    get_tx_conflicting_locks().clear();
- //synchro::unlock(*general_lock());
 }
 
 //----------------------------------------------------------------------------
@@ -465,7 +475,6 @@
 (bool hasTxInFlightMutex)
 {
    synchro::lock_guard_if<Mutex> lock_l(*general_lock(), !hasTxInFlightMutex);
- //if (!hasTxInFlightMutex) synchro::lock(*inflight_lock());
 
    for (InflightTxes::iterator i = transactionsInFlight_.begin();
       i != transactionsInFlight_.end(); ++i)
@@ -479,12 +488,10 @@
       //--------------------------------------------------------------------
       if (t->thread_id() == this_thread::get_id())
       {
- //if (!hasTxInFlightMutex) synchro::unlock(*inflight_lock());
          return t;
       }
    }
 
- //if (!hasTxInFlightMutex) synchro::unlock(*inflight_lock());
    return 0;
 }
 }}

Modified: sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp 2009-11-03 15:31:47 EST (Tue, 03 Nov 2009)
@@ -126,17 +126,14 @@
    while (true)
    {
       {
- //lock(inflight_lock());
       synchro::lock_guard<Mutex> lock_m(*inflight_lock());
 
       if (!irrevocableTxInFlight())
       {
          tx_type(eIrrevocableTx);
- //unlock(inflight_lock());
          return;
       }
 
- //unlock(inflight_lock());
       }
       SLEEP(10);
       cm_perform_irrevocable_tx_wait_priority_promotion(*this);
@@ -164,22 +161,16 @@
       }
 
       {
- //lock(general_lock());
       synchro::lock_guard<Mutex> lock_g(*general_lock());
- //lock(inflight_lock());
       synchro::lock_guard<Mutex> lock_i(*inflight_lock());
 
       if (!irrevocableTxInFlight() && canAbortAllInFlightTxs())
       {
          tx_type(eIrrevocableAndIsolatedTx);
          abortAllInFlightTxs();
- //unlock(general_lock());
- //unlock(inflight_lock());
          return;
       }
 
- //unlock(general_lock());
- //unlock(inflight_lock());
      }
       //SLEEP(10);
       cm_perform_isolated_tx_wait_priority_promotion(*this);
@@ -239,7 +230,6 @@
 
    synchro::lock_guard<Mutex> lock_g(*general_lock());
    synchro::lock_guard<Mutex> lock_m(*mutex());
- //lock_tx();
 
    //--------------------------------------------------------------------------
    // this is a very important and subtle optimization. if the transaction is
@@ -249,12 +239,9 @@
    //--------------------------------------------------------------------------
    if (is_only_reading())
    {
- //unlock(general_lock());
- //unlock_tx();
    }
    else
    {
- //lock(inflight_lock());
       synchro::lock_guard<Mutex> lock_i(*inflight_lock());
 
       //-----------------------------------------------------------------------
@@ -267,9 +254,6 @@
       deferredCommitTransactionNewMemory();
       deferredCommitTransactionDeletedMemory();
 
- //unlock_tx();
- //unlock(general_lock());
- //unlock(inflight_lock());
    }
 
    //--------------------------------------------------------------------------
@@ -589,13 +573,11 @@
 #if PERFORMING_COMPOSITION
 #ifdef USING_SHARED_FORCED_TO_ABORT
    {
- //lock(inflight_lock());
    synchro::lock_guard<Mutex> lock_i(*inflight_lock());
    if (!otherInFlightTransactionsOfSameThreadNotIncludingThis(this))
    {
       unforce_to_abort();
    }
- //unlock(inflight_lock());
    }
 #else
    unforce_to_abort();
@@ -668,26 +650,21 @@
    while (true)
    {
       {
- //lock(inflight_lock());
       synchro::lock_guard<Mutex> lock_i(*inflight_lock());
 
       if (latm::instance().can_go_inflight() && !isolatedTxInFlight())
       {
          transactionsInFlight_.insert(this);
          state_ = e_in_flight;
- //unlock(inflight_lock());
          break;
       }
 
- //unlock(inflight_lock());
       }
       SLEEP(10);
    }
 #else
    synchro::lock_guard<Mutex> lock_i(*inflight_lock());
- //lock(inflight_lock());
    transactionsInFlight_.insert(this);
- //unlock(inflight_lock());
    state_ = e_in_flight;
 #endif
 }
@@ -788,9 +765,11 @@
    }
 
    synchro::lock(*general_lock());
+ //synchro::unique_lock<Mutex> lk_g(*general_lock());
    //lock_tx();
    synchro::lock(*mutex());
-
+ //synchro::lock_guard<Mutex> lk_m(*mutex());
+ // direct_abort_if_not_commited_and_not_handoff(this);
 
    //--------------------------------------------------------------------------
    // erase this from the inflight transactions so processing through the
@@ -806,30 +785,32 @@
       // so unlock it so we can reduce contention
       //-----------------------------------------------------------------------
       bool wasWriting = isWriting() ? true : false;
- if (!wasWriting) synchro::unlock(*general_lock());
- direct_abort();
- //unlock_tx();
- synchro::unlock(*mutex());
+ if (!wasWriting) synchro::unlock(*general_lock()); // TBR
+ //if (!wasWriting) lk_g.unlock();
+ direct_abort(); // TBR
+ synchro::unlock(*mutex()); // TBR
 
       //-----------------------------------------------------------------------
       // if this tx was writing, unlock the transaction mutex now
       //-----------------------------------------------------------------------
- if (wasWriting) synchro::unlock(*general_lock());
+ if (wasWriting) synchro::unlock(*general_lock());// TBR
       throw aborted_transaction_exception
       ("aborting committing transaction due to contention manager priority inversion");
    }
 
- lock_all_mutexes_but_this(threadId_);
+ lock_all_mutexes_but_this(threadId_);// TBR
+ // all_mutexes_but_this all_but_this(this, threadId_);
 
- synchro::lock(*inflight_lock());
+ synchro::lock(*inflight_lock());// TBR
+ //synchro::lock_guard<Mutex> lk_i(*inflight_lock());
    transactionsInFlight_.erase(this);
 
    if (other_in_flight_same_thread_transactions())
    {
       state_ = e_hand_off;
- unlock_all_mutexes();
- synchro::unlock(*general_lock());
- synchro::unlock(*inflight_lock());
+ unlock_all_mutexes();// TBR
+ synchro::unlock(*general_lock());// TBR
+ synchro::unlock(*inflight_lock());// TBR
       bookkeeping_.inc_handoffs();
    }
    else
@@ -842,6 +823,8 @@
          unlock_all_mutexes();
          synchro::unlock(*general_lock());
          synchro::unlock(*inflight_lock());
+ } else {
+ std::cout << "invalidating_direct_end_transaction e_committed != state_" << std::endl;
       }
    }
 }
@@ -872,41 +855,41 @@
    //--------------------------------------------------------------------------
    if (is_only_reading())
    {
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
- synchro::lock(*inflight_lock());
- transactionsInFlight_.erase(this);
+ {
+ synchro::unique_lock<Mutex> lk_i(*inflight_lock());
+
+ transactionsInFlight_.erase(this);
 
 #if PERFORMING_COMPOSITION
- if (other_in_flight_same_thread_transactions())
- {
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
- synchro::unlock(*inflight_lock());
- state_ = e_hand_off;
- bookkeeping_.inc_handoffs();
- }
- else
+ if (other_in_flight_same_thread_transactions())
+ {
+
+ state_ = e_hand_off;
+ bookkeeping_.inc_handoffs();
+ }
+ else
 #endif
- {
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
- synchro::unlock(*inflight_lock());
- tx_type(eNormalTx);
+ {
+
+ lk_i.unlock();
+ tx_type(eNormalTx);
 #if PERFORMING_LATM
- get_tx_conflicting_locks().clear();
- clear_latm_obtained_locks();
+ get_tx_conflicting_locks().clear();
+ clear_latm_obtained_locks();
 #endif
- state_ = e_committed;
- }
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
- ++global_clock();
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
-
- return;
- }
+ state_ = e_committed;
+ }
+ }
+ ++global_clock();
 
- while (!synchro::try_lock(transactionMutex_)) {
- //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
+ return;
     }
 
+ //while (!synchro::try_lock(*general_lock())) {}
+ synchro::lock(*general_lock());
+ //synchro::unique_lock<Mutex> lk_g(*general_lock());
+
+
    //--------------------------------------------------------------------------
    // as much as I'd like to transactionsInFlight_.erase() here, we have
    // to do it inside of abort() because the contention managers must abort
@@ -917,7 +900,8 @@
     //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
    if (forced_to_abort())
    {
- synchro::unlock(*general_lock());
+ synchro::unlock(*general_lock()); //TBR
+ //lk.g.unlock();
       deferred_abort(true);
       throw aborted_transaction_exception
       ("aborting committing transaction due to contention manager priority inversion");
@@ -938,8 +922,10 @@
       // transactionsInFlightMutex
       //-----------------------------------------------------------------------
     //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
- lock_all_mutexes();
+ lock_all_mutexes(); //TBR
+ //all_mutexes lk_all(this);
       synchro::lock(*inflight_lock());
+ //synchro::unique_lock<Mutex> lk_i(*inflight_lock());
 
 #if PERFORMING_COMPOSITION
       if (other_in_flight_same_thread_transactions())
@@ -947,9 +933,9 @@
     //std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
          transactionsInFlight_.erase(this);
          state_ = e_hand_off;
- unlock_all_mutexes();
- synchro::unlock(*general_lock());
- synchro::unlock(*inflight_lock());
+ unlock_all_mutexes();//TBR
+ synchro::unlock(*general_lock());//TBR
+ synchro::unlock(*inflight_lock());//TBR
          bookkeeping_.inc_handoffs();
       }
       else
@@ -1057,7 +1043,6 @@
       //bookkeeping_.inc_abort_perm_denied(threadId_);
       synchro::unlock(*inflight_lock());
       synchro::unlock(*general_lock());
- //unlock_tx();
       synchro::unlock(*mutex());
       throw aborted_transaction_exception
       ("aborting commit due to CM priority");

Modified: sandbox/stm/branches/vbe/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction.hpp 2009-11-03 15:31:47 EST (Tue, 03 Nov 2009)
@@ -327,7 +327,7 @@
       tm_lock_conflict(&lock);
    }
    static void tm_lock_conflict(latm::mutex_type* lock);
-
+
    static void clear_tm_conflicting_locks();
    //inline static latm::mutex_set get_tm_conflicting_locks() { return tmConflictingLocks_; }
 
@@ -351,8 +351,8 @@
 
    void clear_tx_conflicting_locks();
    //latm::mutex_set get_tx_conflicting_locks() { return conflictingMutexRef_; }
-
-
+
+
     #endif
 
    void add_to_obtained_locks(latm::mutex_type* mutex);
@@ -385,13 +385,10 @@
       // infinitely fail
       //-----------------------------------------------------------------------
       synchro::lock_guard<Mutex> lock_m(*inflight_lock());
- //lock(inflight_lock());
       if (other_in_flight_same_thread_transactions())
       {
- //unlock(inflight_lock());
          throw aborted_transaction_exception("closed nesting throw");
       }
- //unlock(inflight_lock());
 
       return true;
    }
@@ -856,14 +853,12 @@
       // memory - since we need to ensure other threads don't try to
       // manipulate this at the same time we are going to
       //-----------------------------------------------------------------------
- //lock(&transactionMutex_);
       synchro::lock_guard<Mutex> lock_m(transactionMutex_);
 
       // we currently don't allow write stealing in direct update. if another
       // tx beat us to the memory, we abort
       if (in.transaction_thread() != invalid_thread_id())
       {
- //unlock(&transactionMutex_);
          throw aborted_tx("direct writer already exists.");
       }
 
@@ -872,7 +867,6 @@
 #if USE_BLOOM_FILTER
       bloom().insert((std::size_t)&in);
 #endif
- //unlock(&transactionMutex_);
       return in;
    }
 
@@ -891,19 +885,15 @@
       // and see if anyone else is writing to it. if not, we add the item to
       // our write list and our deletedList
       //-----------------------------------------------------------------------
- //lock(&transactionMutex_);
       synchro::unique_lock<Mutex> lock_m(transactionMutex_);
 
       if (in.transaction_thread() != invalid_thread_id())
       {
- //unlock(&transactionMutex_);
          cm_abort_on_write(*this, (base_transaction_object&)(in));
       }
       else
       {
          in.transaction_thread(threadId_);
-
- //unlock(&transactionMutex_);
          lock_m.unlock();
          // is this really necessary? in the deferred case it is, but in direct it
          // doesn't actually save any time for anything
@@ -928,18 +918,15 @@
       // and see if anyone else is writing to it. if not, we add the item to
       // our write list and our deletedList
       //-----------------------------------------------------------------------
- //lock(&transactionMutex_);
       synchro::unique_lock<Mutex> lock_m(transactionMutex_);
 
       if (in.transaction_thread() != invalid_thread_id())
       {
- //unlock(&transactionMutex_);
          cm_abort_on_write(*this, (base_transaction_object&)(in));
       }
       else
       {
          in.transaction_thread(threadId_);
- //unlock(&transactionMutex_);
          lock_m.unlock();
          // is this really necessary? in the deferred case it is, but in direct it
          // doesn't actually save any time for anything
@@ -1040,11 +1027,9 @@
       if (i == writeList().end())
       {
          // get the lock before we make a copy of this object
- //lock_tx();
          synchro::unique_lock<Mutex> lock(*mutex());
 #if USE_BLOOM_FILTER
          bloom().insert((std::size_t)&in);
- //unlock_tx();
          lock.unlock();
 #else
 
@@ -1057,9 +1042,6 @@
          base_transaction_object* returnValue = in.clone(this);
          returnValue->transaction_thread(threadId_);
          writeList().insert(tx_pair((base_transaction_object*)&in, returnValue));
-#ifndef USE_BLOOM_FILTER
- //unlock_tx();
-#endif
          return *static_cast<T*>(returnValue);
       }
       else {
@@ -1245,7 +1227,8 @@
 
    static int thread_id_occurance_in_locked_locks_map(thread_id_t threadId);
 
- static void wait_until_all_locks_are_released(bool);
+ static void wait_until_all_locks_are_released();
+ static void wait_until_all_locks_are_released_and_set(latm::mutex_type* mutex);
 
    //--------------------------------------------------------------------------
    // deferred updating locking methods
@@ -1852,7 +1835,7 @@
 inline transaction* current_transaction() {return transaction::current_transaction();}
 
 inline void lock(latm::mutex_type& lock) {transaction::pthread_lock(&lock);}
-inline bool try_lock(latm::mutex_type& lock) {return transaction::pthread_trylock(&lock);}
+inline bool try_lock(latm::mutex_type& lock) {return transaction::pthread_trylock(&lock);}
 inline void unlock(latm::mutex_type& lock) {transaction::pthread_unlock(&lock);}
 
 


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