|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56975 - in sandbox/stm/branches/vbe/boost: stm stm/detail synchro synchro/detail synchro/lockable synchro/lockers synchro/pthread synchro/thread
From: vicente.botet_at_[hidden]
Date: 2009-10-18 06:19:08
Author: viboes
Date: 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
New Revision: 56975
URL: http://svn.boost.org/trac/boost/changeset/56975
Log:
TBoost.STM vbe: Non transactional Synchro mechanism (following as far as possible the Boost names)
* Add a new directory synchro for synchronization specific features (boost/synchro)
* Add free functions to lock,unlock, try_lock, ... (boost/synchro/lock.hpp, boost/synchro/unlock.hpp,boost/synchro/try_lock.hpp ..)
* Add lockers lock_guard, lock_guard_if, unique_lock (boost/synchro/locks.hpp)
* Don't use var_auto_lock as it is not exception safe
* Create non transactional synchronization language-like macros (boost/synchro/language_like.hpp)
Added:
sandbox/stm/branches/vbe/boost/synchro/
sandbox/stm/branches/vbe/boost/synchro/detail/
sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/exceptions.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/language_like.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/
sandbox/stm/branches/vbe/boost/synchro/lockable.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockers/
sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/locks.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/pthread/
sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/tags.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/thread/
sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/synchro/time.hpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp | 2
sandbox/stm/branches/vbe/boost/stm/detail/config.hpp | 1
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_full_impl.hpp | 54 ++++++++++++++++++++++++---------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tm_impl.hpp | 26 ++++++++++--------
sandbox/stm/branches/vbe/boost/stm/detail/latm_def_tx_impl.hpp | 12 +++++--
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_full_impl.hpp | 45 +++++++++++++++++----------------
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tm_impl.hpp | 7 ++--
sandbox/stm/branches/vbe/boost/stm/detail/latm_dir_tx_impl.hpp | 9 ++++--
sandbox/stm/branches/vbe/boost/stm/detail/latm_general_impl.hpp | 4 ++
sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp | 15 +++++-----
sandbox/stm/branches/vbe/boost/stm/synchro.hpp | 11 ++++++-
11 files changed, 110 insertions(+), 76 deletions(-)
Modified: sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/auto_lock.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -102,7 +102,7 @@
for (size_t i = 0; i < timeOut; ++i)
{
- if (0 == synchro::try_lock(*lock_))
+ if (synchro::try_lock(*lock_))
{
hasLock_ = true;
insert_into_threaded_lock_map(mutex);
Modified: sandbox/stm/branches/vbe/boost/stm/detail/config.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/config.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/config.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -101,6 +101,7 @@
// Define BOOST_STM_ALLOWS_DELETERS when you want STM manage with others deleters than delete
#define BOOST_STM_ALLOWS_DELETERS 1
+#define BOOST_STM_USE_BOOST_SYNCHRO 1
#endif // BOOST_STM_DETAIL_CONFIG_H
Modified: sandbox/stm/branches/vbe/boost/stm/detail/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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -58,8 +58,10 @@
//--------------------------------------------------------------------------
if (latmLockedLocks_.empty())
{
- synchro::lock(*general_lock());
- synchro::lock(*inflight_lock());
+ synchro::lock_guard<Mutex> lock_g(*general_lock());
+ //synchro::lock(*general_lock());
+ synchro::lock_guard<Mutex> lock_i(*inflight_lock());
+ //synchro::lock(*inflight_lock());
std::list<transaction*> txList;
for (InflightTxes::iterator i = transactionsInFlight_.begin();
@@ -74,8 +76,8 @@
}
else
{
- synchro::unlock(*general_lock());
- synchro::unlock(*inflight_lock());
+ //synchro::unlock(*general_lock());
+ //synchro::unlock(*inflight_lock());
return false;
}
}
@@ -85,8 +87,8 @@
(*it)->force_to_abort();
}
- synchro::unlock(*general_lock());
- synchro::unlock(*inflight_lock());
+ //synchro::unlock(*general_lock());
+ //synchro::unlock(*inflight_lock());
}
try { latmLockedLocks_.insert(mutex); }
@@ -113,9 +115,11 @@
t->add_to_obtained_locks(mutex);
t->commit_deferred_update_tx();
- synchro::lock(*latm_lock());
+ { synchro::lock_guard<Mutex> lock_l(*latm_lock());
+ //synchro::lock(*latm_lock());
latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- synchro::unlock(*latm_lock());
+ //synchro::unlock(*latm_lock());
+ }
// TBR if (hadLock) return 0;
// TBR else return lock(mutex);
@@ -129,10 +133,11 @@
{
// TBR int val = lock(mutex);
// TBR if (0 != val) return val;
+ //{
synchro::lock(*mutex);
-
+ //synchro::lock_guard<Mutex> lock_m(*mutex);
synchro::lock(latmMutex_);
-
+ //synchro::lock_guard<Mutex> lock_l(latmMutex_);
try
{
//--------------------------------------------------------------------
@@ -152,6 +157,7 @@
//-----------------------------------------------------------------------
synchro::unlock(*mutex);
synchro::unlock(latmMutex_);
+ //}
SLEEP(cm_lock_sleep_time());
waitTime += cm_lock_sleep_time();
@@ -177,18 +183,22 @@
t->add_to_obtained_locks(mutex);
t->commit_deferred_update_tx();
- synchro::lock(*latm_lock());
+ { synchro::lock_guard<Mutex> lock_l(*latm_lock());
+ //synchro::lock(*latm_lock());
latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- synchro::unlock(*latm_lock());
+ //synchro::unlock(*latm_lock());
+ }
if (hadLock) return 0;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(*mutex)?0:1;
}
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::trylock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
- synchro::lock(latmMutex_);
+ //synchro::lock(latmMutex_);
+ synchro::lock_guard<Mutex> lock_l(latmMutex_);
try
{
@@ -198,19 +208,19 @@
if (!def_do_core_full_pthread_lock_mutex(mutex, 0, 0))
{
synchro::unlock(*mutex);
- synchro::unlock(latmMutex_);
+ //synchro::unlock(latmMutex_);
return -1;
}
}
catch (...)
{
synchro::unlock(*mutex);
- synchro::unlock(latmMutex_);
+ //synchro::unlock(latmMutex_);
throw;
}
latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
- synchro::unlock(latmMutex_);
+ //synchro::unlock(latmMutex_);
// note: we do not release the transactionsInFlightMutex - this will prevents
// new transactions from starting until this lock is released
return 0;
@@ -221,8 +231,9 @@
//----------------------------------------------------------------------------
inline int transaction::def_full_pthread_unlock_mutex(Mutex *mutex)
{
- synchro::lock(latmMutex_);
bool hasLock = true;
+ { synchro::lock_guard<Mutex> lock_l(latmMutex_);
+ //synchro::lock(latmMutex_);
if (transaction* t = get_inflight_tx_of_same_thread(false))
{
@@ -243,7 +254,8 @@
if (latmLockedLocks_.empty()) synchro::unlock(*inflight_lock());
latmLockedLocksOfThreadMap_.erase(mutex);
- synchro::unlock(latmMutex_);
+ //synchro::unlock(latmMutex_);
+ }
// TBR if (hasLock) return unlock(mutex);
// TBR else return 0;
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -64,7 +64,8 @@
// so we can abort all the in-flight transactions
if (latmLockedLocks_.empty())
{
- var_auto_lock<PLOCK> autlock(general_lock(), inflight_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
+ synchro::lock_guard<Mutex> autolock_i(*inflight_lock());
std::list<transaction*> txList;
@@ -127,11 +128,11 @@
{
// TRR int val = lock(mutex);
// TRR if (0 != val) return val;
- {
- synchro::lock_guard<Mutex> lock_m(*latm_lock());
- synchro::lock_guard<Mutex> lock_l(latmMutex_);
- //synchro::lock(*mutex);
- //synchro::lock(latmMutex_);
+ //{
+ //synchro::lock_guard<Mutex> lock_m(*latm_lock());
+ //synchro::lock_guard<Mutex> lock_l(latmMutex_);
+ synchro::lock(*mutex);
+ synchro::lock(latmMutex_);
try
{
@@ -151,9 +152,9 @@
//-----------------------------------------------------------------------
// we weren't able to do the core lock work, unlock our mutex and sleep
//-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- }
+ synchro::unlock(*mutex);
+ synchro::unlock(latmMutex_);
+ //}
SLEEP(cm_lock_sleep_time());
waitTime += cm_lock_sleep_time();
@@ -188,14 +189,15 @@
}
if (hadLock) return 0;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(*mutex)?0:1;
}
//synchro::unique_lock<Mutex> lock_m(*mutex, synchro::try_to_lock);
//if (lock_m) return true;
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::try_lock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
//synchro::lock(latmMutex_);
synchro::lock_guard<Mutex> lock_l(latmMutex_);
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -50,7 +50,8 @@
// set. do not keep in-flight transactions blocked once the transactions have
// been processed.
//--------------------------------------------------------------------------
- var_auto_lock<PLOCK> autolock(general_lock(), inflight_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
+ synchro::lock_guard<Mutex> autolock_i(*inflight_lock());
std::list<transaction *> txList;
std::set<size_t> txThreadId;
@@ -218,8 +219,9 @@
bool txIsIrrevocable = false;
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::try_lock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
synchro::lock(latmMutex_);
@@ -264,7 +266,9 @@
//----------------------------------------------------------------------------
inline int transaction::def_tx_conflicting_lock_pthread_unlock_mutex(Mutex *mutex)
{
- var_auto_lock<PLOCK> autolock(latm_lock(), general_lock(), inflight_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_l(*latm_lock());
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
+ synchro::lock_guard<Mutex> autolock_i(*inflight_lock());
bool hasLock = true;
if (transaction* t = get_inflight_tx_of_same_thread(true))
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -59,7 +59,7 @@
if (latmLockedLocks_.empty())
{
- {
+ //{
//synchro::lock_guard<Mutex> lock_g(*general_lock());
synchro::lock(*general_lock());
//synchro::lock_guard<Mutex> lock_i(*inflight_lock());
@@ -96,7 +96,7 @@
synchro::unlock(*general_lock());
synchro::unlock(*inflight_lock());
- }
+ //}
//-----------------------------------------------------------------------
// now we must stall until all in-flight transactions are gone, otherwise
@@ -144,35 +144,35 @@
int waitTime = 0, aborted = 0;
for (;;)
{
- {
+ //{
// TBR int val = lock(mutex);
// TBR if (0 != val) return val;
- //synchro::lock(*mutex);
- synchro::lock_guard<Mutex> lock_m(*mutex);
+ synchro::lock(*mutex);
+ //synchro::lock_guard<Mutex> lock_m(*mutex);
- //synchro::lock(latmMutex_);
- synchro::lock_guard<Mutex> lock_l(latmMutex_);
+ synchro::lock(latmMutex_);
+ //synchro::lock_guard<Mutex> lock_l(latmMutex_);
- //try
- //{
+ try
+ {
//--------------------------------------------------------------------
// if we are able to do the core lock work, break
//--------------------------------------------------------------------
if (dir_do_core_full_pthread_lock_mutex(mutex, waitTime, aborted)) break;
- //}
- //catch (...)
- //{
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- //throw;
- //}
+ }
+ catch (...)
+ {
+ synchro::unlock(*mutex);
+ synchro::unlock(latmMutex_);
+ throw;
+ }
//-----------------------------------------------------------------------
// we weren't able to do the core lock work, unlock our mutex and sleep
//-----------------------------------------------------------------------
- //synchro::unlock(*mutex);
- //synchro::unlock(latmMutex_);
- }
+ synchro::unlock(*mutex);
+ synchro::unlock(latmMutex_);
+ //}
SLEEP(cm_lock_sleep_time());
waitTime += cm_lock_sleep_time();
@@ -203,13 +203,14 @@
synchro::unlock(*latm_lock());
if (hadLock) return 0;
- else return synchro::try_lock(*mutex);
+ else return synchro::try_lock(*mutex)?0:1;
}
//synchro::unique_lock<Mutex> lock_m(*mutex, synchro::try_to_lock);
//if (lock_m) return true;
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::try_lock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
//synchro::lock(latmMutex_);
synchro::lock_guard<Mutex> lock_l(latmMutex_);
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -184,11 +184,12 @@
synchro::lock(*latm_lock());
latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
synchro::unlock(*latm_lock());
- return synchro::try_lock(*mutex);
+ return synchro::try_lock(*mutex)?0:1;
}
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::try_lock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
synchro::lock(latmMutex_);
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -252,8 +252,9 @@
bool txIsIrrevocable = false;
- int val = synchro::try_lock(*mutex);
- if (0 != val) return val;
+ //int val = synchro::try_lock(*mutex);
+ //if (0 != val) return val;
+ if (!synchro::try_lock(*mutex)) return 1;
synchro::lock(latmMutex_);
@@ -297,7 +298,9 @@
//----------------------------------------------------------------------------
inline int transaction::dir_tx_conflicting_lock_pthread_unlock_mutex(Mutex *mutex)
{
- var_auto_lock<PLOCK> autolock(latm_lock(), general_lock(), inflight_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_l(*latm_lock());
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
+ synchro::lock_guard<Mutex> autolock_i(*inflight_lock());
bool hasLock = true;
if (transaction* t = get_inflight_tx_of_same_thread(true))
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-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -325,7 +325,9 @@
if (!doing_tx_lock_protection()) return;
{
- var_auto_lock<PLOCK> autol(latm_lock(), general_lock(), inflight_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_l(*latm_lock());
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
+ synchro::lock_guard<Mutex> autolock_i(*inflight_lock());
if (get_tx_conflicting_locks().find(inLock) != get_tx_conflicting_locks().end()) return;
get_tx_conflicting_locks().insert(inLock);
Modified: sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/detail/transaction_impl.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -230,7 +230,7 @@
// otherwise, force the tx to commit its writes/reads
//--------------------------------------------------------------------------
#if 0
- while (0 != synchro::try_lock(&transactionMutex_))
+ while (!synchro::try_lock(&transactionMutex_))
{
bookkeeping_.inc_lock_convoy_ms(1);
SLEEP(1);
@@ -281,7 +281,7 @@
//-----------------------------------------------------------------------------
inline void transaction::lock_tx()
{
- while (0 != synchro::try_lock(*mutex()))
+ while (!synchro::try_lock(*mutex()))
{
SLEEP(1);
}
@@ -573,7 +573,8 @@
#ifdef LOGGING_BLOCKS
if (++iterations > 100)
{
- var_auto_lock<PLOCK> autolock(latm_lock(), general_lock(), 0);
+ synchro::lock_guard<Mutex> autolock_l(*latm_lock());
+ synchro::lock_guard<Mutex> autolock_g(*general_lock());
//unblock_threads_if_locks_are_empty();
logFile_ << outputBlockedThreadsAndLockedLocks().c_str();
SLEEP(10000);
@@ -904,7 +905,7 @@
return;
}
- while (0 != synchro::try_lock(transactionMutex_)) {
+ while (!synchro::try_lock(transactionMutex_)) {
//std::cout << __LINE__ << " invalidating_deferred_end_transaction" << std::endl;
}
@@ -1849,7 +1850,7 @@
//----------------------------------------------------------------------------
inline size_t transaction::earliest_start_time_of_inflight_txes()
{
- var_auto_lock<PLOCK> a(inflight_lock(), 0);
+ synchro::lock_guard<Mutex> a(*inflight_lock());
size_t secs = 0xffffffff;
@@ -1874,7 +1875,7 @@
size_t earliestInFlightTx = earliest_start_time_of_inflight_txes();
- var_auto_lock<PLOCK> a(&deletionBufferMutex_, 0);
+ synchro::lock_guard<Mutex> a(deletionBufferMutex_);
for (DeletionBuffer::iterator i = deletionBuffer_.begin(); i != deletionBuffer_.end();)
{
@@ -1902,7 +1903,7 @@
if (!deletedMemoryList().empty())
{
- var_auto_lock<PLOCK> a(&deletionBufferMutex_, 0);
+ synchro::lock_guard<Mutex> a(deletionBufferMutex_);
deletionBuffer_.insert( std::pair<size_t, MemoryContainerList>
(time(0), deletedMemoryList()) );
deletedMemoryList().clear();
Modified: sandbox/stm/branches/vbe/boost/stm/synchro.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/synchro.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/synchro.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -16,6 +16,10 @@
#include <boost/stm/detail/config.hpp>
+#ifdef BOOST_STM_USE_BOOST_SYNCHRO
+#include <boost/synchro.hpp>
+#endif
+
//-----------------------------------------------------------------------------
#include <stdarg.h>
#include <pthread.h>
@@ -42,7 +46,9 @@
#endif
//-----------------------------------------------------------------------------
+
namespace boost {
+#ifndef BOOST_STM_USE_BOOST_SYNCHRO
namespace synchro {
class lock_error : public std::exception
@@ -116,7 +122,8 @@
return !res;
}
#endif
-
+
+
template<typename Mutex>
class lock_guard
{
@@ -166,7 +173,6 @@
}
};
-
template<typename Mutex>
class unique_lock
{
@@ -396,6 +402,7 @@
}
+#endif
namespace stm {
//-----------------------------------------------------------------------------
Added: sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/detail/config.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_DETAIL_CONFIG_HPP
+#define BOOST_SYNCHO_DETAIL_CONFIG_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/config.hpp>
+#include <boost/thread/detail/platform.hpp>
+//-----------------------------------------------------------------------------
+
+#endif // BOOST_SYNCHO_DETAIL_CONFIG_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/exceptions.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/exceptions.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_EXCEPTIONS_HPP
+#define BOOST_SYNCHO_EXCEPTIONS_HPP
+
+//-----------------------------------------------------------------------------
+#include <stdexcept>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ class lock_error : public std::logic_error {
+ public:
+ lock_error() : std::logic_error("synchro::lock_error") {}
+ };
+
+ class timeout_exception : public std::logic_error {
+ public:
+ timeout_exception() : std::logic_error("synchro::timeout_exception") {}
+ };
+
+}}
+#endif // BOOST_SYNCHO_EXCEPTIONS_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/language_like.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/language_like.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,87 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHRO_SYNCHRONIZED__HPP
+#define BOOST_SYNCHRO_SYNCHRONIZED__HPP
+
+namespace boost { namespace synchro { namespace detail {
+ inline bool no_opt_false() {return false;}
+}}}
+
+#define BOOST_SYNCHRO_SYNCHRONIZE_EXT(VAR_DECL) \
+ if (bool __stop = boost::synchro::detail::no_opt_false()) {} else \
+ for (VAR_DECL;!__stop; __stop= true)
+
+#define BOOST_SYNCHRO_SYNCHRONIZE_TYPE(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE))
+
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_TYPE(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::adopt_lock))
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE_TYPE(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::defer_lock))
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE(TYPE, VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, boost::synchro::try_to_lock))
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_UNTIL(TYPE, VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(LOCKABLE, ABS_TIME))
+#define BOOST_SYNCHRO_SYNCHRONIZE_TYPE_UNTIL(TYPE, VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_EXT(boost::synchro::unique_lock<TYPE> VAR(ABS_TIME, LOCKABLE))
+
+#define BOOST_SYNCHRO_SYNCHRONIZE_VAR(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_TYPE(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_TYPE(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_DEFER_SYNCHRONIZE_TYPE(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR(VAR, LOCKABLE) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE(boost::mutex, VAR, LOCKABLE)
+#define BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL(VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_TYPE_UNTIL(boost::mutex, VAR, LOCKABLE, ABS_TIME)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL(VAR, LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_TYPE_UNTIL(boost::mutex, VAR, LOCKABLE, ABS_TIME)
+
+#define BOOST_SYNCHRO_SYNCHRONIZE(LOCKABLE) \
+ BOOST_SYNCHRO_SYNCHRONIZE_VAR(_, LOCKABLE)
+#define BOOST_SYNCHRO_ADOPT_SYNCHRONIZE(LOCKABLE) \
+ BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR(_, LOCKABLE)
+#define BOOST_SYNCHRO_DEFER_SYNCHRONIZE(LOCKABLE) \
+ BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR(_, LOCKABLE)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE(LOCKABLE) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR(_, LOCKABLE)
+#define BOOST_SYNCHRO_SYNCHRONIZE_UNTIL(LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL(_, LOCKABLE, ABS_TIME)
+#define BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_UNTIL(LOCKABLE, ABS_TIME) \
+ BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL(_, LOCKABLE, ABS_TIME)
+
+#define synchronize(LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE(LOCKABLE)
+#define adopt_synchronize(LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE(LOCKABLE)
+#define defer_synchronize(LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE(LOCKABLE)
+#define try_to_synchronize(LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE(LOCKABLE)
+#define try_to_synchronize_until(LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_UNTIL(LOCKABLE, ABS_TIME)
+#define synchronize_until(LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_UNTIL(LOCKABLE, ABS_TIME)
+
+#define synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE_VAR(VAR, LOCKABLE)
+#define adopt_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR(VAR, LOCKABLE)
+#define defer_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR(VAR, LOCKABLE)
+#define try_to_synchronize_var(VAR, LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR(VAR, LOCKABLE)
+#define try_to_synchronize_var_until(VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL(VAR, LOCKABLE, ABS_TIME)
+#define synchronize_var_until(VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL(VAR, ABS_TIME, LOCKABLE)
+
+#define synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_SYNCHRONIZE_TYPE(TYPE, VAR, LOCKABLE)
+#define adopt_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_ADOPT_SYNCHRONIZE_VAR(TYPE, VAR, LOCKABLE)
+#define defer_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_DEFER_SYNCHRONIZE_VAR(TYPE, VAR, LOCKABLE)
+#define try_to_synchronize_type(TYPE, VAR, LOCKABLE) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR(TYPE, VAR, LOCKABLE)
+#define try_to_synchronize_type_until(TYPE, VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_TRY_TO_SYNCHRONIZE_VAR_UNTIL(TYPE, VAR, LOCKABLE, ABS_TIME)
+#define synchronize_type_until(TYPE, VAR, LOCKABLE, ABS_TIME) BOOST_SYNCHRO_SYNCHRONIZE_VAR_UNTIL(TYPE, VAR, ABS_TIME, LOCKABLE)
+
+
+#endif
Added: sandbox/stm/branches/vbe/boost/synchro/lockable.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE__HPP
+#define BOOST_SYNCHO_LOCKABLE__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/lockable/lock.hpp>
+#include <boost/synchro/lockable/unlock.hpp>
+#include <boost/synchro/lockable/try_lock.hpp>
+#include <boost/synchro/lockable/lock_until.hpp>
+#include <boost/synchro/lockable/lock_for.hpp>
+//-----------------------------------------------------------------------------
+
+#endif // BOOST_SYNCHO_UNIQUE_LOCK__HPP
Added: sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE_LOCK_HPP
+#define BOOST_SYNCHO_LOCKABLE_LOCK_HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template< typename Lockable >
+ inline void lock(Lockable& lockable) {
+ lockable.lock();
+ }
+
+}}
+#endif // BOOST_SYNCHO_LOCKABLE_LOCK_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock_for.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE_LOCK_FOR_HPP
+#define BOOST_SYNCHO_LOCKABLE_LOCK_FOR_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/time.hpp>
+#include <boost/synchro/lockable/lock_until.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template <typename Lockable, typename TimeDuration >
+ bool lock_for(Lockable& lockable, const TimeDuration& rel_time) {
+ return lock_until(&lockable, get_system_time()+rel_time);
+ }
+
+}}
+#endif // BOOST_SYNCHO_LOCKABLE_LOCK_FOR_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/lock_until.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE_LOCK_UNTIL_HPP
+#define BOOST_SYNCHO_LOCKABLE_LOCK_UNTIL_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/time.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template< typename Lockable>
+ inline bool lock_until(Lockable& lockable, system_time const& target_time) {
+ return lockable.lock_until(target_time);
+ }
+
+}}
+#endif // BOOST_SYNCHO_LOCKABLE_LOCK_UNTIL_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/try_lock.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE_TRY_LOCK_HPP
+#define BOOST_SYNCHO_LOCKABLE_TRY_LOCK_HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template< typename Lockable >
+ inline bool try_lock(Lockable& lockable) {
+ return lockable.try_lock();
+ }
+
+}}
+#endif // BOOST_SYNCHO_TRY_LOCK_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockable/unlock.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKABLE_UNLOCK_HPP
+#define BOOST_SYNCHO_LOCKABLE_UNLOCK_HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template< typename Lockable >
+ inline void unlock(Lockable& lockable) {
+ lockable.unlock();
+ }
+
+}}
+#endif // BOOST_SYNCHO_LOCKABLE_UNLOCK_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockers/lock_guard.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,113 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKER_LOCK_GUARD_HPP
+#define BOOST_SYNCHO_LOCKER_LOCK_GUARD_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/tags.hpp>
+#include <boost/synchro/exceptions.hpp>
+#include <boost/synchro/lockable/lock.hpp>
+#include <boost/synchro/lockable/unlock.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost {
+namespace synchro {
+
+ template<typename Mutex, Mutex& m>
+ class static_lock_guard {
+ private:
+
+ explicit static_lock_guard(static_lock_guard&);
+ static_lock_guard& operator=(static_lock_guard&);
+ public:
+ static_lock_guard()
+ {
+ lock(m);
+ }
+ explicit static_lock_guard(adopt_lock_t)
+ {}
+ ~static_lock_guard() {
+ unlock(m);
+ }
+ };
+
+ template<typename Mutex>
+ class lock_guard {
+ private:
+ Mutex& m;
+
+ explicit lock_guard(lock_guard&);
+ lock_guard& operator=(lock_guard&);
+ public:
+ explicit lock_guard(Mutex& m_)
+ : m(m_)
+ {
+ lock(m);
+ }
+ lock_guard(Mutex& m_, bool cnd, adopt_lock_t)
+ : m(m_)
+ {}
+ ~lock_guard() {
+ unlock(m);
+ }
+ };
+
+ template<typename Mutex, Mutex& m>
+ class static_lock_guard_if {
+ private:
+ bool cnd_;
+
+ explicit static_lock_guard_if(static_lock_guard_if&);
+ static_lock_guard_if& operator=(static_lock_guard_if&);
+ public:
+ explicit static_lock_guard_if(bool cnd)
+ : cnd_(cnd)
+ {
+ if (cnd_) lock(m);
+ }
+ static_lock_guard_if(bool cnd,adopt_lock_t)
+ : cnd_(cnd)
+ {}
+ ~static_lock_guard_if() {
+ if (cnd_) unlock(m);
+ }
+ };
+
+ template<typename Mutex>
+ class lock_guard_if {
+ private:
+ Mutex& m;
+ bool cnd_;
+
+ explicit lock_guard_if(lock_guard_if&);
+ lock_guard_if& operator=(lock_guard_if&);
+ public:
+ lock_guard_if(Mutex& m_, bool cnd)
+ : m(m_)
+ , cnd_(cnd)
+ {
+ if (cnd_) lock(m);
+ }
+ lock_guard_if(Mutex& m_, bool cnd, adopt_lock_t)
+ : m(m_)
+ , cnd_(cnd)
+ {}
+ ~lock_guard_if() {
+ if (cnd_) unlock(m);
+ }
+ };
+
+}}
+#endif // BOOST_SYNCHO_LOCKER_LOCK_GUARD_HPP
+
Added: sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/lockers/unique_lock.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,233 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKER_UNIQUE_LOCK__HPP
+#define BOOST_SYNCHO_LOCKER_UNIQUE_LOCK__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/synchro/tags.hpp>
+#include <boost/synchro/exceptions.hpp>
+#include <boost/synchro/lockable.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost {
+namespace synchro {
+
+ template<typename Mutex>
+ class unique_lock
+ {
+ private:
+ Mutex* m;
+ bool is_locked;
+ unique_lock(unique_lock&);
+ unique_lock& operator=(unique_lock&);
+ public:
+ unique_lock():
+ m(0),is_locked(false)
+ {}
+
+ explicit unique_lock(Mutex& m_):
+ m(&m_),is_locked(false)
+ {
+ lock();
+ }
+
+ unique_lock(Mutex& m_,adopt_lock_t):
+ m(&m_),is_locked(true)
+ {}
+ unique_lock(Mutex& m_,defer_lock_t):
+ m(&m_),is_locked(false)
+ {}
+ unique_lock(Mutex& m_,try_to_lock_t):
+ m(&m_),is_locked(false)
+ {
+ try_lock();
+ }
+ template<typename TimeDuration>
+ unique_lock(Mutex& m_,TimeDuration const& target_time):
+ m(&m_),is_locked(false)
+ {
+ lock_for(target_time);
+ }
+ unique_lock(Mutex& m_,system_time const& target_time):
+ m(&m_),is_locked(false)
+ {
+ lock_until(target_time);
+ }
+#ifdef BOOST_HAS_RVALUE_REFS
+ unique_lock(unique_lock&& other):
+ m(other.m),is_locked(other.is_locked)
+ {
+ other.is_locked=false;
+ other.m=0;
+ }
+ unique_lock<Mutex>&& move()
+ {
+ return static_cast<unique_lock<Mutex>&&>(*this);
+ }
+
+
+ unique_lock& operator=(unique_lock<Mutex>&& other)
+ {
+ unique_lock temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ void swap(unique_lock&& other)
+ {
+ std::swap(m,other.m);
+ std::swap(is_locked,other.is_locked);
+ }
+#else
+#if 0
+ unique_lock(detail::thread_move_t<unique_lock<Mutex> > other):
+ m(other->m),is_locked(other->is_locked)
+ {
+ other->is_locked=false;
+ other->m=0;
+ }
+
+ operator detail::thread_move_t<unique_lock<Mutex> >()
+ {
+ return move();
+ }
+
+ detail::thread_move_t<unique_lock<Mutex> > move()
+ {
+ return detail::thread_move_t<unique_lock<Mutex> >(*this);
+ }
+
+ unique_lock& operator=(detail::thread_move_t<unique_lock<Mutex> > other)
+ {
+ unique_lock temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ void swap(detail::thread_move_t<unique_lock<Mutex> > other)
+ {
+ std::swap(m,other->m);
+ std::swap(is_locked,other->is_locked);
+ }
+#endif
+ void swap(unique_lock& other)
+ {
+ std::swap(m,other.m);
+ std::swap(is_locked,other.is_locked);
+ }
+
+#endif
+ ~unique_lock()
+ {
+ if(owns_lock())
+ {
+ synchro::unlock(*m);
+ }
+ }
+ void lock()
+ {
+ if(owns_lock())
+ {
+ throw lock_error();
+ }
+ synchro::lock(*m);
+ is_locked=true;
+ }
+ bool try_lock()
+ {
+ if(owns_lock())
+ {
+ throw lock_error();
+ }
+ is_locked=synchro::try_lock(*m);
+ return is_locked;
+ }
+ template<typename TimeDuration>
+ bool lock_for(TimeDuration const& relative_time)
+ {
+ is_locked=synchro::lock_for(*m, relative_time);
+ return is_locked;
+ }
+
+ bool lock_until(system_time const& absolute_time)
+ {
+ is_locked=synchro::lock_until(*m, absolute_time);
+ return is_locked;
+ }
+ void unlock()
+ {
+ if(!owns_lock())
+ {
+ throw lock_error();
+ }
+ synchro::unlock(*m);
+ is_locked=false;
+ }
+
+ typedef void (unique_lock::*bool_type)();
+ operator bool_type() const
+ {
+ return is_locked?&unique_lock::lock:0;
+ }
+ bool operator!() const
+ {
+ return !owns_lock();
+ }
+ bool owns_lock() const
+ {
+ return is_locked;
+ }
+
+ Mutex* mutex() const
+ {
+ return m;
+ }
+
+ Mutex* release()
+ {
+ Mutex* const res=m;
+ m=0;
+ is_locked=false;
+ return res;
+ }
+ };
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex>
+ void swap(unique_lock<Mutex>&& lhs,unique_lock<Mutex>&& rhs)
+ {
+ lhs.swap(rhs);
+ }
+#else
+ template<typename Mutex>
+ void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
+ {
+ lhs.swap(rhs);
+ }
+#endif
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex>
+ inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul)
+ {
+ return ul;
+ }
+#endif
+
+}}
+#endif // BOOST_SYNCHO_LOCKER_UNIQUE_LOCK__HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/locks.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/locks.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_LOCKS__HPP
+#define BOOST_SYNCHO_LOCKS__HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/synchro/lockers/lock_guard.hpp>
+//#include <boost/synchro/lockers/var_lock_guard.hpp>
+#include <boost/synchro/lockers/unique_lock.hpp>
+//-----------------------------------------------------------------------------
+
+#endif // BOOST_SYNCHO_UNIQUE_LOCK__HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/pthread/mutex.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,65 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_PTHREAD_MUTEX_HPP
+#define BOOST_SYNCHO_PTHREAD_MUTEX_HPP
+
+//-----------------------------------------------------------------------------
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <boost/synchro/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/synchro/exceptions.hpp>
+#include <boost/synchro/time.hpp>
+#include <boost/synchro/lockable.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ template<>
+ inline void lock<pthread_mutex_t>(pthread_mutex_t& lockable) {
+ //int const res=
+ pthread_mutex_lock(&lockable);
+ //if (res!=0) throw lock_error();
+ }
+
+ template<>
+ inline void unlock<pthread_mutex_t>(pthread_mutex_t& lockable) {
+ //int const res=
+ pthread_mutex_unlock(&lockable);
+ //if (res!=0) throw lock_error();
+ }
+
+ template<>
+ inline bool try_lock<pthread_mutex_t>(pthread_mutex_t& lockable) {
+ int const res=pthread_mutex_trylock(&lockable);
+ //BOOST_ASSERT(!res || res==EBUSY);
+ return (!res);
+ }
+
+#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
+ template<>
+ inline bool lock_until<pthread_mutex_t>(
+ pthread_mutex_t& lockable, system_time const& abs_time) {
+ struct timespec const timeout=detail::get_timespec(abs_time);
+ int const res=pthread_mutex_timedlock(&lockable,&timeout);
+ //BOOST_ASSERT(!res || res==ETIMEDOUT);
+ return !res;
+ }
+#endif
+
+
+}}
+#endif // BOOST_SYNCHO_TRY_LOCK_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/tags.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/tags.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_TAGS_HPP
+#define BOOST_SYNCHO_TAGS_HPP
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ struct defer_lock_t
+ {};
+ struct try_to_lock_t
+ {};
+ struct adopt_lock_t
+ {};
+
+ const defer_lock_t defer_lock={};
+ const try_to_lock_t try_to_lock={};
+ const adopt_lock_t adopt_lock={};
+
+}}
+#endif // BOOST_SYNCHO_TAGS_HPP
+
Added: sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/thread/mutex.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,38 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_THREAD_MUTEX_HPP
+#define BOOST_SYNCHO_THREAD_MUTEX_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/thread/mutex.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/synchro/exceptions.hpp>
+#include <boost/synchro/time.hpp>
+#include <boost/synchro/lockable.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
+ template<>
+ inline bool lock_until<boost::timed_mutex>(
+ boost::timed_mutex& lockable, system_time const& abs_time) {
+ return lockable.timed_lock(abs_time);
+ }
+#endif
+
+}}
+#endif // BOOST_SYNCHO_THREAD_MUTEX_HPP
+
+
Added: sandbox/stm/branches/vbe/boost/synchro/time.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/synchro/time.hpp 2009-10-18 06:19:05 EDT (Sun, 18 Oct 2009)
@@ -0,0 +1,39 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_SYNCHO_TIME_HPP
+#define BOOST_SYNCHO_TIME_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/thread/thread_time.hpp>
+#include <boost/thread/pthread/timespec.hpp>
+//-----------------------------------------------------------------------------
+
+namespace boost { namespace synchro {
+
+ using boost::system_time;
+
+ inline system_time get_system_time() {
+ return boost::get_system_time();
+ }
+
+ namespace detail {
+ inline struct timespec const get_timespec(system_time& t) {
+ return boost::detail::get_timespec(t);
+ }
+ }
+
+}}
+#endif // BOOST_SYNCHO_TRY_LOCK_HPP
+
+
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