Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56977 - in sandbox/stm/branches/vbe/boost/stm: . detail
From: vicente.botet_at_[hidden]
Date: 2009-10-18 08:27:01


Author: viboes
Date: 2009-10-18 08:27:00 EDT (Sun, 18 Oct 2009)
New Revision: 56977
URL: http://svn.boost.org/trac/boost/changeset/56977

Log:
TBoost.STM vbe:
* Remove var_auto_lock as it is not exception safe
* Replace light_auto_lock by synchro::unique_lock
* BUG: improve the general lock when getting the transactions stack

Text files modified:
   sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 3
   sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 7
   sandbox/stm/branches/vbe/boost/stm/synchro.hpp | 266 ---------------------------------------
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 37 ++---
   4 files changed, 24 insertions(+), 289 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/config.hpp 2009-10-18 08:27:00 EDT (Sun, 18 Oct 2009)
@@ -34,7 +34,7 @@
 // OTHER: each TSS data has its specific TSS
 
 #define USE_SINGLE_THREAD_CONTEXT_MAP 1
-//#define BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP 1
+#define BOOST_STM_HAVE_SINGLE_TSS_CONTEXT_MAP 1
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -102,6 +102,7 @@
 #define BOOST_STM_ALLOWS_DELETERS 1
 
 #define BOOST_STM_USE_BOOST_SYNCHRO 1
+
 #endif // BOOST_STM_DETAIL_CONFIG_H
 
 

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-10-18 08:27:00 EDT (Sun, 18 Oct 2009)
@@ -396,7 +396,7 @@
 inline transaction::transaction() :
    threadId_(THREAD_ID),
    //transactionMutexLocker_(),
- auto_general_lock_(general_lock()),
+ auto_general_lock_(*general_lock()),
 
 #if USE_SINGLE_THREAD_CONTEXT_MAP
 ////////////////////////////////////////
@@ -444,7 +444,7 @@
    currentlyLockedLocksRef_(*threadCurrentlyLockedLocks_.find(threadId_)->second),
 #endif
 #endif
- transactionsRef_(transactions(threadId_)),
+ transactionsRef_(transactions_unsafe(threadId_)),
 
 ////////////////////////////////////////
 #else
@@ -481,7 +481,7 @@
    currentlyLockedLocksRef_(*threadCurrentlyLockedLocks_.find(threadId_)->second),
 #endif
 ////////////////////////////////////////
- transactionsRef_(transactions(threadId_)),
+ transactionsRef_(transactions_unsafe(threadId_)),
 
 #endif
 
@@ -491,6 +491,7 @@
    reads_(0),
    startTime_(time(0))
 {
+ auto_general_lock_.unlock();
    if (direct_updating()) doIntervalDeletions();
 #if PERFORMING_LATM
    while (blocked()) { SLEEP(10) ; }

Modified: sandbox/stm/branches/vbe/boost/stm/synchro.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/synchro.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/synchro.hpp 2009-10-18 08:27:00 EDT (Sun, 18 Oct 2009)
@@ -45,6 +45,8 @@
    typedef boost::mutex Mutex;
 #endif
 
+typedef pthread_mutex_t PLOCK;
+
 //-----------------------------------------------------------------------------
 
 namespace boost {
@@ -86,17 +88,6 @@
         return lockable.try_lock();
     }
 
-#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
- template <typename Lockable, typename TimeDuration >
- bool lock_for(Lockable& lockable, const TimeDuration& rel_time) {
- return lock_until(&lockable, get_system_time()+rel_time);
- }
-
- template< typename Lockable>
- inline bool lock_until(Lockable& lockable, system_time const& target_time) {
- return lockable.timed_lock(target_time);
- }
-#endif
     template<>
     inline void lock<pthread_mutex_t>(pthread_mutex_t& lockable) {
         pthread_mutex_lock(&lockable);
@@ -112,18 +103,6 @@
         return pthread_mutex_trylock(&lockable);
     }
 
-#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
- template<>
- inline bool lock_until<pthread_mutex_t>(
- pthread_mutex_t& lockable, system_time const& abs_time) {
- struct timespec const timeout=boost::detail::get_timespec(abs_time);
- int const res=pthread_mutex_timedlock(&lockable,&timeout);
- //BOOST_ASSERT(!res || res==ETIMEDOUT);
- return !res;
- }
-#endif
-
-
     template<typename Mutex>
     class lock_guard
     {
@@ -203,89 +182,12 @@
         {
             try_lock();
         }
-#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
- template<typename TimeDuration>
- unique_lock(Mutex& m_,TimeDuration const& target_time):
- m(&m_),is_locked(false)
- {
- timed_lock(target_time);
- }
- unique_lock(Mutex& m_,boost::system_time const& target_time):
- m(&m_),is_locked(false)
- {
- timed_lock(target_time);
- }
-#endif
-#if 0
-#ifdef BOOST_HAS_RVALUE_REFS
- unique_lock(unique_lock&& other):
- m(other.m),is_locked(other.is_locked)
- {
- other.is_locked=false;
- other.m=0;
- }
- unique_lock<Mutex>&& move()
- {
- return static_cast<unique_lock<Mutex>&&>(*this);
- }
-
-
- unique_lock& operator=(unique_lock<Mutex>&& other)
- {
- unique_lock temp(other);
- swap(temp);
- return *this;
- }
-
- void swap(unique_lock&& other)
- {
- std::swap(m,other.m);
- std::swap(is_locked,other.is_locked);
- }
-#else
- unique_lock(detail::thread_move_t<unique_lock<Mutex> > other):
- m(other->m),is_locked(other->is_locked)
- {
- other->is_locked=false;
- other->m=0;
- }
-
- operator detail::thread_move_t<unique_lock<Mutex> >()
- {
- return move();
- }
-
- detail::thread_move_t<unique_lock<Mutex> > move()
- {
- return detail::thread_move_t<unique_lock<Mutex> >(*this);
- }
-
- unique_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other)
- {
- unique_lock temp(other);
- swap(temp);
- return *this;
- }
-
- void swap(unique_lock& other)
- {
- std::swap(m,other.m);
- std::swap(is_locked,other.is_locked);
- }
- void swap(detail::thread_move_t<unique_lock<Mutex> > other)
- {
- std::swap(m,other->m);
- std::swap(is_locked,other->is_locked);
- }
-#endif
-#else
         void swap(unique_lock& other)
         {
             std::swap(m,other.m);
             std::swap(is_locked,other.is_locked);
         }
         
-#endif
         ~unique_lock()
         {
             if(owns_lock())
@@ -311,25 +213,6 @@
             is_locked=synchro::try_lock(*m);
             return is_locked;
         }
-#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
- template<typename TimeDuration>
- bool timed_lock(TimeDuration const& relative_time)
- {
- is_locked=synchro::timed_lock(*m, relative_time);
- return is_locked;
- }
-
- bool timed_lock(::boost::system_time const& absolute_time)
- {
- is_locked=synchro::timed_lock(*m, absolute_time);
- return is_locked;
- }
- bool timed_lock(::boost::xtime const& absolute_time)
- {
- is_locked=synchro::timed_lock(*m, absolute_time);
- return is_locked;
- }
-#endif
         void unlock()
         {
             if(!owns_lock())
@@ -368,158 +251,15 @@
         }
     };
 
-#if 0
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex>
- void swap(unique_lock<Mutex>&& lhs,unique_lock<Mutex>&& rhs)
- {
- lhs.swap(rhs);
- }
-#else
- template<typename Mutex>
- void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
- {
- lhs.swap(rhs);
- }
-#endif
-#else
     template<typename Mutex>
     void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
     {
         lhs.swap(rhs);
- }
-#endif
-
-#if 0
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex>
- inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul)
- {
- return ul;
- }
-#endif
-#endif
-
-
+ }
 }
 #endif
 namespace stm {
 
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-
-typedef pthread_mutex_t PLOCK;
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-
- inline int lock22(PLOCK &lock) { return pthread_mutex_lock(&lock); }
- inline int lock22(PLOCK *lock) { return pthread_mutex_lock(lock); }
-
- inline int trylock22(PLOCK &lock) { return pthread_mutex_trylock(&lock); }
- inline int trylock22(PLOCK *lock) { return pthread_mutex_trylock(lock); }
-
- inline int unlock22(PLOCK &lock) { return pthread_mutex_unlock(&lock); }
- inline int unlock22(PLOCK *lock) { return pthread_mutex_unlock(lock); }
-
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-
-class light_auto_lock
-{
-public:
-
- light_auto_lock(Mutex &mutex) : lock_(0)
- {
- do_auto_lock(&mutex);
- }
-
- light_auto_lock(Mutex *mutex) : lock_(0)
- {
- do_auto_lock(mutex);
- }
-
- ~light_auto_lock() { do_auto_unlock(); }
-
- bool has_lock() { return hasLock_; }
-
- void release_lock() { do_auto_unlock(); }
-
-private:
-
- void do_auto_lock(Mutex *mutex)
- {
- lock_ = mutex;
- synchro::lock(*mutex);
- hasLock_ = true;
- }
-
- void do_auto_unlock()
- {
- if (hasLock_)
- {
- hasLock_ = false;
- synchro::unlock(*lock_);
- }
- }
-
- bool hasLock_;
- Mutex *lock_;
-};
-
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-template <typename T>
-class var_auto_lock
-{
-public:
-
- //--------------------------------------------------------------------------
- typedef T lock_type;
- typedef std::list<lock_type*> lock_list;
-
- //--------------------------------------------------------------------------
- var_auto_lock(lock_type *l, ...)
- {
- va_list ap;
- va_start(ap, l);
-
- while (l)
- {
- lockList_.push_back(l);
- l = va_arg(ap, lock_type*);
- }
-
- va_end(ap);
-
- std::list<PLOCK*>::iterator i = lockList_.begin();
-
- for (; i != lockList_.end(); ++i)
- {
- synchro::lock(**i);
- }
- }
-
- //--------------------------------------------------------------------------
- ~var_auto_lock()
- {
- for (std::list<PLOCK*>::iterator i = lockList_.begin(); i != lockList_.end(); ++i)
- {
- synchro::unlock(**i);
- }
- }
-
-private:
- std::list<lock_type*> lockList_;
-
-};
-
 
 } // namespace core
 }

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-10-18 08:27:00 EDT (Sun, 18 Oct 2009)
@@ -100,12 +100,6 @@
 
 typedef std::pair<base_transaction_object*, base_transaction_object*> tx_pair;
 
- template <typename MUTEX, MUTEX& mtx>
- struct locker {
- inline locker();
- inline ~locker();
- inline void unlock();
- };
 
 ///////////////////////////////////////////////////////////////////////////////
 // transaction Class
@@ -1512,8 +1506,7 @@
    //--------------------------------------------------------------------------
    size_t threadId_;
 
- light_auto_lock auto_general_lock_;
- //locker<Mutex, transactionMutex_> transactionMutexLocker_;
+ synchro::unique_lock<Mutex> auto_general_lock_;
 
    //--------------------------------------------------------------------------
    // ******** WARNING ******** MOVING threadId_ WILL BREAK TRANSACTION.
@@ -1684,7 +1677,11 @@
    public:
     inline TransactionsStack& transactions() {return transactionsRef_;}
     inline static TransactionsStack &transactions(thread_id_t id) {
- light_auto_lock auto_general_lock_(general_lock());
+ synchro::lock_guard<Mutex> auto_general_lock_(*general_lock());
+ return *threadTransactionsStack_.find(id)->second;
+ }
+ inline static TransactionsStack &transactions_unsafe(thread_id_t id) {
+ //synchro::lock_guard<Mutex> auto_general_lock_(*general_lock());
         return *threadTransactionsStack_.find(id)->second;
     }
     private:
@@ -1851,7 +1848,11 @@
    public:
     inline TransactionsStack& transactions() {return transactionsRef_;}
     inline static TransactionsStack &transactions(thread_id_t id) {
- light_auto_lock auto_general_lock_(general_lock());
+ synchro::lock_guard<Mutex> auto_general_lock_(*general_lock());
+ tss_context_map_type::iterator i = tss_context_map_.find(id);
+ return i->second->transactions_;
+ }
+ inline static TransactionsStack &transactions_unsafe(thread_id_t id) {
         tss_context_map_type::iterator i = tss_context_map_.find(id);
         return i->second->transactions_;
     }
@@ -2002,7 +2003,10 @@
    public:
     inline TransactionsStack& transactions() {return transactionsRef_;}
     inline static TransactionsStack &transactions(thread_id_t id) {
- light_auto_lock auto_general_lock_(general_lock());
+ synchro::lock_guard<Mutex> auto_general_lock_(*general_lock());
+ return *threadTransactionsStack_.find(id)->second;
+ }
+ inline static TransactionsStack &transactions_unsafe(thread_id_t id) {
         return *threadTransactionsStack_.find(id)->second;
     }
     private:
@@ -2034,17 +2038,6 @@
 
 inline transaction* current_transaction() {return transaction::current_transaction();}
 
-template <typename MUTEX, MUTEX& mtx>
-locker<MUTEX,mtx>::locker() {
- synchro::lock(mtx);
-}
-template <typename MUTEX, MUTEX& mtx>
-locker<MUTEX,mtx>::~locker() {}
-
-template <typename MUTEX, MUTEX& mtx>
-void locker<MUTEX,mtx>::unlock() {
- synchro::unlock(mtx);
-}
 
 template <class T> T* cache_allocate(transaction* t) {
     #if defined(BOOST_STM_CACHE_USE_MEMORY_MANAGER) && defined (USE_STM_MEMORY_MANAGER)


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