aboutsummaryrefslogtreecommitdiff
path: root/odb/session.cxx
blob: d8f03d3d51a8a3ffe5b502190e79bccc41f2ccc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// file      : odb/session.cxx
// copyright : Copyright (c) 2009-2019 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 (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 ()
  {
  }
}