Ticket #1850: 1850.patch

File 1850.patch, 12.2 KB (added by viboes, 11 years ago)
  • reverse_lock.hpp

     
     1// Distributed under the Boost Software License, Version 1.0. (See
     2// accompanying file LICENSE_1_0.txt or copy at
     3// http://www.boost.org/LICENSE_1_0.txt)
     4// (C) Copyright 2012 Vicente J. Botet Escriba
     5
     6#ifndef BOOST_THREAD_REVERSE_LOCK_HPP
     7#define BOOST_THREAD_REVERSE_LOCK_HPP
     8#include <boost/thread/detail/config.hpp>
     9#include <boost/thread/locks.hpp>
     10
     11namespace boost
     12{
     13
     14    template<typename Lock>
     15    class reverse_lock
     16    {
     17
     18#ifndef BOOST_NO_DELETED_FUNCTIONS
     19    public:
     20        reverse_lock(reverse_lock const&) = delete;
     21        reverse_lock& operator=(reverse_lock const&) = delete;
     22#else // BOOST_NO_DELETED_FUNCTIONS
     23    private:
     24        reverse_lock(reverse_lock&);
     25        reverse_lock& operator=(reverse_lock&);
     26#endif // BOOST_NO_DELETED_FUNCTIONS
     27    public:
     28        typedef typename Lock::mutex_type mutex_type;
     29
     30        explicit reverse_lock(Lock& m_)
     31        : m(m_), mtx(0)
     32        {
     33            if (m.owns_lock())
     34            {
     35              m.unlock();
     36            }
     37            mtx=m.release();
     38        }
     39        ~reverse_lock()
     40        {
     41          if (mtx) {
     42            mtx->lock();
     43            m = Lock(*mtx, adopt_lock);
     44          }
     45        }
     46
     47    private:
     48      Lock& m;
     49      mutex_type* mtx;
     50    };
     51
     52
     53#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
     54    template<typename T>
     55    struct is_mutex_type<reverse_lock<T> >
     56    {
     57        BOOST_STATIC_CONSTANT(bool, value = true);
     58    };
     59
     60#endif
     61
     62
     63}
     64
     65#endif // header
  • ../../libs/thread/doc/overview.qbk

    Property changes on: reverse_lock.hpp
    ___________________________________________________________________
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Id
    Added: svn:eol-style
       + native
    
     
    2020[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2139.html N2139], and
    2121[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2094.html N2094]
    2222
    23 Vicente J. Botet Escriba started in version 2 the adaptation to comply with the accepted Thread C++11 library (Make use of Boost.Chrono and Boost.Move) and the [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] Howard Hinnant proposal except for the upward conversions.   
     23Vicente J. Botet Escriba started in version 2 the adaptation to comply with the accepted Thread C++11 library (Make use of Boost.Chrono and Boost.Move) and the [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] Howard Hinnant proposal except for the upward conversions.  Some minor features have been added also
     24as thread attributes, reverse_lock, shared_lock_guard.
    2425
    25 [/ as some new features as thread attributes, unlock_guard, shared_guard, ]
    26 
    2726In order to use the classes and functions described here, you can
    2827either include the specific headers specified by the descriptions of
    2928each class or function, or include the master thread library header:
  • ../../libs/thread/doc/changes.qbk

     
    1212
    1313New Features:
    1414
    15 [/
    1615* [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard  to compliment lock_guard.
    17 ]
    18 
    1916* [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared.
    2017* [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes.
    2118* [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard.
     
    188185  * [@http://svn.boost.org/trac/boost/ticket/6270 #6270] Add thread constructor from movable callable and movable arguments following C++11.
    189186       
    190187
    191 # Add some complementary locks
    192 
    193   * [@http://svn.boost.org/trac/boost/ticket/1850 #1850]        Request for unlock_guard (and/or unique_unlock) to compliment lock_guard/unique_lock.
    194   * [@http://svn.boost.org/trac/boost/ticket/3567 #3567]        Request for shared_lock_guard.
    195 
    196188# Add the shared locking upward conversions.
    197189
    198190  * [@http://svn.boost.org/trac/boost/ticket/6217 #6217]        Enhance Boost.Thread shared mutex interface following Howard Hinnant proposal.
  • ../../libs/thread/doc/mutex_concepts.qbk

     
    15931593
    15941594[endsect]
    15951595
    1596 [/
    15971596[section:reverse_lock Class template `reverse_lock`]
    15981597
    15991598    #include <boost/thread/reverse_lock.hpp>
     
    16421641
    16431642
    16441643[endsect]
    1645 ]
    16461644
    16471645[endsect]
    16481646
  • ../../libs/thread/test/Jamfile.v2

     
    387387          [ thread-run2 ./sync/mutual_exclusion/locks/shared_lock_guard/types_pass.cpp : shared_lock_guard__types_p ]
    388388    ;
    389389
     390    #explicit reverse_lock ;
     391    test-suite reverse_lock
     392    :
     393          [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp : : reverse_lock__copy_assign_f ]
     394          [ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp : : reverse_lock__copy_ctor_f ]
     395          [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp : reverse_lock__unique_lock_ctor_p ]
     396          [ thread-run2 ./sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp : reverse_lock__types_p ]
     397    ;
     398
    390399}
  • ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp

     
     1// Copyright (C) 2012 Vicente J. Botet Escriba
     2//
     3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6// <boost/thread/locks.hpp>
     7
     8// template <class Mutex> class unlock_guard;
     9
     10// unlock_guard& operator=(unlock_guard const&) = delete;
     11
     12#include <boost/thread/locks.hpp>
     13#include <boost/thread/mutex.hpp>
     14#include <boost/detail/lightweight_test.hpp>
     15
     16
     17int main()
     18{
     19  boost::mutex m0;
     20  boost::mutex m1;
     21  boost::unique_lock<boost::mutex> lk0(m0);
     22  boost::unique_lock<boost::mutex> lk1(m1);
     23  {
     24    boost::unlock_guard<boost::unique_lock<boost::mutex> > lg0(lk0);
     25    boost::unlock_guard<boost::unique_lock<boost::mutex> > lg1(lk1);
     26    lk1 = lk0;
     27  }
     28
     29}
     30
  • ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp

    Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_assign_fail.cpp
    ___________________________________________________________________
    Added: svn:executable
       + *
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Id
    Added: svn:eol-style
       + native
    
     
     1// Copyright (C) 2012 Vicente J. Botet Escriba
     2//
     3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6// <boost/thread/mutex.hpp>
     7
     8// <mutex>
     9
     10// template <class Mutex>
     11// class unlock_guard
     12// {
     13// public:
     14//     typedef Mutex mutex_type;
     15//     ...
     16// };
     17
     18
     19#include <boost/thread/mutex.hpp>
     20#include <boost/thread/reverse_lock.hpp>
     21#include <boost/thread/locks.hpp>
     22#include <boost/thread/mutex.hpp>
     23#include <boost/static_assert.hpp>
     24#include <boost/detail/lightweight_test.hpp>
     25
     26int main()
     27{
     28  BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::reverse_lock<boost::unique_lock<boost::mutex> >::mutex_type,
     29      boost::mutex>::value), "");
     30
     31  return boost::report_errors();
     32}
     33
  • ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp

    Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/types_pass.cpp
    ___________________________________________________________________
    Added: svn:executable
       + *
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Id
    Added: svn:eol-style
       + native
    
     
     1// Copyright (C) 2012 Vicente J. Botet Escriba
     2//
     3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6// <boost/thread/locks.hpp>
     7
     8// template <class Mutex> class unlock_guard;
     9
     10// unlock_guard(unlock_guard const&) = delete;
     11
     12#include <boost/thread/reverse_lock.hpp>
     13#include <boost/thread/locks.hpp>
     14#include <boost/thread/mutex.hpp>
     15#include <boost/thread/thread.hpp>
     16#include <boost/detail/lightweight_test.hpp>
     17
     18
     19int main()
     20{
     21  {
     22    boost::mutex m;
     23    boost::unique_lock<boost::mutex> lk(m);
     24    BOOST_TEST(lk.owns_lock());
     25    BOOST_TEST(lk.mutex()==&m);
     26
     27    {
     28      boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk);
     29      BOOST_TEST(!lk.owns_lock());
     30      BOOST_TEST(lk.mutex()==0);
     31    }
     32    BOOST_TEST(lk.owns_lock());
     33    BOOST_TEST(lk.mutex()==&m);
     34  }
     35
     36  {
     37    boost::mutex m;
     38    boost::unique_lock<boost::mutex> lk(m, boost::defer_lock);
     39    BOOST_TEST(! lk.owns_lock());
     40    BOOST_TEST(lk.mutex()==&m);
     41    {
     42      boost::reverse_lock<boost::unique_lock<boost::mutex> > lg(lk);
     43      BOOST_TEST(!lk.owns_lock());
     44      BOOST_TEST(lk.mutex()==0);
     45    }
     46    BOOST_TEST(lk.owns_lock());
     47    BOOST_TEST(lk.mutex()==&m);
     48  }
     49
     50
     51  return boost::report_errors();
     52}
  • ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/copy_ctor_fail.cpp

    Property changes on: ../../libs/thread/test/sync/mutual_exclusion/locks/reverse_lock/unique_lock_ctor_pass.cpp
    ___________________________________________________________________
    Added: svn:executable
       + *
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Id
    Added: svn:eol-style
       + native
    
     
     1// Copyright (C) 2012 Vicente J. Botet Escriba
     2//
     3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6// <boost/thread/locks.hpp>
     7
     8// template <class Mutex> class unlock_guard;
     9
     10// unlock_guard(unlock_guard const&) = delete;
     11
     12
     13#include <boost/thread/locks.hpp>
     14#include <boost/thread/mutex.hpp>
     15#include <boost/detail/lightweight_test.hpp>
     16
     17boost::mutex m0;
     18boost::mutex m1;
     19
     20int main()
     21{
     22  boost::mutex m0;
     23  boost::mutex m1;
     24  boost::unique_lock<boost::mutex> lk0(m0);
     25  boost::unique_lock<boost::mutex> lk1(m1);
     26  {
     27    boost::unlock_guard<boost::unique_lock<boost::mutex> > lg0(lk0);
     28    boost::unlock_guard<boost::unique_lock<boost::mutex> > lg1(lg0);
     29  }
     30}
     31