Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51258 - in sandbox/synchro/boost/synchro: . process thread
From: vicente.botet_at_[hidden]
Date: 2009-02-15 08:09:47


Author: viboes
Date: 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
New Revision: 51258
URL: http://svn.boost.org/trac/boost/changeset/51258

Log:
Boost.Synchro V0.0.0
Adding try_unique_locker and exception based timed locks constructors
Text files modified:
   sandbox/synchro/boost/synchro/lockable_concepts.hpp | 8
   sandbox/synchro/boost/synchro/lockers.hpp | 29 +++++
   sandbox/synchro/boost/synchro/process/locks.hpp | 212 ++++++++++++++++++++++++++++++++++++---
   sandbox/synchro/boost/synchro/process/named_upgradable_mutex.hpp | 10 +
   sandbox/synchro/boost/synchro/thread/locks.hpp | 171 ++++++++++++++++++++++++++++---
   5 files changed, 382 insertions(+), 48 deletions(-)

Modified: sandbox/synchro/boost/synchro/lockable_concepts.hpp
==============================================================================
--- sandbox/synchro/boost/synchro/lockable_concepts.hpp (original)
+++ sandbox/synchro/boost/synchro/lockable_concepts.hpp 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
@@ -39,7 +39,7 @@
         l.unlock();
         l.try_lock();
     }
- Lockable l;
+ Lockable& l;
 };
 //]
 /**
@@ -56,7 +56,7 @@
         l.try_lock_until(t);
 // l.try_lock_for(1);
     }
- Lockable l;
+ Lockable& l;
     system_time t;
 };
 //]
@@ -77,7 +77,7 @@
         l.try_lock_shared();
         l.unlock_shared();
     }
- Lockable l;
+ Lockable& l;
     system_time t;
 };
 //]
@@ -103,7 +103,7 @@
         l.unlock_and_lock_shared();
         l.unlock_upgrade_and_lock_shared();
     }
- Lockable l;
+ Lockable& l;
     system_time t;
 };
 //]

Modified: sandbox/synchro/boost/synchro/lockers.hpp
==============================================================================
--- sandbox/synchro/boost/synchro/lockers.hpp (original)
+++ sandbox/synchro/boost/synchro/lockers.hpp 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
@@ -17,6 +17,8 @@
 
 namespace boost { namespace synchro {
 
+ struct force_lock_t
+ {};
     struct defer_lock_t
     {};
     struct try_to_lock_t
@@ -27,6 +29,8 @@
     {};
 
 
+
+ const force_lock_t force_lock={};
     const defer_lock_t defer_lock={};
     const try_to_lock_t try_to_lock={};
     const adopt_lock_t adopt_lock={};
@@ -36,6 +40,9 @@
     class unique_locker;
 
     template<typename Mutex, typename ScopeTag=typename scope_tag<Mutex>::type>
+ class try_unique_locker;
+
+ template<typename Mutex, typename ScopeTag=typename scope_tag<Mutex>::type>
     class shared_locker;
 
     template<typename Mutex, typename ScopeTag=typename scope_tag<Mutex>::type>
@@ -66,6 +73,28 @@
     }
 #endif
 
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex, typename ScopeTag>
+ void swap(try_unique_locker<Mutex, ScopeTag>&& lhs, try_unique_locker<Mutex, ScopeTag>&& rhs)
+ {
+ lhs.swap(rhs);
+ }
+#else
+ template<typename Mutex, typename ScopeTag>
+ void swap(try_unique_locker<Mutex, ScopeTag>& lhs, try_unique_locker<Mutex, ScopeTag>& rhs)
+ {
+ lhs.swap(rhs);
+ }
+#endif
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex, typename ScopeTag>
+ inline try_unique_locker<Mutex, ScopeTag>&& move(try_unique_locker<Mutex, ScopeTag>&& ul)
+ {
+ return ul;
+ }
+#endif
+
     #ifdef BOOST_HAS_RVALUE_REFS
     template<typename Mutex, typename ScopeTag>
     void swap(shared_locker<Mutex, ScopeTag>&& lhs,shared_locker<Mutex, ScopeTag>&& rhs)

Modified: sandbox/synchro/boost/synchro/process/locks.hpp
==============================================================================
--- sandbox/synchro/boost/synchro/process/locks.hpp (original)
+++ sandbox/synchro/boost/synchro/process/locks.hpp 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
@@ -71,6 +71,17 @@
         {
             lock_until(target_time);
         }
+ template<typename TimeDuration>
+ unique_locker(TimeDuration const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ lock_for(target_time);
+ }
+ unique_locker(system_time const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ lock_until(target_time);
+ }
 #ifdef BOOST_HAS_RVALUE_REFS
         unique_locker(unique_locker&& other): base_type(other)
         {}
@@ -194,29 +205,186 @@
         friend class shared_locker<Mutex,scope_tag_type>;
         friend class upgrade_locker<Mutex,scope_tag_type>;
     };
-#if 0
+
+
+ template<typename Mutex>
+ class try_unique_locker<Mutex,multi_process_tag>: public unique_locker<Mutex,multi_process_tag> {
+ //typename scope_tag<Mutex>::type == multi_process_tag
+ private:
+ typedef Mutex lockable_type;
+ typedef multi_process_tag scope_tag_type;
+ typedef unique_locker<Mutex,multi_process_tag> base_type;
+ try_unique_locker(try_unique_locker&);
+ explicit try_unique_locker(try_unique_locker<Mutex, scope_tag_type>&);
+ try_unique_locker& operator=(try_unique_locker&);
+ try_unique_locker& operator=(try_unique_locker<Mutex, scope_tag_type>& other);
+ public:
+ try_unique_locker(): base_type()
+ {}
+
+ explicit try_unique_locker(Mutex& m_): base_type(m_, boost::interprocess::defer_lock)
+ {
+ this->try_lock();
+ }
+ try_unique_locker(Mutex& m_,force_lock_t): base_type(m_)
+ {}
+ try_unique_locker(Mutex& m_,adopt_lock_t): base_type(m_, boost::interprocess::accept_ownership)
+ {}
+ try_unique_locker(Mutex& m_,defer_lock_t): base_type(m_, boost::interprocess::defer_lock)
+ {}
+ try_unique_locker(Mutex& m_,try_to_lock_t): base_type(m_, boost::interprocess::try_to_lock)
+ {}
+ template<typename TimeDuration>
+ try_unique_locker(Mutex& m_,TimeDuration const& target_time): base_type(m_, target_time)
+ {}
+ try_unique_locker(Mutex& m_,system_time const& target_time): base_type(m_, target_time)
+ {}
+ template<typename TimeDuration>
+ try_unique_locker(Mutex& m_,TimeDuration const& target_time, throw_lock_t)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_for(target_time);
+ }
+ try_unique_locker(Mutex& m_,system_time const& target_time, throw_lock_t)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_until(target_time);
+ }
+ template<typename TimeDuration>
+ try_unique_locker(TimeDuration const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_for(target_time);
+ }
+ try_unique_locker(system_time const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_until(target_time);
+ }
 #ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex, typename ScopeTag>
- void swap(unique_locker<Mutex, ScopeTag>&& lhs, unique_locker<Mutex, ScopeTag>&& rhs)
- {
- lhs.swap(rhs);
- }
+ try_unique_locker(try_unique_locker&& other): base_type(other)
+ {}
+ explicit try_unique_locker(upgrade_locker<Mutex,scope_tag_type>&& other) : base_type(other)
+ {}
+
+ try_unique_locker<Mutex, scope_tag_type>&& move()
+ {
+ return static_cast<try_unique_locker<Mutex, scope_tag_type>&&>(*this);
+ }
+
+
+ try_unique_locker& operator=(try_unique_locker<Mutex, scope_tag_type>&& other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ try_unique_locker& operator=(upgrade_locker<Mutex>&& other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+ void swap(try_unique_locker&& other)
+ {
+ this->base_type.swap(other);
+ }
 #else
- template<typename Mutex, typename ScopeTag>
- void swap(unique_locker<Mutex, ScopeTag>& lhs, unique_locker<Mutex, ScopeTag>& rhs)
- {
- lhs.swap(rhs);
- }
-#endif
+ try_unique_locker(interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> > other)
+ : base_type(interprocess::detail::moved_object<base_type>(other.get()))
+ {}
+ try_unique_locker(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> > other)
+ : base_type(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> >(other.get()))
+ {}
+ // interprocess specific
+ try_unique_locker(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> > other
+ , try_to_lock_t)
+ : base_type(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> >(other.get())
+ , boost::interprocess::try_to_lock)
+ {}
 
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex, typename ScopeTag>
- inline unique_locker<Mutex, ScopeTag>&& move(unique_locker<Mutex, ScopeTag>&& ul)
- {
- return ul;
- }
-#endif
+ // interprocess specific
+ try_unique_locker(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> > other
+ , system_time const& target_time)
+ : base_type(interprocess::detail::moved_object<upgrade_locker<Mutex,scope_tag_type> >(other.get())
+ , target_time)
+ {}
+
+ operator interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> >()
+ {
+ return move();
+ }
+
+ interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> > move()
+ {
+ return interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> >(*this);
+ }
+
+ try_unique_locker& operator=(interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> > other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ try_unique_locker& operator=(interprocess::detail::moved_object<upgrade_locker<Mutex, scope_tag_type> > other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+ void swap(try_unique_locker& other)
+ {
+ this->base_type.swap(other);
+ }
+ void swap(interprocess::detail::moved_object<try_unique_locker<Mutex, scope_tag_type> > other)
+ {
+ this->base_type.swap(interprocess::detail::moved_object<base_type>(other.get()));
+ }
 #endif
+
+ ~try_unique_locker() {}
+
+ Mutex* mutex() const
+ {
+ return static_cast<Mutex*>(this->base_type.mutex());
+ }
+
+ bool is_locking(lockable_type* l) const {
+ return l==mutex();
+ } /*< strict lockers specific function >*/
+
+ bool owns_lock() const {
+ return this->owns();
+ }
+
+ template<typename TimeDuration>
+ bool try_lock_for(TimeDuration const& relative_time)
+ {
+ return this->timed_lock(relative_time);
+ }
+
+ bool try_lock_until(::boost::system_time const& absolute_time)
+ {
+ return this->timed_lock(absolute_time);
+ }
+
+ template<typename TimeDuration>
+ void lock_for(TimeDuration const& relative_time)
+ {
+ if(!try_lock_for(relative_time)) throw timeout_exception();
+ }
+
+ void lock_until(::boost::system_time const& absolute_time)
+ {
+ if(!try_lock_until(absolute_time)) throw timeout_exception();
+ }
+
+ friend class shared_locker<Mutex,scope_tag_type>;
+ friend class upgrade_locker<Mutex,scope_tag_type>;
+ };
+
     template<typename Mutex>
     class shared_locker<Mutex,multi_process_tag>: public shared_lock_type<Mutex>::type {
         //typename scope_tag<Mutex>::type == multi_process_tag
@@ -251,10 +419,14 @@
             lock_until(target_time);
         }
         template<typename TimeDuration>
+ shared_locker(Mutex& m_,TimeDuration const& target_time,throw_lock_t)
+ {
+ lock_for(target_time);
+ }
         shared_locker(Mutex& m_,system_time const& target_time,throw_lock_t)
             : base_type(m_, boost::interprocess::defer_lock)
         {
- lock_for(target_time);
+ lock_until(target_time);
         }
 
 

Modified: sandbox/synchro/boost/synchro/process/named_upgradable_mutex.hpp
==============================================================================
--- sandbox/synchro/boost/synchro/process/named_upgradable_mutex.hpp (original)
+++ sandbox/synchro/boost/synchro/process/named_upgradable_mutex.hpp 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
@@ -36,14 +36,14 @@
 public:
     typedef boost::interprocess::interprocess_condition condition_type;
     typedef boost::interprocess::interprocess_condition condition_any_type;
-#if 1
+
     interprocess_named_upgradable_mutex(interprocess::create_only_t create_only, const char *name)
            : interprocess::named_upgradable_mutex(create_only, name) {};
        interprocess_named_upgradable_mutex(interprocess::open_or_create_t open_or_create, const char *name)
           : interprocess::named_upgradable_mutex(open_or_create, name) {};
       interprocess_named_upgradable_mutex(interprocess::open_only_t open_only, const char *name)
           : interprocess::named_upgradable_mutex(open_only, name) {};
-#endif
+
     bool try_lock_until(system_time const & abs_time)
     {return timed_lock(abs_time);}
     template<typename TimeDuration>
@@ -90,10 +90,12 @@
     void unlock_and_lock_shared()
     {unlock_and_lock_sharable();}
 
+ void unlock_upgrade_and_lock_shared()
+ {
+ unlock_upgradable_and_lock_sharable();
 #if 0
- void unlock_upgrade_and_lock_shared();
- {unlock_upgradable_and_lock_sharable();}
 #endif
+ }
     void unlock_upgrade_and_lock()
     {unlock_upgrade_and_lock();}
 

Modified: sandbox/synchro/boost/synchro/thread/locks.hpp
==============================================================================
--- sandbox/synchro/boost/synchro/thread/locks.hpp (original)
+++ sandbox/synchro/boost/synchro/thread/locks.hpp 2009-02-15 08:09:45 EST (Sun, 15 Feb 2009)
@@ -77,6 +77,17 @@
         {
             lock_until(target_time);
         }
+ template<typename TimeDuration>
+ unique_locker(TimeDuration const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ lock_for(target_time);
+ }
+ unique_locker(system_time const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ lock_until(target_time);
+ }
 #ifdef BOOST_HAS_RVALUE_REFS
         unique_locker(unique_locker&& other): base_type(other)
         {}
@@ -182,29 +193,135 @@
         friend class shared_locker<Mutex,scope_tag_type>;
         friend class upgrade_locker<Mutex,scope_tag_type>;
     };
-#if 0
+
+ template<typename Mutex>
+ class try_unique_locker<Mutex,multi_threaded_tag>: public unique_locker<Mutex,multi_threaded_tag> {
+ //typename scope_tag<Mutex>::type == multi_threaded_tag
+ private:
+ typedef Mutex lockable_type;
+ typedef multi_threaded_tag scope_tag_type;
+ typedef unique_locker<Mutex,multi_threaded_tag> base_type;
+ //try_unique_locker(try_unique_locker&);
+ explicit try_unique_locker(try_unique_locker<Mutex, scope_tag_type>&);
+ //try_unique_locker& operator=(try_unique_locker&);
+ try_unique_locker& operator=(try_unique_locker<Mutex, scope_tag_type>& other);
+ public:
+ try_unique_locker(): base_type()
+ {}
+
+ explicit try_unique_locker(Mutex& m_): base_type(m_, boost::defer_lock)
+ { this->try_lock(); }
+ try_unique_locker(Mutex& m_,force_lock_t): base_type(m_)
+ {}
+ try_unique_locker(Mutex& m_,adopt_lock_t): base_type(m_, boost::adopt_lock)
+ {}
+ try_unique_locker(Mutex& m_,defer_lock_t): base_type(m_, boost::defer_lock)
+ {}
+ try_unique_locker(Mutex& m_,try_to_lock_t): base_type(m_, boost::try_to_lock)
+ {}
+ template<typename TimeDuration>
+ try_unique_locker(Mutex& m_,TimeDuration const& target_time): base_type(m_, target_time)
+ {}
+ try_unique_locker(Mutex& m_,system_time const& target_time): base_type(m_, target_time)
+ {}
+ template<typename TimeDuration>
+ try_unique_locker(Mutex& m_,TimeDuration const& target_time, throw_lock_t)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_for(target_time);
+ }
+ try_unique_locker(Mutex& m_,system_time const& target_time, throw_lock_t)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_until(target_time);
+ }
+ template<typename TimeDuration>
+ try_unique_locker(TimeDuration const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_for(target_time);
+ }
+ try_unique_locker(system_time const& target_time, Mutex& m_)
+ : base_type(m_, defer_lock)
+ {
+ this->lock_until(target_time);
+ }
 #ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex, typename ScopeTag>
- void swap(unique_locker<Mutex, ScopeTag>&& lhs, unique_locker<Mutex, ScopeTag>&& rhs)
- {
- lhs.swap(rhs);
- }
+ try_unique_locker(try_unique_locker&& other): base_type(other)
+ {}
+ explicit try_unique_locker(upgrade_locker<Mutex,scope_tag_type>&& other) : base_type(other)
+ {}
+
+ try_unique_locker<Mutex, scope_tag_type>&& move()
+ {
+ return static_cast<try_unique_locker<Mutex, scope_tag_type>&&>(*this);
+ }
+
+
+ try_unique_locker& operator=(try_unique_locker<Mutex, scope_tag_type>&& other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ try_unique_locker& operator=(upgrade_locker<Mutex>&& other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+ void swap(try_unique_locker&& other)
+ {
+ this->base_type.swap(other);
+ }
 #else
- template<typename Mutex, typename ScopeTag>
- void swap(unique_locker<Mutex, ScopeTag>& lhs, unique_locker<Mutex, ScopeTag>& rhs)
- {
- lhs.swap(rhs);
- }
-#endif
+ try_unique_locker(detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> > other)
+ : base_type(detail::thread_move_t<base_type>(other.t))
+ {}
+ try_unique_locker(detail::thread_move_t<upgrade_locker<Mutex,scope_tag_type> > other)
+ : base_type(detail::thread_move_t<upgrade_locker<Mutex,scope_tag_type> >(other.t))
+ {}
 
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename Mutex, typename ScopeTag>
- inline unique_locker<Mutex, ScopeTag>&& move(unique_locker<Mutex, ScopeTag>&& ul)
- {
- return ul;
- }
-#endif
+ operator detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> >()
+ {
+ return move();
+ }
+
+ detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> > move()
+ {
+ return detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> >(*this);
+ }
+
+ try_unique_locker& operator=(detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> > other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ try_unique_locker& operator=(detail::thread_move_t<upgrade_locker<Mutex, scope_tag_type> > other)
+ {
+ try_unique_locker temp(other);
+ swap(temp);
+ return *this;
+ }
+ void swap(try_unique_locker& other)
+ {
+ this->base_type.swap(other);
+ }
+ void swap(detail::thread_move_t<try_unique_locker<Mutex, scope_tag_type> > other)
+ {
+ this->base_type.swap(detail::thread_move_t<base_type>(other.t));
+ }
 #endif
+
+ ~try_unique_locker() {}
+
+ friend class shared_locker<Mutex,scope_tag_type>;
+ friend class upgrade_locker<Mutex,scope_tag_type>;
+ };
+
     template<typename Mutex>
     class shared_locker<Mutex,multi_threaded_tag>: public shared_lock_type<Mutex>::type {
         //typename scope_tag<Mutex>::type == multi_threaded_tag
@@ -239,12 +356,26 @@
             lock_until(target_time);
         }
         template<typename TimeDuration>
+ shared_locker(Mutex& m_,TimeDuration const& target_time,throw_lock_t)
+ : base_type(m_, boost::defer_lock)
+ {
+ lock_for(target_time);
+ }
         shared_locker(Mutex& m_,system_time const& target_time,throw_lock_t)
             : base_type(m_, boost::defer_lock)
         {
+ lock_until(target_time);
+ }
+ template<typename TimeDuration>
+ shared_locker(TimeDuration const& target_time, Mutex& m_)
+ {
             lock_for(target_time);
         }
-
+ shared_locker(system_time const& target_time, Mutex& m_)
+ : base_type(m_, boost::defer_lock)
+ {
+ lock_until(target_time);
+ }
 
         shared_locker(detail::thread_move_t<shared_locker<Mutex, scope_tag_type> > other)
             : base_type(detail::thread_move_t<base_type>(other.t))


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