CUBRID Engine  latest
critical_section_tracker.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 /*
20  * critical_section_tracker.hpp - interface to track and debug critical sections usage
21  */
22 
23 #ifndef _CRITICAL_SECTION_TRACKER_HPP_
24 #define _CRITICAL_SECTION_TRACKER_HPP_
25 
26 #include "critical_section.h"
27 
28 #include <cstdint>
29 
30 namespace cubsync
31 {
33  {
34  public:
35 
36  critical_section_tracker (bool enable = false);
37 
38  static const std::size_t MAX_REENTERS = 8; // how many re-enters do we allow?
39 
40  void start (void);
41  void stop (void);
42  void clear_all (void);
43 
44  void on_enter_as_reader (int cs_index);
45  void on_enter_as_writer (int cs_index);
46  void on_promote (int cs_index);
47  void on_demote (int cs_index);
48  void on_exit (int cs_index);
49 
50  private:
51 
53  {
54  std::uint8_t m_enter_count;
57 
58  cstrack_entry ();
59  };
60 
61  bool is_started (void);
62  void check (void);
63  void check_csect_interdependencies (int cs_index);
64 
66  bool m_enabled;
67  std::uint8_t m_start_count;
68  };
69 
70 } // namespace cubsync
71 
72 #endif // _CRITICAL_SECTION_TRACKER_HPP_
bool m_is_demoted
cstrack_entry()
bool m_is_writer
static const int CRITICAL_SECTION_COUNT
cstrack_entry m_cstrack_array[CRITICAL_SECTION_COUNT]
std::uint8_t m_enter_count