CUBRID Engine  latest
lockfree_transaction_descriptor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
23 
24 #include <cassert>
25 
26 namespace lockfree
27 {
28  namespace tran
29  {
31  : m_table (NULL)
32  , m_tranid (INVALID_TRANID)
33  , m_last_reclaim_minid (0)
34  , m_retired_head (NULL)
35  , m_retired_tail (NULL)
36  , m_did_incr (false)
37  , m_saved_node (NULL)
38  , m_retire_count (0)
39  , m_reclaim_count (0)
40  {
41  }
42 
44  {
45  assert (!is_tran_started ());
46  while (m_retired_head != NULL)
47  {
49  }
50  if (m_saved_node != NULL)
51  {
53  }
54  }
55 
56  void
58  {
59  m_table = &tbl;
60  }
61 
62  void
64  {
65  bool should_end = !is_tran_started ();
67 
69 
71  node.m_retired_next = NULL;
72  // add to tail to keep delete ids ordered
73  if (m_retired_tail == NULL)
74  {
77  }
78  else
79  {
81  m_retired_tail = &node;
82  }
84 
85  if (should_end)
86  {
87  end_tran ();
88  }
89  }
90 
91  void
93  {
94  if (!is_tran_started ())
95  {
97  }
98  }
99 
100  void
102  {
103  if (!m_did_incr)
104  {
106  }
108  }
109 
110  bool
112  {
113  return m_tranid != INVALID_TRANID;
114  }
115 
116  void
118  {
119  assert (is_tran_started ());
121  m_did_incr = false;
122  }
123 
124  id
126  {
127  return m_tranid;
128  }
129 
130  void
132  {
133  id min_tran_id = m_table->get_min_active_tranid ();
134  if (min_tran_id <= m_last_reclaim_minid)
135  {
136  // nothing changed
137  return;
138  }
139  while (m_retired_head != NULL && m_retired_head->m_retire_tranid < min_tran_id)
140  {
142  }
143  if (m_retired_head == NULL)
144  {
146  }
147 
148  m_last_reclaim_minid = min_tran_id;
149  }
150 
151  void
153  {
157  if (m_retired_head == NULL)
158  {
160  }
161 
162  nodep->m_retired_next = NULL;
163  nodep->reclaim ();
164  ++m_reclaim_count;
165  }
166 
167  void
169  {
170  assert (m_saved_node == NULL);
171  m_saved_node = node;
172  node = NULL;
173  }
174 
177  {
179  m_saved_node = NULL;
180  return ret;
181  }
182 
183  size_t
185  {
186  return m_retire_count;
187  }
188 
189  size_t
191  {
192  return m_reclaim_count;
193  }
194 
195  size_t
197  {
199  }
200  } // namespace tran
201 } // namespace lockfree
#define assert(x)
#define NULL
Definition: freelistheap.h:34
void save_reclaimable(reclaimable_node *&node)