|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59760 - sandbox/transaction/boost/transact
From: strasser_at_[hidden]
Date: 2010-02-19 10:01:51
Author: stefans
Date: 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
New Revision: 59760
URL: http://svn.boost.org/trac/boost/changeset/59760
Log:
new macro syntax
Added:
sandbox/transaction/boost/transact/language.hpp (contents, props changed)
Removed:
sandbox/transaction/boost/transact/atomic.hpp
sandbox/transaction/boost/transact/basic_atomic.hpp
Text files modified:
sandbox/transaction/boost/transact/basic_transaction.hpp | 66 ++++++++++++++++++++++++++++++++++++++++
sandbox/transaction/boost/transact/transaction.hpp | 17 ++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
Deleted: sandbox/transaction/boost/transact/atomic.hpp
==============================================================================
--- sandbox/transaction/boost/transact/atomic.hpp 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
+++ (empty file)
@@ -1,16 +0,0 @@
-#ifndef BOOST_TRANSACT_ATOMIC_HPP
-#define BOOST_TRANSACT_ATOMIC_HPP
-
-#include <boost/transact/basic_atomic.hpp>
-#include <boost/transact/transaction_manager.hpp>
-
-/// \brief An alias of BOOST_TRANSACT_BASIC_ATOMIC using the default transaction manager
-#define BOOST_TRANSACT_ATOMIC \
- BOOST_TRANSACT_BASIC_ATOMIC(boost::transact::transaction_manager)
-
-/// \brief An alias of BOOST_TRANSACT_BASIC_COMMIT using the default transaction manager
-#define BOOST_TRANSACT_COMMIT() \
- BOOST_TRANSACT_BASIC_COMMIT(boost::transact::transaction_manager)
-
-
-#endif
Deleted: sandbox/transaction/boost/transact/basic_atomic.hpp
==============================================================================
--- sandbox/transaction/boost/transact/basic_atomic.hpp 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
+++ (empty file)
@@ -1,49 +0,0 @@
-#include <boost/transact/basic_transaction.hpp>
-
-#ifndef BOOST_TRANSACT_BASIC_ATOMIC_HPP
-#define BOOST_TRANSACT_BASIC_ATOMIC_HPP
-
-/// \brief Begins a new transaction scope.
-///
-/// BOOST_TRANSACT_BASIC_ATOMIC and BOOST_TRANSACT_BASIC_COMMIT provide a simple syntax for
-/// concurrent transactions.
-///
-/// When used together the macros
-/// expand to a transaction scope that gets repeatedly executed until the transaction
-/// is successfully committed without conflicting with another transaction.
-///
-/// Example: \code
-/// #define atomic BOOST_TRANSACT_ATOMIC
-/// #define commit BOOST_TRANSACT_COMMIT
-///
-/// do atomic{
-/// ...
-/// }commit();
-/// \endcode expands to code equivalent to \code
-/// do{
-/// try{
-/// transaction tx;
-/// ...
-/// tx.commit();
-/// }catch(isolation_exception &i){
-/// i.unwind<transaction_manager>();
-/// continue;
-/// }
-/// }while(false); \endcode
-#define BOOST_TRANSACT_BASIC_ATOMIC(TXMGR) \
- { \
- try{ \
- boost::transact::basic_transaction<TXMGR> ___tx;
-
-/// Ends a transaction scope.
-/// See BOOST_TRANSACT_BASIC_ATOMIC for a detailed description.
-#define BOOST_TRANSACT_BASIC_COMMIT(TXMGR) \
- } \
- ___tx.commit_(); \
- }catch(boost::transact::isolation_exception &i){ \
- i.unwind<TXMGR>(); \
- continue; \
- } \
- }while(false);
-
-#endif
Modified: sandbox/transaction/boost/transact/basic_transaction.hpp
==============================================================================
--- sandbox/transaction/boost/transact/basic_transaction.hpp (original)
+++ sandbox/transaction/boost/transact/basic_transaction.hpp 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
@@ -8,6 +8,8 @@
#define BOOST_TRANSACT_BASIC_TRANSACTION_HEADER_HPP
#include <boost/noncopyable.hpp>
+#include <boost/transact/exception.hpp>
+#include <boost/assert.hpp>
namespace boost{
namespace transact{
@@ -128,10 +130,74 @@
};
+namespace detail{
+
+template<class TxMgr>
+struct commit_on_destruction{
+ explicit commit_on_destruction(basic_transaction<TxMgr> &tx)
+ : tx(&tx){}
+ ~commit_on_destruction(){
+ if(this->tx) this->tx->commit();
+ }
+ void nullify(){
+ this->tx=0;
+ }
+private:
+ basic_transaction<TxMgr> *tx;
+};
+
+}
+
}
}
+#define BOOST_TRANSACT_BASIC_BEGIN_TRANSACTION(TXMGR) \
+ { \
+ int ___control; \
+ while(true){ \
+ try{ \
+ boost::transact::basic_transaction<TXMGR> ___tx; \
+ boost::transact::detail::commit_on_destruction<TXMGR> ___commit(___tx); \
+ try{ \
+ do{ \
+ ___control=1;
+
+#define BOOST_TRANSACT_BASIC_RETRY(TXMGR) \
+ ___control=0; \
+ break; \
+ }while((___control=2),false); \
+ }catch(...){ \
+ ___commit.nullify(); \
+ throw; \
+ } \
+ break; \
+ }catch(boost::transact::isolation_exception &___i){ \
+ ___i.unwind<TXMGR>(); \
+ ___control=0;
+
+#define BOOST_TRANSACT_BASIC_END_RETRY(TXMGR) \
+ } \
+ }; \
+ BOOST_ASSERT(___control == 0); \
+ }void()
+
+#define BOOST_TRANSACT_BASIC_END_RETRY_IN_LOOP(TXMGR) \
+ } \
+ }; \
+ if(___control > 0){ \
+ if(___control==1) break; \
+ else continue; \
+ } \
+ }void()
+
+#define BOOST_TRANSACT_BASIC_END_TRANSACTION(TXMGR) \
+ BOOST_TRANSACT_BASIC_RETRY(TXMGR){} \
+ BOOST_TRANSACT_BASIC_END_RETRY(TXMGR)
+
+#define BOOST_TRANSACT_BASIC_END_TRANSACTION_IN_LOOP(TXMGR) \
+ BOOST_TRANSACT_BASIC_RETRY(TXMGR){} \
+ BOOST_TRANSACT_BASIC_END_RETRY_IN_LOOP(TXMGR)
Added: sandbox/transaction/boost/transact/language.hpp
==============================================================================
--- (empty file)
+++ sandbox/transaction/boost/transact/language.hpp 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
@@ -0,0 +1,19 @@
+// Copyright Stefan Strasser 2010.
+// 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)
+
+
+#ifndef BOOST_TRANSACT_LANGUAGE_HPP
+#define BOOST_TRANSACT_LANGUAGE_HPP
+
+#include <boost/transact/transaction.hpp>
+
+#define begin_transaction BOOST_TRANSACT_BEGIN_TRANSACTION
+#define retry BOOST_TRANSACT_RETRY
+#define end_retry BOOST_TRANSACT_END_RETRY
+#define end_retry_in_loop BOOST_TRANSACT_END_RETRY_IN_LOOP
+#define end_transaction BOOST_TRANSACT_END_TRANSACTION
+#define end_transaction_in_loop BOOST_TRANSACT_END_TRANSACTION_IN_LOOP
+
+#endif
Modified: sandbox/transaction/boost/transact/transaction.hpp
==============================================================================
--- sandbox/transaction/boost/transact/transaction.hpp (original)
+++ sandbox/transaction/boost/transact/transaction.hpp 2010-02-19 10:01:50 EST (Fri, 19 Feb 2010)
@@ -21,5 +21,22 @@
}
}
+#define BOOST_TRANSACT_BEGIN_TRANSACTION \
+ BOOST_TRANSACT_BASIC_BEGIN_TRANSACTION(boost::transact::transaction_manager)
+
+#define BOOST_TRANSACT_RETRY \
+ BOOST_TRANSACT_BASIC_RETRY(boost::transact::transaction_manager)
+
+#define BOOST_TRANSACT_END_RETRY \
+ BOOST_TRANSACT_BASIC_END_RETRY(boost::transact::transaction_manager)
+
+#define BOOST_TRANSACT_END_RETRY_IN_LOOP \
+ BOOST_TRANSACT_BASIC_END_RETRY_IN_LOOP(boost::transact::transaction_manager)
+
+#define BOOST_TRANSACT_END_TRANSACTION \
+ BOOST_TRANSACT_BASIC_END_TRANSACTION(boost::transact::transaction_manager)
+
+#define BOOST_TRANSACT_END_TRANSACTION_IN_LOOP \
+ BOOST_TRANSACT_BASIC_END_TRANSACTION_IN_LOOP(boost::transact::transaction_manager)
#endif
\ No newline at end of file
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