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

Method init_thread

handlersocket/database.cpp:273–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271#define DENA_THR_OFFSETOF(fld) ((char *)(&thd->fld) - (char *)thd)
272
273void
274dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag)
275{
276 DBG_THR(fprintf(stderr, "HNDSOCK init thread\n"));
277 {
278 my_thread_init();
279 thd = new THD;
280 thd->thread_stack = (char *)stack_bottom;
281 DBG_THR(fprintf(stderr,
282 "thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu "
283 "O: %zu %zu %zu %zu %zu %zu %zu\n",
284 thd->thread_stack, sizeof(THD), sizeof(LOCK_thread_count),
285 DENA_THR_OFFSETOF(mdl_context),
286 DENA_THR_OFFSETOF(net),
287 DENA_THR_OFFSETOF(LOCK_thd_data),
288 DENA_THR_OFFSETOF(mysys_var),
289 DENA_THR_OFFSETOF(stmt_arena),
290 DENA_THR_OFFSETOF(limit_found_rows),
291 DENA_THR_OFFSETOF(locked_tables_list)));
292 thd->store_globals();
293 thd->system_thread = static_cast<enum_thread_type>(1<<30UL);
294 const NET v = { 0 };
295 thd->net = v;
296 if (for_write_flag) {
297 #if MYSQL_VERSION_ID >= 50505
298 thd->variables.option_bits |= OPTION_BIN_LOG;
299 #else
300 thd->options |= OPTION_BIN_LOG;
301 #endif
302 safeFree(thd->db);
303 thd->db = 0;
304 thd->db = my_strdup("handlersocket", MYF(0));
305 }
306 my_pthread_setspecific_ptr(THR_THD, thd);
307 DBG_THR(fprintf(stderr, "HNDSOCK x0 %p\n", thd));
308 }
309 {
310 pthread_mutex_lock(&LOCK_thread_count);
311 thd->thread_id = thread_id++;
312 #if MYSQL_VERSION_ID >= 50600
313 add_global_thread(thd);
314 #else
315 threads.append(thd);
316 ++thread_count;
317 #endif
318 pthread_mutex_unlock(&LOCK_thread_count);
319 }
320
321 DBG_THR(fprintf(stderr, "HNDSOCK %p init thread wsts\n", thd));
322 wait_server_to_start(thd, shutdown_flag);
323 DBG_THR(fprintf(stderr, "HNDSOCK %p init thread done\n", thd));
324
325 thd_proc_info(thd, &info_message_buf[0]);
326 set_thread_message("hs:listening");
327 DBG_THR(fprintf(stderr, "HNDSOCK x1 %p\n", thd));
328
329 lex_start(thd);
330

Callers 1

thr_initMethod · 0.80

Calls 3

wait_server_to_startFunction · 0.85
appendMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected