aboutsummaryrefslogtreecommitdiff
path: root/odb/session.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/session.cxx')
-rw-r--r--odb/session.cxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/odb/session.cxx b/odb/session.cxx
new file mode 100644
index 0000000..b34c1d7
--- /dev/null
+++ b/odb/session.cxx
@@ -0,0 +1,72 @@
+// file : odb/session.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/exceptions.hxx>
+#include <odb/session.hxx>
+
+#include <odb/details/tls.hxx>
+
+namespace odb
+{
+ using namespace details;
+
+ static ODB_TLS_POINTER (session) current_session;
+
+ session::
+ session ()
+ {
+ if (has_current ())
+ throw already_in_session ();
+
+ current (*this);
+ }
+
+ session::
+ ~session ()
+ {
+ // If we are the current thread's session, reset it.
+ //
+ if (has_current () && &current () == this)
+ reset_current ();
+ }
+
+ bool session::
+ has_current ()
+ {
+ return tls_get (current_session) != 0;
+ }
+
+ session& session::
+ current ()
+ {
+ session* cur (tls_get (current_session));
+
+ if (cur == 0)
+ throw not_in_session ();
+
+ return *cur;
+ }
+
+ void session::
+ current (session& s)
+ {
+ tls_set (current_session, &s);
+ }
+
+ void session::
+ reset_current ()
+ {
+ session* s (0);
+ tls_set (current_session, s);
+ }
+
+ //
+ // object_map_base
+ //
+ session::object_map_base::
+ ~object_map_base ()
+ {
+ }
+}