CUBRID Engine  latest
thread_entry_task.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 
19 /*
20  * thread_entry_task.cpp - implementation of entry_task and entry_manager
21  */
22 
23 #include "thread_entry_task.hpp"
24 
25 #include "error_manager.h"
26 #include "log_impl.h"
27 #include "porting.h"
28 #include "thread_entry.hpp"
29 #include "thread_manager.hpp"
30 
31 #include <cstring>
32 
33 namespace cubthread
34 {
35 
36  entry &
38  {
39  entry &context = *get_manager ()->claim_entry ();
40 
41  // for backward compatibility
42  context.register_id ();
43  context.type = TT_WORKER;
44 #if defined (SERVER_MODE)
46  context.shutdown = false;
47 #endif // SERVER_MODE
48 
50 
51  on_create (context);
52  return context;
53  }
54 
55  void
57  {
58  on_retire (context);
59 
60  // clear error messages
62 
63  context.end_resource_tracks ();
64 
65  // todo: here we should do more operations to clear thread entry before being reused
66  context.unregister_id ();
67  context.tran_index = NULL_TRAN_INDEX;
68  context.check_interrupt = true;
69  context.private_lru_index = -1;
70 #if defined (SERVER_MODE)
73 #endif // SERVER_MODE
74 
75  get_manager ()->retire_entry (context);
76  }
77 
78  void
80  {
81  er_clear (); // clear errors
82  context.end_resource_tracks ();
83  std::memset (&context.event_stats, 0, sizeof (context.event_stats)); // clear even stats
84  context.tran_index = NULL_TRAN_INDEX; // clear transaction ID
85  context.private_lru_index = -1;
86 #if defined (SERVER_MODE)
88  context.shutdown = false;
89 #endif // SERVER_MODE
90 
91  on_recycle (context);
92  }
93 
94  void
96  {
97  context.shutdown = true;
98  }
99 
100  void
102  {
103  context.type = TT_DAEMON;
105 
106  on_daemon_create (context);
107  }
108 
109  void
111  {
112 #if defined (SERVER_MODE)
114 #endif // SERVER_MODE
115 
116  context.unregister_id (); // unregister thread ID
117 
118  on_daemon_retire (context);
119  }
120 
121 } // namespace cubthread
void stop_execution(entry &context) override
EVENT_STAT event_stats
void recycle_context(entry &context) final
const int LOG_SYSTEM_TRAN_INDEX
void retire_context(entry &context) final
std::atomic_bool shutdown
thread_resume_suspend_status resume_status
void register_thread_local(void)
thread_type type
manager * get_manager(void)
virtual void on_retire(context_type &)
cuberr::context & get_error_context(void)
void on_retire(entry &) final
virtual void on_recycle(context_type &)
#define NULL_TRAN_INDEX
void deregister_thread_local(void)
void on_create(entry &) final
void end_resource_tracks(void)
void er_clear(void)
entry * claim_entry(void)
void retire_entry(entry &entry_p)
entry & create_context(void) final
virtual void on_create(context_type &)