summaryrefslogtreecommitdiff
path: root/libodb/odb/session.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libodb/odb/session.cxx')
-rw-r--r--libodb/odb/session.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/libodb/odb/session.cxx b/libodb/odb/session.cxx
new file mode 100644
index 0000000..bc0e854
--- /dev/null
+++ b/libodb/odb/session.cxx
@@ -0,0 +1,66 @@
+// file : odb/session.cxx
+// 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 (bool make_current)
+ {
+ if (make_current)
+ {
+ if (has_current ())
+ throw already_in_session ();
+
+ current_pointer (this);
+ }
+ }
+
+ session::
+ ~session ()
+ {
+ // If we are the current thread's session, reset it.
+ //
+ if (current_pointer () == this)
+ reset_current ();
+ }
+
+ session* session::
+ current_pointer ()
+ {
+ return tls_get (current_session);
+ }
+
+ void session::
+ current_pointer (session* s)
+ {
+ tls_set (current_session, s);
+ }
+
+ session& session::
+ current ()
+ {
+ session* cur (tls_get (current_session));
+
+ if (cur == 0)
+ throw not_in_session ();
+
+ return *cur;
+ }
+
+ //
+ // object_map_base
+ //
+ session::object_map_base::
+ ~object_map_base ()
+ {
+ }
+}