|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57492 - in sandbox/stm/branches/vbe: boost/stm boost/stm/detail boost/stm/synch libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-11-08 13:06:42
Author: viboes
Date: 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
New Revision: 57492
URL: http://svn.boost.org/trac/boost/changeset/57492
Log:
TBoost.STM vbe:
* Replacing latm::mutex_type by pthread_mutes_t or boost::mutex
* Adding two parameters to stm::lock, try_lock and unlock: the first is the static mutex and is a template parameter the second the dynamic one
* adapting auto_lock and exclusive_ref_lock_adapter to the new interface
Text files modified:
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp | 53 +++++++++++++------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp | 55 ++++++++++++++------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp | 57 ++++++++++++++-------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 53 +++++++++++++------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp | 47 ++++++++++++----------
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp | 53 +++++++++++++------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp | 45 +++++++++++----------
sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp | 60 ++++++++++++++--------------
sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp | 16 +++---
sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 81 ++++++++++++++++++++++++++-------------
sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx.cpp | 18 +++++--
sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx2.cpp | 20 ++++++---
sandbox/stm/branches/vbe/libs/stm/test/isolatedIntLockInTx.cpp | 14 ++++-
sandbox/stm/branches/vbe/libs/stm/test/litExample.cpp | 32 +++++++++------
sandbox/stm/branches/vbe/libs/stm/test/lotExample.cpp | 38 ++++++++++-------
sandbox/stm/branches/vbe/libs/stm/test/main.h | 2
sandbox/stm/branches/vbe/libs/stm/test/nestedTxs.cpp | 33 +++++++++------
sandbox/stm/branches/vbe/libs/stm/test/stm.cpp | 6 +-
sandbox/stm/branches/vbe/libs/stm/test/testHT_latm.h | 2
sandbox/stm/branches/vbe/libs/stm/test/testHashMapWithLocks.h | 2
sandbox/stm/branches/vbe/libs/stm/test/testLL_latm.h | 16 ++++--
sandbox/stm/branches/vbe/libs/stm/test/testLinkedListWithLocks.h | 15 ++++--
sandbox/stm/branches/vbe/libs/stm/test/txLinearLock.cpp | 20 +++++----
sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.cpp | 30 +++++++------
sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h | 13 ++++-
25 files changed, 440 insertions(+), 341 deletions(-)
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -92,24 +92,25 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_full_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_full_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
t->make_isolated();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
t->commit_deferred_update_tx();
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
if (hadLock) return;
- else synchro::lock(*mutex);
+ else synchro::lock(m);
return;
}
@@ -117,13 +118,13 @@
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
- if (def_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ if (def_do_core_full_pthread_lock_mutex(&mutex, waitTime, aborted)) {
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -144,27 +145,28 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::def_full_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::def_full_try_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
t->make_isolated();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
t->commit_deferred_update_tx();
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
if (hadLock) return true;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(m);
}
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
@@ -172,12 +174,12 @@
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!def_do_core_full_pthread_lock_mutex(mutex, 0, 0))
+ if (!def_do_core_full_pthread_lock_mutex(&mutex, 0, 0))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
lk.release();
@@ -187,7 +189,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_full_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_full_unlock(M& m, latm::mutex_type& mutex)
{
bool hasLock = true;
{
@@ -195,7 +198,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -203,18 +206,18 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
- latm::instance().latmLockedLocks_.erase(mutex);
+ latm::instance().latmLockedLocks_.erase(&mutex);
if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
}
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -97,24 +97,25 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_tm_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ latm::instance().must_be_in_tm_conflicting_lock_set(&mutex);
t->make_isolated();
t->commit_deferred_update_tx();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
if (hadLock) return;
- else synchro::lock(*mutex);
+ else synchro::lock(m);
return;
}
@@ -123,15 +124,15 @@
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(*latm_lock());
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
if (def_do_core_tm_conflicting_lock_pthread_lock_mutex
- (mutex, waitTime, aborted)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ (&mutex, waitTime, aborted)) {
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -151,27 +152,28 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::def_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::def_tm_try_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ latm::instance().must_be_in_tm_conflicting_lock_set(&mutex);
t->make_isolated();
t->commit_deferred_update_tx();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
if (hadLock) return true;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(m);
}
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
@@ -179,12 +181,12 @@
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!def_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
+ if (!def_do_core_tm_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
lk.release();
@@ -194,7 +196,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_tm_unlock(M& m, latm::mutex_type& mutex)
{
bool hasLock = true;
{
@@ -202,7 +205,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -210,8 +213,8 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
//--------------------------------------------------------------------------
@@ -219,17 +222,17 @@
// it from the latmLocks and check to see if we allow transactions to
// continue.
//--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ if (latm::instance().tmConflictingLocks_.find(&mutex) != latm::instance().tmConflictingLocks_.end())
{
- latm::instance().latmLockedLocks_.erase(mutex);
+ latm::instance().latmLockedLocks_.erase(&mutex);
if (latm::instance().latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
}
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
}
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -121,7 +121,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_tx_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_tx_lock(M& m, latm::mutex_type& mutex)
{
int waitTime = 0, aborted = 0;
@@ -147,35 +148,35 @@
//--------------------------------------------------------------------------
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- t->must_be_in_conflicting_lock_set(mutex);
+ t->must_be_in_conflicting_lock_set(&mutex);
t->make_irrevocable();
- if (!t->is_currently_locked_lock(mutex))
+ if (!t->is_currently_locked_lock(&mutex))
{
- synchro::lock(*mutex);
+ synchro::lock(m);
}
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
t->commit_deferred_update_tx();
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, true);
+ def_do_core_tx_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0, true);
return;
}
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
- if (def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, waitTime, aborted, false))
+ if (def_do_core_tx_conflicting_lock_pthread_lock_mutex(&mutex, waitTime, aborted, false))
{
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -197,7 +198,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::def_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::def_tx_try_lock(M& m, latm::mutex_type& mutex)
{
//--------------------------------------------------------------------------
@@ -205,7 +207,7 @@
bool txIsIrrevocable = false;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
@@ -213,21 +215,21 @@
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
txIsIrrevocable = true;
- t->must_be_in_conflicting_lock_set(mutex);
+ t->must_be_in_conflicting_lock_set(&mutex);
t->make_irrevocable();
- t->add_to_obtained_locks(mutex);
+ t->add_to_obtained_locks(&mutex);
t->commit_deferred_update_tx();
}
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
+ if (!def_do_core_tx_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0, txIsIrrevocable))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
@@ -238,7 +240,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::def_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::def_tx_unlock(M& m, latm::mutex_type& mutex)
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
synchro::lock_guard<Mutex> lk_g(*general_lock());
@@ -247,7 +250,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(true))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -255,8 +258,8 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
//--------------------------------------------------------------------------
@@ -264,25 +267,25 @@
// it from the latmLocks and any txs on the full thread list that are
// blocked because of this lock being locked should be unblocked
//--------------------------------------------------------------------------
- if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
+ if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(&mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
{
#if LOGGING_BLOCKS
- logFile_ << "----------------------\nbefore unlocked mutex: " << mutex << endl << endl;
+ logFile_ << "----------------------\nbefore unlocked mutex: " << &mutex << endl << endl;
logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
#endif
- latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
- unblock_conflicting_threads(mutex);
+ latm::instance().latmLockedLocksAndThreadIdsMap_.erase(&mutex);
+ unblock_conflicting_threads(&mutex);
#if LOGGING_BLOCKS
- logFile_ << "----------------------\nafter unlocked mutex: " << mutex << endl << endl;
+ logFile_ << "----------------------\nafter unlocked mutex: " << &mutex << endl << endl;
logFile_ << outputBlockedThreadsAndLockedLocks() << endl;
#endif
}
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
unblock_threads_if_locks_are_empty();
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
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-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -116,20 +116,21 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::dir_full_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_full_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
t->make_isolated();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
- wait_until_all_locks_are_released_and_set(mutex);
+ wait_until_all_locks_are_released_and_set(&mutex);
if (hadLock) return;
- else synchro::lock(*mutex);
+ else synchro::lock(m);
return;
}
@@ -137,14 +138,14 @@
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
- if (dir_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ if (dir_do_core_full_pthread_lock_mutex(&mutex, waitTime, aborted)) {
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -164,35 +165,36 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::dir_full_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::dir_full_try_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
t->make_isolated();
- bool hadLock = t->is_currently_locked_lock(mutex);
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ bool hadLock = t->is_currently_locked_lock(&mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
- wait_until_all_locks_are_released_and_set(mutex);
+ wait_until_all_locks_are_released_and_set(&mutex);
if (hadLock) return true;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(m);
}
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!dir_do_core_full_pthread_lock_mutex(mutex, 0, 0))
+ if (!dir_do_core_full_pthread_lock_mutex(&mutex, 0, 0))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
lk.release();
@@ -202,7 +204,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::dir_full_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_full_unlock(M& m, latm::mutex_type& mutex)
{
bool hasLock = true;
{
@@ -210,7 +213,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -218,11 +221,11 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
- latm::instance().latmLockedLocks_.erase(mutex);
+ latm::instance().latmLockedLocks_.erase(&mutex);
if (latm::instance().latmLockedLocks_.empty())
{
@@ -230,9 +233,9 @@
thread_conflicting_mutexes_set_all(false);
}
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
}
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -115,17 +115,18 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::dir_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_tm_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ latm::instance().must_be_in_tm_conflicting_lock_set(&mutex);
t->make_isolated();
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
- synchro::lock(*mutex); // BUG: should't be before the map setting and making the tx isolated?
+ synchro::lock(m); // BUG: should't be before the map setting and making the tx isolated?
return;
}
@@ -134,15 +135,15 @@
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
if (dir_do_core_tm_conflicting_lock_pthread_lock_mutex
- (mutex, waitTime, aborted)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ (&mutex, waitTime, aborted)) {
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -163,32 +164,33 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::dir_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::dir_tm_try_lock(M& m, latm::mutex_type& mutex)
{
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- latm::instance().must_be_in_tm_conflicting_lock_set(mutex);
+ latm::instance().must_be_in_tm_conflicting_lock_set(&mutex);
t->make_isolated();
{
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
}
- return synchro::try_lock(*mutex); // BUG: : should't be before the map setting and making the tx isolated?
+ return synchro::try_lock(m); // BUG: : should't be before the map setting and making the tx isolated?
}
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!dir_do_core_tm_conflicting_lock_pthread_lock_mutex(mutex, 0, 0))
+ if (!dir_do_core_tm_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
lk.release();
@@ -198,7 +200,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::dir_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_tm_unlock(M& m, latm::mutex_type& mutex)
{
bool hasLock = true;
{
@@ -206,7 +209,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -214,8 +217,8 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
//--------------------------------------------------------------------------
@@ -223,9 +226,9 @@
// it from the latmLocks and check to see if we allow transactions to
// continue.
//--------------------------------------------------------------------------
- if (latm::instance().tmConflictingLocks_.find(mutex) != latm::instance().tmConflictingLocks_.end())
+ if (latm::instance().tmConflictingLocks_.find(&mutex) != latm::instance().tmConflictingLocks_.end())
{
- latm::instance().latmLockedLocks_.erase(mutex);
+ latm::instance().latmLockedLocks_.erase(&mutex);
if (latm::instance().latmLockedLocks_.empty())
{
@@ -234,10 +237,10 @@
}
}
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
}
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
Modified: sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -151,7 +151,8 @@
// Protected by: mutex is locked
// Postcondition: mutex is locked
//----------------------------------------------------------------------------
-inline void transaction::dir_tx_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_tx_lock(M& m, latm::mutex_type& mutex)
{
int waitTime = 0, aborted = 0;
@@ -177,19 +178,19 @@
//--------------------------------------------------------------------------
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
- t->must_be_in_conflicting_lock_set(mutex);
+ t->must_be_in_conflicting_lock_set(&mutex);
t->make_irrevocable();
- if (!t->is_currently_locked_lock(mutex))
+ if (!t->is_currently_locked_lock(&mutex))
{
- synchro::lock(*mutex);
+ synchro::lock(m);
}
- t->add_to_currently_locked_locks(mutex);
- t->add_to_obtained_locks(mutex);
+ t->add_to_currently_locked_locks(&mutex);
+ t->add_to_obtained_locks(&mutex);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
- def_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, true);
+ def_do_core_tx_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0, true);
return;
}
@@ -197,15 +198,15 @@
for (;;)
{
{
- synchro::unique_lock<latm::mutex_type> lk(*mutex);
+ synchro::unique_lock<M> lk(m);
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
if (dir_do_core_tx_conflicting_lock_pthread_lock_mutex
- (mutex, waitTime, aborted, false)) {
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ (&mutex, waitTime, aborted, false)) {
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return;
}
@@ -227,34 +228,35 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline bool transaction::dir_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline bool transaction::dir_tx_try_lock(M& m, latm::mutex_type& mutex)
{
//--------------------------------------------------------------------------
throw "might not be possible to implement trylock for this";
bool txIsIrrevocable = false;
- synchro::unique_lock<latm::mutex_type> lk(*mutex, synchro::try_to_lock);
+ synchro::unique_lock<M> lk(m, synchro::try_to_lock);
if (!lk) return false;
synchro::lock_guard<Mutex> lk_l(latm::instance().latmMutex_);
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
txIsIrrevocable = true;
- t->must_be_in_conflicting_lock_set(mutex);
+ t->must_be_in_conflicting_lock_set(&mutex);
t->make_irrevocable();
- t->add_to_obtained_locks(mutex);
+ t->add_to_obtained_locks(&mutex);
}
//-----------------------------------------------------------------------
// if !core done, since trylock, we cannot stall & retry - just exit
//-----------------------------------------------------------------------
- if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable))
+ if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(&mutex, 0, 0, txIsIrrevocable))
{
return false;
}
- latm::instance().latmLockedLocksOfThreadMap_[mutex] = this_thread::get_id();
+ latm::instance().latmLockedLocksOfThreadMap_[&mutex] = this_thread::get_id();
lk.release();
return true;
}
@@ -262,7 +264,8 @@
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
-inline void transaction::dir_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex)
+template <typename M>
+inline void transaction::dir_tx_unlock(M& m, latm::mutex_type& mutex)
{
synchro::lock_guard<Mutex> lk_l(*latm_lock());
synchro::lock_guard<Mutex> lk_g(*general_lock());
@@ -271,7 +274,7 @@
if (transaction* t = get_inflight_tx_of_same_thread(true))
{
- if (!t->is_on_obtained_locks_list(mutex))
+ if (!t->is_on_obtained_locks_list(&mutex))
{
// this is illegal, it means the transaction is unlocking a lock
// it did not obtain (e.g., early release) while the transaction
@@ -279,8 +282,8 @@
throw "lock released for transaction that did not obtain it";
}
- if (!t->is_currently_locked_lock(mutex)) hasLock = false;
- t->remove_from_currently_locked_locks(mutex);
+ if (!t->is_currently_locked_lock(&mutex)) hasLock = false;
+ t->remove_from_currently_locked_locks(&mutex);
}
//--------------------------------------------------------------------------
@@ -288,16 +291,16 @@
// it from the latmLocks and any txs on the full thread list that are
// blocked because of this lock being locked should be unblocked
//--------------------------------------------------------------------------
- if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
+ if (latm::instance().latmLockedLocksAndThreadIdsMap_.find(&mutex) != latm::instance().latmLockedLocksAndThreadIdsMap_.end())
{
- latm::instance().latmLockedLocksAndThreadIdsMap_.erase(mutex);
- unblock_conflicting_threads(mutex);
+ latm::instance().latmLockedLocksAndThreadIdsMap_.erase(&mutex);
+ unblock_conflicting_threads(&mutex);
}
- latm::instance().latmLockedLocksOfThreadMap_.erase(mutex);
+ latm::instance().latmLockedLocksOfThreadMap_.erase(&mutex);
unblock_threads_if_locks_are_empty();
- if (hasLock) synchro::unlock(*mutex);
+ if (hasLock) synchro::unlock(m);
return;
}
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-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -318,21 +318,22 @@
// the client chose
//
//----------------------------------------------------------------------------
-inline void boost::stm::transaction::pthread_lock(latm::mutex_type* mutex)
+template <typename M>
+inline void boost::stm::transaction::lock(M& m, latm::mutex_type& mutex)
{
//using namespace boost::stm;
switch (latm::instance().protection())
{
case eFullLatmProtection:
- if (direct_updating()) {dir_full_pthread_lock_mutex(mutex); return;}
- else {def_full_pthread_lock_mutex(mutex);return;}
+ if (direct_updating()) {dir_full_lock(m, mutex); return;}
+ else {def_full_lock(m, mutex);return;}
case eTmConflictingLockLatmProtection:
- if (direct_updating()) {dir_tm_conflicting_lock_pthread_lock_mutex(mutex);return;}
- else {def_tm_conflicting_lock_pthread_lock_mutex(mutex);return;}
+ if (direct_updating()) {dir_tm_lock(m, mutex);return;}
+ else {def_tm_lock(m, mutex);return;}
case eTxConflictingLockLatmProtection:
- if (direct_updating()) {dir_tx_conflicting_lock_pthread_lock_mutex(mutex);return;}
- else {def_tx_conflicting_lock_pthread_lock_mutex(mutex);return;}
+ if (direct_updating()) {dir_tx_lock(m, mutex);return;}
+ else {def_tx_lock(m, mutex);return;}
default:
throw "invalid LATM type";
}
@@ -341,21 +342,22 @@
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
-inline bool boost::stm::transaction::pthread_trylock(latm::mutex_type* mutex)
+template <typename M>
+inline bool boost::stm::transaction::try_lock(M& m, latm::mutex_type& mutex)
{
//using namespace boost::stm;
switch (latm::instance().protection())
{
case eFullLatmProtection:
- if (direct_updating()) return dir_full_pthread_trylock_mutex(mutex);
- else return def_full_pthread_trylock_mutex(mutex);
+ if (direct_updating()) return dir_fulltry_lock(m, mutex);
+ else return def_full_try_lock(m, mutex);
case eTmConflictingLockLatmProtection:
- if (direct_updating()) return dir_tm_conflicting_lock_pthread_trylock_mutex(mutex);
- else return def_tm_conflicting_lock_pthread_trylock_mutex(mutex);
+ if (direct_updating()) return dir_tm_try_lock(m, mutex);
+ else return def_tm_try_lock(m, mutex);
case eTxConflictingLockLatmProtection:
- if (direct_updating()) return dir_tx_conflicting_lock_pthread_trylock_mutex(mutex);
- else return def_tx_conflicting_lock_pthread_trylock_mutex(mutex);
+ if (direct_updating()) return dir_tx_try_lock(m, mutex);
+ else return def_tx_try_lock(m, mutex);
default:
throw "invalid LATM type";
}
@@ -363,21 +365,22 @@
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
-inline void boost::stm::transaction::pthread_unlock(latm::mutex_type* mutex)
+template <typename M>
+inline void boost::stm::transaction::unlock(M& m, latm::mutex_type& mutex)
{
//using namespace boost::stm;
switch (latm::instance().protection())
{
case eFullLatmProtection:
- if (direct_updating()) {dir_full_pthread_unlock_mutex(mutex);return;}
- else {def_full_pthread_unlock_mutex(mutex);return;}
+ if (direct_updating()) {dir_full_unlock(m, mutex);return;}
+ else {def_full_unlock(m, mutex);return;}
case eTmConflictingLockLatmProtection:
- if (direct_updating()) {dir_tm_conflicting_lock_pthread_unlock_mutex(mutex);return;}
- else {def_tm_conflicting_lock_pthread_unlock_mutex(mutex); return;}
+ if (direct_updating()) {dir_tm_unlock(m, mutex);return;}
+ else {def_tm_unlock(m, mutex); return;}
case eTxConflictingLockLatmProtection:
- if (direct_updating()) {dir_tx_conflicting_lock_pthread_unlock_mutex(mutex);return;}
- else {def_tx_conflicting_lock_pthread_unlock_mutex(mutex);return;}
+ if (direct_updating()) {dir_tx_unlock(m, mutex);return;}
+ else {def_tx_unlock(m, mutex);return;}
default:
throw "invalid LATM type";
}
Modified: sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/synch/auto_lock.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,11 +36,11 @@
//---------------------------------------------------------------------------
#ifdef PERFORMING_LATM
-#define BOOST_STM_LOCK(a) boost::stm::lock(a)
-#define BOOST_STM_UNLOCK(a) boost::stm::unlock(a)
+#define BOOST_STM_LOCK(a, b) boost::stm::lock(a,b)
+#define BOOST_STM_UNLOCK(a, b) boost::stm::unlock(a, b)
#else
-#define BOOST_STM_LOCK(a) boost::synchro::lock(a)
-#define BOOST_STM_UNLOCK(a) boost::synchro::unlock(a)
+#define BOOST_STM_LOCK(a, b) boost::synchro::lock(a)
+#define BOOST_STM_UNLOCK(a, b) boost::synchro::unlock(a)
#endif
//---------------------------------------------------------------------------
@@ -72,25 +72,25 @@
typedef std::multimap<thread_id_t const, latm::mutex_type*> ThreadedLockContainer;
typedef ThreadedLockContainer::iterator ThreadedLockIter;
- auto_lock(latm::mutex_type &mutex) : hasLock_(false), lock_(0)
+ auto_lock(latm::mutex_type &mutex) : hasLock_(false), lock_(mutex)
{
- do_auto_lock(&mutex);
+ do_auto_lock();
}
- auto_lock(latm::mutex_type *mutex) : hasLock_(false), lock_(0)
+ auto_lock(latm::mutex_type *mutex) : hasLock_(false), lock_(*mutex)
{
- do_auto_lock(mutex);
+ do_auto_lock();
}
- auto_lock(milliseconds_t timeOut, latm::mutex_type &mutex) : hasLock_(false), lock_(0)
+ auto_lock(milliseconds_t timeOut, latm::mutex_type &mutex) : hasLock_(false), lock_(mutex)
{
- do_timed_auto_lock(timeOut, &mutex);
+ do_timed_auto_lock(timeOut);
}
- auto_lock(milliseconds_t timeOut, latm::mutex_type *mutex) : hasLock_(false), lock_(0)
+ auto_lock(milliseconds_t timeOut, latm::mutex_type *mutex) : hasLock_(false), lock_(*mutex)
{
- do_timed_auto_lock(timeOut, mutex);
+ do_timed_auto_lock(timeOut);
}
~auto_lock() { do_auto_unlock(); }
@@ -107,18 +107,18 @@
private:
- void do_timed_auto_lock(milliseconds_t timeOut, latm::mutex_type *mutex)
+ void do_timed_auto_lock(milliseconds_t timeOut)
{
- lock_ = mutex;
+ //lock_ = mutex;
- if (thread_has_lock(mutex)) return;
+ if (thread_has_lock(lock_)) return;
for (milliseconds_t i = 0; i < timeOut; ++i)
{
- if (synchro::try_lock(*lock_))
+ if (synchro::try_lock(lock_))
{
hasLock_ = true;
- insert_into_threaded_lock_map(mutex);
+ insert_into_threaded_lock_map(lock_);
return;
}
@@ -128,21 +128,21 @@
throw timer_lock_exception( "lock timed out" );
}
- void insert_into_threaded_lock_map(latm::mutex_type* mutex)
+ void insert_into_threaded_lock_map(latm::mutex_type& mutex)
{
synchro::lock_guard<Mutex> lock_i(*global_lock());
- threaded_locks().insert(ThreadedLockPair(this_thread::get_id(), mutex));
+ threaded_locks().insert(ThreadedLockPair(this_thread::get_id(), &mutex));
}
- void do_auto_lock(latm::mutex_type *mutex)
+ void do_auto_lock()
{
- lock_ = mutex;
- if (thread_has_lock(mutex)) return;
+ //lock_ = mutex;
+ if (thread_has_lock(lock_)) return;
- BOOST_STM_LOCK(*mutex);
+ BOOST_STM_LOCK(lock_, lock_);
hasLock_ = true;
- insert_into_threaded_lock_map(mutex);
+ insert_into_threaded_lock_map(lock_);
}
void do_auto_unlock()
@@ -150,19 +150,19 @@
if (hasLock_)
{
hasLock_ = false;
- BOOST_STM_UNLOCK(*lock_);
+ BOOST_STM_UNLOCK(lock_, lock_);
remove_thread_has_lock(lock_);
}
}
- bool thread_has_lock(latm::mutex_type *rhs)
+ bool thread_has_lock(latm::mutex_type &rhs)
{
synchro::lock_guard<Mutex> lock_g(*global_lock());
for (ThreadedLockIter i = threaded_locks().begin();
i != threaded_locks().end(); ++i)
{
- if (i->first == this_thread::get_id() && i->second == rhs)
+ if (i->first == this_thread::get_id() && i->second == &rhs)
{
return true;
}
@@ -171,14 +171,14 @@
return false;
}
- void remove_thread_has_lock(latm::mutex_type *rhs)
+ void remove_thread_has_lock(latm::mutex_type &rhs)
{
synchro::lock_guard<Mutex> lock_g(*global_lock());
for (ThreadedLockIter i = threaded_locks().begin();
i != threaded_locks().end(); ++i)
{
- if (i->first == this_thread::get_id() && i->second == rhs)
+ if (i->first == this_thread::get_id() && i->second == &rhs)
{
threaded_locks().erase(i);
break;
@@ -206,7 +206,7 @@
//auto_lock& operator=(auto_lock const &);
bool hasLock_;
- latm::mutex_type *lock_;
+ latm::mutex_type &lock_;
};
//---------------------------------------------------------------------------
Modified: sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/synch/mutex.hpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -61,7 +61,7 @@
protected:
lockable_type* the_lock() { return &st_lock_; }
mutable lockable_type& st_lock_;
- //mutable Poly<lockable_type, Base> dyn_lock_;
+ mutable Poly<lockable_type, Base> dyn_lock_;
};
#else
template <typename Lockable >
@@ -73,9 +73,9 @@
exclusive_ref_lock_adapter(lockable_type& lock): st_lock_(lock) {}
~exclusive_ref_lock_adapter() {}
- void lock() {stm::lock(st_lock_);}
- void unlock() {stm::unlock(st_lock_);}
- bool try_lock() { return stm::try_lock(st_lock_);}
+ void lock() {stm::lock(st_lock_, st_lock_);}
+ void unlock() {stm::unlock(st_lock_, st_lock_);}
+ bool try_lock() { return stm::try_lock(st_lock_, st_lock_);}
protected:
lockable_type* the_lock() { return &st_lock_; }
@@ -83,14 +83,14 @@
};
#endif
+#if 0
template <typename Lockable>
-void lock(exclusive_lock_adapter<Lockable>& lock) {transaction::pthread_lock(&lock);}
+void lock(exclusive_lock_adapter<Lockable>& lock) {transaction::lock(lock, lock);}
template <typename Lockable>
-bool try_lock(exclusive_lock_adapter<Lockable>& lock) {return transaction::pthread_trylock(&lock);}
+bool try_lock(exclusive_lock_adapter<Lockable>& lock) {return transaction::try_lock(lock, lock);}
template <typename Lockable>
-void unlock(exclusive_lock_adapter<Lockable>& lock) {transaction::pthread_unlock(&lock);}
+void unlock(exclusive_lock_adapter<Lockable>& lock) {transaction::unlock(lock, lock);}
-#if 0
template <typename TimedLock>
class timed_lock_adapter
: public exclusive_lock_adapter<TimedLock>
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-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -311,9 +311,13 @@
// Lock Aware Transactional Memory support methods
//--------------------------------------------------------------------------
- static void pthread_lock(latm::mutex_type* lock);
- static bool pthread_trylock(latm::mutex_type* lock);
- static void pthread_unlock(latm::mutex_type* lock);
+
+ template <typename M>
+ static void lock(M& m, latm::mutex_type& lock);
+ template <typename M>
+ static bool try_lock(M& m, latm::mutex_type& lock);
+ template <typename M>
+ static void unlock(M& m, latm::mutex_type& lock);
//--------------------------------------------------------------------------
#if PERFORMING_LATM
@@ -1394,32 +1398,50 @@
//--------------------------------------------------------------------------
// deferred updating locking methods
//--------------------------------------------------------------------------
- static void def_full_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool def_full_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void def_full_pthread_unlock_mutex(latm::mutex_type* mutex);
-
- static void def_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool def_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void def_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex);
-
- static void def_tx_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool def_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void def_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex);
+ template <typename M>
+ static void def_full_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool def_full_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void def_full_unlock(M& m, latm::mutex_type& mutex);
+
+ template <typename M>
+ static void def_tm_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool def_tm_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void def_tm_unlock(M& m, latm::mutex_type& mutex);
+
+ template <typename M>
+ static void def_tx_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool def_tx_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void def_tx_unlock(M& m, latm::mutex_type& mutex);
//--------------------------------------------------------------------------
// direct updating locking methods
//--------------------------------------------------------------------------
- static void dir_full_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool dir_full_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void dir_full_pthread_unlock_mutex(latm::mutex_type* mutex);
-
- static void dir_tm_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool dir_tm_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void dir_tm_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex);
-
- static void dir_tx_conflicting_lock_pthread_lock_mutex(latm::mutex_type* mutex);
- static bool dir_tx_conflicting_lock_pthread_trylock_mutex(latm::mutex_type* mutex);
- static void dir_tx_conflicting_lock_pthread_unlock_mutex(latm::mutex_type* mutex);
+ template <typename M>
+ static void dir_full_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool dir_full_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void dir_full_unlock(M& m, latm::mutex_type& mutex);
+
+ template <typename M>
+ static void dir_tm_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool dir_tm_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void dir_tm_unlock(M& m, latm::mutex_type& mutex);
+
+ template <typename M>
+ static void dir_tx_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static bool dir_tx_try_lock(M& m, latm::mutex_type& mutex);
+ template <typename M>
+ static void dir_tx_unlock(M& m, latm::mutex_type& mutex);
//--------------------------------------------------------------------------
@@ -1995,9 +2017,12 @@
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 void unlock(latm::mutex_type& lock) {transaction::pthread_unlock(&lock);}
+template <typename M>
+inline void lock(M& m, latm::mutex_type& lock) {transaction::lock(m, lock);}
+template <typename M>
+inline bool try_lock(M& m, latm::mutex_type& lock) {return transaction::try_lock(m, lock);}
+template <typename M>
+inline void unlock(M& m, latm::mutex_type& lock) {transaction::unlock(m, lock);}
template <class T> T* cache_allocate(transaction* t) {
Modified: sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,11 +36,17 @@
#include <boost/stm/synch.hpp>
#include "main.h"
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
+
static boost::stm::native_trans<int> gInt;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type lock1 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type lock1;
+static boost::mutex lock1;
#endif
////////////////////////////////////////////////////////////////////////////
using namespace std; using namespace boost::stm;
@@ -64,7 +70,7 @@
try
{
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
++gInt.value();
cout << "\t" << gInt.value() << endl;
}
@@ -74,7 +80,7 @@
// intermediate state IF they can get lock1 (they shouldn't)
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
--gInt.value();
cout << "\t" << gInt.value() << endl;
}
@@ -115,7 +121,7 @@
for (int i = startingValue; i < 100*endingValue; ++i)
{
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
cout << gInt.value() << endl;
}
SLEEP(10); // do nothing on purpose
Modified: sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx2.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx2.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/isolatedComposedIntLockInTx2.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,14 +36,20 @@
#include <boost/stm/synch.hpp>
#include "main.h"
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
+
static boost::stm::native_trans<int> gInt;
static boost::stm::native_trans<int> gInt2;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type lock1 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type lock2 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type lock1;
-//static boost::stm::latm::mutex_type lock2;
+static boost::mutex lock1;
+//static boost::mutex lock2;
#endif
////////////////////////////////////////////////////////////////////////////
using namespace std; using namespace boost::stm;
@@ -68,7 +74,7 @@
try
{
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
++gInt.value();
cout << "\t" << gInt.value() << endl;
}
@@ -78,7 +84,7 @@
// intermediate state IF they can get lock1 (they shouldn't)
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
--gInt.value();
cout << "\t" << gInt.value() << endl;
}
Modified: sandbox/stm/branches/vbe/libs/stm/test/isolatedIntLockInTx.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/isolatedIntLockInTx.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/isolatedIntLockInTx.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,12 +36,18 @@
#include <boost/stm/synch.hpp>
#include "main.h"
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
+
static boost::stm::native_trans<int> gInt;
static boost::stm::native_trans<int> gInt2;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type lock1 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type lock1;
+static boost::mutex lock1;
#endif
////////////////////////////////////////////////////////////////////////////
using namespace std; using namespace boost::stm;
@@ -78,7 +84,7 @@
// reflect all changes made previously inside the tx
//-------------------------------------------------------
{
- stm::lock_guard<latm::mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk(lock1);
cout << gInt.value() << endl;
++gInt.value();
Modified: sandbox/stm/branches/vbe/libs/stm/test/litExample.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/litExample.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/litExample.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,16 +36,22 @@
#include <boost/stm/synch.hpp>
#include "main.h"
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type L2 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L3 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L4 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type L8 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
#else
-static boost::stm::latm::mutex_type L2;
-static boost::stm::latm::mutex_type L3;
-static boost::stm::latm::mutex_type L4;
-//static boost::stm::latm::mutex_type L8;
+typedef boost::mutex mutex_type;
+#endif
+
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t L2 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L3 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L4 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t L8 = PTHREAD_MUTEX_INITIALIZER;
+#else
+static boost::mutex L2;
+static boost::mutex L3;
+static boost::mutex L4;
+//static boost::mutex L8;
#endif
////////////////////////////////////////////////////////////////////////////
using namespace std; using namespace boost::stm;
@@ -64,7 +70,7 @@
static void inc2()
{
- stm::lock_guard<latm::mutex_type> lk(L2);
+ stm::lock_guard<mutex_type> lk(L2);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr2[i].value();
@@ -73,7 +79,7 @@
static void inc3()
{
- stm::lock_guard<latm::mutex_type> lk(L3);
+ stm::lock_guard<mutex_type> lk(L3);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr3[i].value();
@@ -82,7 +88,7 @@
static void inc4()
{
- stm::lock_guard<latm::mutex_type> lk(L4);
+ stm::lock_guard<mutex_type> lk(L4);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr4[i].value();
@@ -138,7 +144,7 @@
if (work3) return;
work3 = true;
- stm::lock_guard<latm::mutex_type> lk(L8);
+ stm::lock_guard<mutex_type> lk(L8);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr8[i].value();
Modified: sandbox/stm/branches/vbe/libs/stm/test/lotExample.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/lotExample.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/lotExample.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -36,20 +36,26 @@
#include <boost/stm/synch.hpp>
#include "main.h"
-#ifndef BOOST_STM_USE_BOOST_MUTEX
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
+
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type L1 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L2 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L3 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type L8 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type L9 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L2 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L3 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t L8 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t L9 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type L1;
-static boost::stm::latm::mutex_type L2;
-static boost::stm::latm::mutex_type L3;
-//static boost::stm::latm::mutex_type L8;
-//static boost::stm::latm::mutex_type L9;
+static boost::mutex L1;
+static boost::mutex L2;
+static boost::mutex L3;
+//static boost::mutex L8;
+//static boost::mutex L9;
#endif
////////////////////////////////////////////////////////////////////////////
@@ -115,7 +121,7 @@
for (int iters = 0; iters < iterations; ++iters)
{
- stm::lock_guard<latm::mutex_type> lk(L8);
+ stm::lock_guard<mutex_type> lk(L8);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr8[i].value();
@@ -131,7 +137,7 @@
for (int iters = 0; iters < iterations; ++iters)
{
- stm::lock_guard<latm::mutex_type> lk(L9);
+ stm::lock_guard<mutex_type> lk(L9);
for (int i = 0; i < kMaxArrSize; ++i)
{
++arr9[i].value();
@@ -258,7 +264,7 @@
for (int iters = 0; iters < lockFactor*3000*iterations; ++iters)
{
- stm::lock_guard<latm::mutex_type> lk(L1);
+ stm::lock_guard<mutex_type> lk(L1);
int sum = 0;
for (int i = 0; i < kMaxArrSize; ++i) sum += arr1[i].value();
}
@@ -282,7 +288,7 @@
for (int iters = 0; iters < lockFactor*3000*iterations; ++iters)
{
- stm::lock_guard<latm::mutex_type> lk(L2);
+ stm::lock_guard<mutex_type> lk(L2);
int sum = 0;
for (int i = 0; i < kMaxArrSize; ++i) sum += arr2[i].value();
}
@@ -306,7 +312,7 @@
for (int iters = 0; iters < 10000*iterations; ++iters)
{
- stm::lock_guard<latm::mutex_type> lk(L3);
+ stm::lock_guard<mutex_type> lk(L3);
int sum = 0;
for (int i = 0; i < kMaxArrSize; ++i) sum += arr3[i].value();
}
Modified: sandbox/stm/branches/vbe/libs/stm/test/main.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/main.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/main.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -51,7 +51,7 @@
class String;
class Integer;
-extern boost::stm::latm::mutex_type outputMutex;
+extern pthread_mutex_t outputMutex;
extern String globalString;
extern boost::stm::native_trans<int> threadsFinished;
Modified: sandbox/stm/branches/vbe/libs/stm/test/nestedTxs.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/nestedTxs.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/nestedTxs.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -34,17 +34,22 @@
#include "nestedTxs.h"
#include <boost/stm/synch.hpp>
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type L = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L2 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L3 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type L4 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t L = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L2 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L3 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t L4 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type L;
-static boost::stm::latm::mutex_type L2;
-static boost::stm::latm::mutex_type L3;
-//static boost::stm::latm::mutex_type L4;
+static boost::mutex L;
+static boost::mutex L2;
+static boost::mutex L3;
+//static boost::mutex L4;
#endif
using namespace boost::stm;
@@ -120,7 +125,7 @@
{
transaction::initialize_thread();
- stm::lock_guard<latm::mutex_type> lk(L2);
+ stm::lock_guard<mutex_type> lk(L2);
SLEEP(10000);
@@ -184,8 +189,8 @@
SLEEP(1000);
- stm::lock_guard<latm::mutex_type> lk(L);
- stm::lock_guard<latm::mutex_type> lk3(L3);
+ stm::lock_guard<mutex_type> lk(L);
+ stm::lock_guard<mutex_type> lk3(L3);
try_atomic(t)
{
@@ -210,8 +215,8 @@
SLEEP(1000);
- stm::unique_lock<latm::mutex_type> lk(L);
- stm::lock_guard<latm::mutex_type> lk3(L3);
+ stm::unique_lock<mutex_type> lk(L);
+ stm::lock_guard<mutex_type> lk3(L3);
try_atomic(t)
{
Modified: sandbox/stm/branches/vbe/libs/stm/test/stm.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/stm.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/stm.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -52,10 +52,10 @@
time_t endTimer = 0;
eWorkType gWorkLoadType;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type finishLock = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+static pthread_mutex_t finishLock = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type finishLock;
+static boost::mutex finishLock;
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Modified: sandbox/stm/branches/vbe/libs/stm/test/testHT_latm.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/testHT_latm.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/testHT_latm.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -107,7 +107,7 @@
}
}
- boost::stm::latm::mutex_type* get_hash_lock(int val) { return buckets_[val].get_list_lock(); }
+ pthread_mutex_t* get_hash_lock(int val) { return buckets_[val].get_list_lock(); }
private:
LATM::LinkedList<T> buckets_[nHashMap::kBuckets];
Modified: sandbox/stm/branches/vbe/libs/stm/test/testHashMapWithLocks.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/testHashMapWithLocks.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/testHashMapWithLocks.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -79,7 +79,7 @@
}
}
- boost::stm::latm::mutex_type* get_hash_lock(int val) { return buckets_[val].get_list_lock(); }
+ pthread_mutex_t* get_hash_lock(int val) { return buckets_[val].get_list_lock(); }
private:
LATM::LinkedList<T> buckets_[nHashMap::kBuckets2];
Modified: sandbox/stm/branches/vbe/libs/stm/test/testLL_latm.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/testLL_latm.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/testLL_latm.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -20,7 +20,11 @@
#include <boost/stm/synch.hpp>
#include <pthread.h>
#include <fstream>
-
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
namespace LATM
@@ -93,7 +97,7 @@
LinkedList()
{
-#ifndef BOOST_STM_USE_BOOST_MUTEX
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
pthread_mutex_init (&list_lock_, 0);
#endif
head_.value() = T();
@@ -101,7 +105,7 @@
~LinkedList() { quick_clear(); }
- boost::stm::latm::mutex_type* get_list_lock() { return &list_lock_; }
+ pthread_mutex_t* get_list_lock() { return &list_lock_; }
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
@@ -196,7 +200,7 @@
{
using namespace boost::stm;
using namespace boost;
- stm::lock_guard<latm::mutex_type> lk(list_lock_);
+ stm::lock_guard<mutex_type> lk(list_lock_);
list_node<T> *headP = &head_;
@@ -254,7 +258,7 @@
{
using namespace boost::stm;
using namespace boost;
- stm::lock_guard<latm::mutex_type> lk(list_lock_);
+ stm::lock_guard<mutex_type> lk(list_lock_);
LATM::list_node<T> *cur = &head_;
@@ -532,7 +536,7 @@
public:
list_node<T> head_;
- boost::stm::latm::mutex_type list_lock_;
+ pthread_mutex_t list_lock_;
};
} // LockAwareTransactions
Modified: sandbox/stm/branches/vbe/libs/stm/test/testLinkedListWithLocks.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/testLinkedListWithLocks.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/testLinkedListWithLocks.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -21,6 +21,11 @@
#include <pthread.h>
#include <fstream>
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -94,7 +99,7 @@
LinkedList()
{
-#ifndef BOOST_STM_USE_BOOST_MUTEX
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
pthread_mutex_init (&list_lock_, 0);
#endif
head_.value() = T();
@@ -102,7 +107,7 @@
~LinkedList() { quick_clear(); }
- boost::stm::latm::mutex_type* get_list_lock() { return &list_lock_; }
+ pthread_mutex_t* get_list_lock() { return &list_lock_; }
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
@@ -179,7 +184,7 @@
{
using namespace boost::stm;
using namespace boost;
- stm::lock_guard<latm::mutex_type> lk(list_lock_);
+ stm::lock_guard<mutex_type> lk(list_lock_);
list_node<T> *headP = &head_;
@@ -237,7 +242,7 @@
{
using namespace boost::stm;
using namespace boost;
- stm::lock_guard<latm::mutex_type> lk(list_lock_);
+ stm::lock_guard<mutex_type> lk(list_lock_);
LATM::list_node<T> *cur = &head_;
@@ -514,7 +519,7 @@
}
list_node<T> head_;
- boost::stm::latm::mutex_type list_lock_;
+ pthread_mutex_t list_lock_;
};
} // LockAwareTransactions
Modified: sandbox/stm/branches/vbe/libs/stm/test/txLinearLock.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/txLinearLock.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/txLinearLock.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -19,12 +19,14 @@
static boost::stm::native_trans<int> gInt1;
static boost::stm::native_trans<int> gInt2;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type lock1 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type lock2 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+static pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type lock1;
-static boost::stm::latm::mutex_type lock2;
+typedef boost::mutex mutex_type;
+static boost::mutex lock1;
+static boost::mutex lock2;
#endif
////////////////////////////////////////////////////////////////////////////
@@ -50,7 +52,7 @@
try
{
{
- stm::lock_guard<latm::mutex_type> lk(lock2);
+ stm::lock_guard<mutex_type> lk(lock2);
--gInt2.value();
cout << "\tgInt2: " << gInt2.value() << endl;
}
@@ -58,7 +60,7 @@
SLEEP(1000);
{
- stm::lock_guard<latm::mutex_type> lk(lock2);
+ stm::lock_guard<mutex_type> lk(lock2);
++gInt1.value();
cout << "\tgInt1: " << gInt1.value() << endl;
}
@@ -100,8 +102,8 @@
{
SLEEP(1000);
- stm::lock_guard<latm::mutex_type> lk(lock1);
- stm::lock_guard<latm::mutex_type> lk2(lock2);
+ stm::lock_guard<mutex_type> lk(lock1);
+ stm::lock_guard<mutex_type> lk2(lock2);
--gInt1.value();
++gInt2.value();
Modified: sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.cpp 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -21,16 +21,18 @@
static newSyntaxNS::LinkedList< list_node_type > *llist = 0;
-#ifndef BOOST_STM_USE_BOOST_MUTEX
-static boost::stm::latm::mutex_type L = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L2 = PTHREAD_MUTEX_INITIALIZER;
-static boost::stm::latm::mutex_type L3 = PTHREAD_MUTEX_INITIALIZER;
-//static boost::stm::latm::mutex_type L4 = PTHREAD_MUTEX_INITIALIZER;
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+static pthread_mutex_t L = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L2 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t L3 = PTHREAD_MUTEX_INITIALIZER;
+//static pthread_mutex_t L4 = PTHREAD_MUTEX_INITIALIZER;
#else
-static boost::stm::latm::mutex_type L;
-static boost::stm::latm::mutex_type L2;
-static boost::stm::latm::mutex_type L3;
-//static boost::stm::latm::mutex_type L4;
+typedef boost::mutex mutex_type;
+static boost::mutex L;
+static boost::mutex L2;
+static boost::mutex L3;
+//static boost::mutex L4;
#endif
using namespace boost::stm;
@@ -288,7 +290,7 @@
{
transaction::initialize_thread();
- stm::lock_guard<latm::mutex_type> lk(L2);
+ stm::lock_guard<mutex_type> lk(L2);
SLEEP(10000);
@@ -337,8 +339,8 @@
SLEEP(1000);
- stm::lock_guard<latm::mutex_type> lk(L);
- stm::lock_guard<latm::mutex_type> lk3(L3);
+ stm::lock_guard<mutex_type> lk(L);
+ stm::lock_guard<mutex_type> lk3(L3);
try_atomic(t)
{
@@ -362,8 +364,8 @@
SLEEP(1000);
- stm::unique_lock<latm::mutex_type> lk(L);
- stm::lock_guard<latm::mutex_type> lk3(L3);
+ stm::unique_lock<mutex_type> lk(L);
+ stm::lock_guard<mutex_type> lk3(L3);
try_atomic(t)
{
Modified: sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/usingLockTx.h 2009-11-08 13:06:39 EST (Sun, 08 Nov 2009)
@@ -23,6 +23,11 @@
#include <pthread.h>
#include <fstream>
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
+typedef pthread_mutex_t mutex_type;
+#else
+typedef boost::mutex mutex_type;
+#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -96,7 +101,7 @@
LinkedList()
{
-#ifndef BOOST_STM_USE_BOOST_MUTEX
+#ifndef BOOST_STM_T_USE_BOOST_MUTEX
pthread_mutex_init (&list_lock_, 0);
#endif
head_.value() = T();
@@ -104,7 +109,7 @@
~LinkedList() { quick_clear(); }
- boost::stm::latm::mutex_type* get_list_lock() { return &list_lock_; }
+ pthread_mutex_t* get_list_lock() { return &list_lock_; }
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
@@ -239,7 +244,7 @@
{
using namespace boost::stm;
using namespace boost;
- stm::lock_guard<latm::mutex_type> lk(list_lock_);
+ stm::lock_guard<mutex_type> lk(list_lock_);
LATM::list_node<T> *cur = &head_;
@@ -515,7 +520,7 @@
}
list_node<T> head_;
- boost::stm::latm::mutex_type list_lock_;
+ pthread_mutex_t list_lock_;
};
} // LockAwareTransactions
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