Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81101 - trunk/libs/thread/example
From: vicente.botet_at_[hidden]
Date: 2012-10-29 15:05:52


Author: viboes
Date: 2012-10-29 15:05:51 EDT (Mon, 29 Oct 2012)
New Revision: 81101
URL: http://svn.boost.org/trac/boost/changeset/81101

Log:
Thread: change strict_lock is_locking by own_lock and update lockable concepts
Text files modified:
   trunk/libs/thread/example/ba_externallly_locked.cpp | 79 ++++++++++++++++++++-------------------
   trunk/libs/thread/example/strict_lock.cpp | 2
   trunk/libs/thread/example/thread_guard.cpp | 4 ++
   3 files changed, 45 insertions(+), 40 deletions(-)

Modified: trunk/libs/thread/example/ba_externallly_locked.cpp
==============================================================================
--- trunk/libs/thread/example/ba_externallly_locked.cpp (original)
+++ trunk/libs/thread/example/ba_externallly_locked.cpp 2012-10-29 15:05:51 EDT (Mon, 29 Oct 2012)
@@ -6,6 +6,7 @@
 #define BOOST_THREAD_VERSION 4
 
 #include <boost/thread/mutex.hpp>
+#include <boost/thread/lockable_adapter.hpp>
 #include <boost/thread/externally_locked.hpp>
 #include <boost/thread/strict_lock.hpp>
 #include <boost/thread/lock_types.hpp>
@@ -32,12 +33,12 @@
 };
 
 //[AccountManager
-class AccountManager
+class AccountManager: public basic_lockable_adapter<mutex>
 {
- mutex mtx_;
 public:
+ typedef basic_lockable_adapter<mutex> lockable_base_type;
   AccountManager() :
- checkingAcct_(mtx_), savingsAcct_(mtx_)
+ lockable_base_type(), checkingAcct_(*this), savingsAcct_(*this)
   {
   }
   inline void Checking2Savings(int amount);
@@ -48,63 +49,63 @@
   {
     return true;
   } /*->*/
- externally_locked<BankAccount, mutex > checkingAcct_;
- externally_locked<BankAccount, mutex > savingsAcct_;
+ externally_locked<BankAccount, AccountManager > checkingAcct_;
+ externally_locked<BankAccount, AccountManager > savingsAcct_;
 };
 //]
 
 //[Checking2Savings
 void AccountManager::Checking2Savings(int amount)
 {
- strict_lock<mutex> guard(mtx_);
+ strict_lock<AccountManager> guard(*this);
   checkingAcct_.get(guard).Withdraw(amount);
   savingsAcct_.get(guard).Deposit(amount);
 }
 //]
 
-#if MUST_NOT_COMPILE
-//[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE
+//#if DO_NOT_COMPILE
+////[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE
+//void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
+// unique_lock<AccountManager> guard(*this);
+// if (some_condition()) {
+// guard.lock();
+// }
+// checkingAcct_.get(guard).Withdraw(amount);
+// savingsAcct_.get(guard).Deposit(amount);
+// guard1.unlock();
+//}
+////]
+//#elif DO_NOT_COMPILE_2
+////[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE2
+//void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
+// unique_lock<AccountManager> guard1(*this);
+// if (some_condition()) {
+// guard1.lock();
+// }
+// {
+// strict_lock<AccountManager> guard(guard1);
+// checkingAcct_.get(guard).Withdraw(amount);
+// savingsAcct_.get(guard).Deposit(amount);
+// }
+// guard1.unlock();
+//}
+////]
+//#else
+////[AMoreComplicatedChecking2Savings
 void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
- unique_lock<mutex> guard(mtx_);
- if (some_condition()) {
- guard.lock();
- }
- checkingAcct_.get(guard).Withdraw(amount);
- savingsAcct_.get(guard).Deposit(amount);
- guard1.unlock();
-}
-//]
-#elif MUST_NOT_COMPILE_2
-//[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE2
-void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
- unique_lock<mutex> guard1(mtx_);
+ unique_lock<AccountManager> guard1(*this);
     if (some_condition()) {
         guard1.lock();
     }
     {
- strict_lock<mutex> guard(guard1);
+ nested_strict_lock<unique_lock<AccountManager> > guard(guard1);
         checkingAcct_.get(guard).Withdraw(amount);
         savingsAcct_.get(guard).Deposit(amount);
     }
     guard1.unlock();
 }
-]
-#else
-//[AMoreComplicatedChecking2Savings
-void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
- unique_lock<mutex> guard1(mtx_);
- if (some_condition()) {
- guard1.lock();
- }
- {
- nested_strict_lock<unique_lock<mutex> > guard(guard1);
- checkingAcct_.get(guard).Withdraw(amount);
- savingsAcct_.get(guard).Deposit(amount);
- }
- guard1.unlock();
-}
-//]
-#endif
+////]
+//#endif
 
 int main()
 {

Modified: trunk/libs/thread/example/strict_lock.cpp
==============================================================================
--- trunk/libs/thread/example/strict_lock.cpp (original)
+++ trunk/libs/thread/example/strict_lock.cpp 2012-10-29 15:05:51 EDT (Mon, 29 Oct 2012)
@@ -5,8 +5,8 @@
 
 #define BOOST_THREAD_VERSION 4
 
-#include <boost/thread/lock_traits.hpp>
 #include <boost/thread/mutex.hpp>
+#include <boost/thread/lock_traits.hpp>
 #include <boost/thread/shared_mutex.hpp>
 #include <boost/thread/strict_lock.hpp>
 #include <boost/thread/lock_types.hpp>

Modified: trunk/libs/thread/example/thread_guard.cpp
==============================================================================
--- trunk/libs/thread/example/thread_guard.cpp (original)
+++ trunk/libs/thread/example/thread_guard.cpp 2012-10-29 15:05:51 EDT (Mon, 29 Oct 2012)
@@ -28,6 +28,10 @@
             do_something(i);
         }
     }
+
+private:
+ func& operator=(func const&);
+
 };
 
 void do_something_in_current_thread()


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