MCPcopy Create free account
hub / github.com/DeNA/HandlerSocket-Plugin-for-MySQL / thread_base

Class thread_base

client/hslongrun.cpp:108–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106};
107
108struct thread_base {
109 thread_base() : need_join(false), stack_size(256 * 1024) { }
110 virtual ~thread_base() {
111 join();
112 }
113 virtual void run() = 0;
114 void start() {
115 if (!start_nothrow()) {
116 fatal_abort("thread::start");
117 }
118 }
119 bool start_nothrow() {
120 if (need_join) {
121 return need_join; /* true */
122 }
123 void *const arg = this;
124 pthread_attr_t attr;
125 if (pthread_attr_init(&attr) != 0) {
126 fatal_abort("pthread_attr_init");
127 }
128 if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
129 fatal_abort("pthread_attr_setstacksize");
130 }
131 const int r = pthread_create(&thr, &attr, thread_main, arg);
132 if (pthread_attr_destroy(&attr) != 0) {
133 fatal_abort("pthread_attr_destroy");
134 }
135 if (r != 0) {
136 return need_join; /* false */
137 }
138 need_join = true;
139 return need_join; /* true */
140 }
141 void join() {
142 if (!need_join) {
143 return;
144 }
145 int e = 0;
146 if ((e = pthread_join(thr, 0)) != 0) {
147 fatal_abort("pthread_join");
148 }
149 need_join = false;
150 }
151 private:
152 static void *thread_main(void *arg) {
153 thread_base *p = static_cast<thread_base *>(arg);
154 p->run();
155 return 0;
156 }
157 private:
158 pthread_t thr;
159 bool need_join;
160 size_t stack_size;
161};
162
163struct hs_longrun_stat {
164 unsigned long long verify_error_count;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected