aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-18 17:52:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-18 17:52:02 +0200
commit854af2dbb1ee01f6e1c8d4f8f513ff2bad7da4f0 (patch)
tree3f21689909fe2edbfffc89b877789ada170d5a78
parentacb656e605d91971ee4014da66be1b7ba6201ac3 (diff)
Use TLS to store current transaction
-rw-r--r--odb/transaction.cxx20
1 files changed, 13 insertions, 7 deletions
diff --git a/odb/transaction.cxx b/odb/transaction.cxx
index df155ad..4fc730a 100644
--- a/odb/transaction.cxx
+++ b/odb/transaction.cxx
@@ -6,19 +6,23 @@
#include <odb/exceptions.hxx>
#include <odb/transaction.hxx>
+#include <odb/details/tls.hxx>
+
namespace odb
{
+ using namespace details;
+
//
// transaction
//
- static transaction* current_transaction = 0;
+ static ODB_TLS_POINTER (transaction) current_transaction;
transaction::
transaction (transaction_impl* impl)
: finilized_ (false), impl_ (impl)
{
- current_transaction = this;
+ tls_set (current_transaction, this);
}
transaction::
@@ -42,16 +46,18 @@ namespace odb
bool transaction::
has_current ()
{
- return current_transaction != 0;
+ return tls_get (current_transaction) != 0;
}
transaction& transaction::
current ()
{
- if (current_transaction == 0)
+ transaction* cur (tls_get (current_transaction));
+
+ if (cur == 0)
throw not_in_transaction ();
- return *current_transaction;
+ return *cur;
}
void transaction::
@@ -61,7 +67,7 @@ namespace odb
throw transaction_already_finilized ();
finilized_ = true;
- current_transaction = 0;
+ tls_set<transaction> (current_transaction, 0);
impl_->commit ();
}
@@ -72,7 +78,7 @@ namespace odb
throw transaction_already_finilized ();
finilized_ = true;
- current_transaction = 0;
+ tls_set<transaction> (current_transaction, 0);
impl_->rollback ();
}