CUBRID Engine  latest
lockfree_transaction_descriptor.hpp
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 
19 #ifndef _LOCKFREE_TRANSACTION_DESCRIPTOR_HPP_
20 #define _LOCKFREE_TRANSACTION_DESCRIPTOR_HPP_
21 
22 //
23 // lock-free transaction descriptor
24 //
25 // Monitors the activity of a thread on a lock-free data structure and manages retired nodes that are not yet ready
26 // to be deleted.
27 //
28 // See lockfree_transaction_system.hpp description for an overview of the lock-free transaction implementation.
29 //
30 
32 
33 #include <limits>
34 
35 // forward definition
36 namespace lockfree
37 {
38  namespace tran
39  {
40  class reclaimable_node;
41  class table;
42  } // namespace tran
43 } // namespace lockfree
44 
45 namespace lockfree
46 {
47  namespace tran
48  {
50 
51  class descriptor
52  {
53  public:
54  descriptor ();
55  ~descriptor ();
56 
57  // retire a lock-free data structure node
58  // !! NOTE: it is callers responsibility to make sure no new thread can access the node once retired.
59  // transaction system can only safe-guard against concurrent access that started prior retirement.
60  void retire_node (reclaimable_node &hzp);
61 
62  void set_table (table &tbl);
63 
64  void start_tran ();
65  void start_tran_and_increment_id ();
66  void end_tran ();
67 
68  bool is_tran_started () const;
69 
70  id get_transaction_id () const;
71 
72  void reclaim_retired_list ();
73 
74  // a reclaimable node may be saved for later use; must not have been part of lock-free structure
75  void save_reclaimable (reclaimable_node *&node);
76  reclaimable_node *pull_saved_reclaimable ();
77 
78  size_t get_total_retire_count () const;
79  size_t get_total_reclaim_count () const;
80  size_t get_current_retire_count () const;
81 
82  private:
83  void reclaim_retired_head ();
84 
90  bool m_did_incr;
91 
93 
94  // stats
97  };
98  } // namespace tran
99 } // namespace lockfree
100 
101 #endif // !_LOCKFREE_TRANSACTION_DESCRIPTOR_HPP_
#define max(a, b)