diff options
author | andrey@lmy004. <> | 2006-07-13 10:59:58 +0200 |
---|---|---|
committer | andrey@lmy004. <> | 2006-07-13 10:59:58 +0200 |
commit | dd31d457898e129a9f22363741101780e028038f (patch) | |
tree | fb7407480fd7ae1b764e1bf59ec33047559bf6dd /sql/event_scheduler.cc | |
parent | 3f4e1f5c695215cd18222c359fa56eea4ab63664 (diff) | |
download | mariadb-git-dd31d457898e129a9f22363741101780e028038f.tar.gz |
WL #3337 (Events new architecture)
Final stroke, events should be loaded from disk on server startup.
Also check the validity of their bodies if possible during loading.
Diffstat (limited to 'sql/event_scheduler.cc')
-rw-r--r-- | sql/event_scheduler.cc | 114 |
1 files changed, 59 insertions, 55 deletions
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 85d357ec11e..5e6ffb090cb 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -40,9 +40,6 @@ struct scheduler_param Event_scheduler *scheduler; }; -struct scheduler_param scheduler_param_value; - - static LEX_STRING scheduler_states_names[] = @@ -103,25 +100,23 @@ evex_print_warnings(THD *thd, Event_job_data *et) /* - Inits an scheduler thread handler, both the main and a worker + Performs pre- pthread_create() initialisation of THD. Do this + in the thread that will pass THD to the child thread. In the + child thread call post_init_event_thread(). SYNOPSIS - init_event_thread() - thd - the THD of the thread. Has to be allocated by the caller. + pre_init_event_thread() + thd The THD of the thread. Has to be allocated by the caller. NOTES 1. The host of the thead is my_localhost 2. thd->net is initted with NULL - no communication. - - RETURN VALUE - 0 OK - -1 Error */ -static int -init_scheduler_thread(THD* thd) +void +pre_init_event_thread(THD* thd) { - DBUG_ENTER("init_event_thread"); + DBUG_ENTER("pre_init_event_thread"); thd->client_capabilities= 0; thd->security_ctx->master_access= 0; thd->security_ctx->db_access= 0; @@ -148,7 +143,36 @@ init_scheduler_thread(THD* thd) thd->version= refresh_version; thd->set_time(); - DBUG_RETURN(0); + DBUG_VOID_RETURN; +} + + +/* + Performs post initialization of structures in a new thread. + + SYNOPSIS + post_init_event_thread() + thd Thread +*/ + +bool +post_init_event_thread(THD *thd) +{ + my_thread_init(); + pthread_detach_this_thread(); + thd->real_id= pthread_self(); + if (init_thr_lock() || thd->store_globals()) + { + thd->cleanup(); + return TRUE; + } + +#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) + sigset_t set; + VOID(sigemptyset(&set)); // Get mask in use + VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals)); +#endif + return FALSE; } @@ -160,7 +184,7 @@ init_scheduler_thread(THD* thd) thd Thread */ -static void +void deinit_event_thread(THD *thd) { thd->proc_info= "Clearing"; @@ -192,29 +216,18 @@ pthread_handler_t event_scheduler_thread(void *arg) { /* needs to be first for thread_stack */ - THD *thd= (THD *)(*(struct scheduler_param *) arg).thd; + THD *thd= (THD *)((struct scheduler_param *) arg)->thd; + Event_scheduler *scheduler= ((struct scheduler_param *) arg)->scheduler; - thd->thread_stack= (char *)&thd; // remember where our stack is - DBUG_ENTER("event_scheduler_thread"); + my_free((char*)arg, MYF(0)); - my_thread_init(); - pthread_detach_this_thread(); - thd->real_id=pthread_self(); - if (init_thr_lock() || thd->store_globals()) - { - thd->cleanup(); - goto end; - } + thd->thread_stack= (char *)&thd; // remember where our stack is -#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) - sigset_t set; - VOID(sigemptyset(&set)); // Get mask in use - VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals)); -#endif + DBUG_ENTER("event_scheduler_thread"); - ((struct scheduler_param *) arg)->scheduler->run(thd); + if (!post_init_event_thread(thd)) + scheduler->run(thd); -end: deinit_event_thread(thd); DBUG_RETURN(0); // Against gcc warnings @@ -242,27 +255,13 @@ event_worker_thread(void *arg) int ret; thd= event->thd; - thd->thread_stack= (char *) &thd; + thd->thread_stack= (char *) &thd; // remember where our stack is + DBUG_ENTER("event_worker_thread"); - my_thread_init(); - pthread_detach_this_thread(); - thd->real_id=pthread_self(); - if (init_thr_lock() || thd->store_globals()) - { - thd->cleanup(); + if (post_init_event_thread(thd)) goto end; - } - -#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__) - sigset_t set; - VOID(sigemptyset(&set)); // Get mask in use - VOID(pthread_sigmask(SIG_UNBLOCK, &set, &thd->block_signals)); -#endif - thd->init_for_queries(); - - DBUG_ENTER("event_worker_thread"); DBUG_PRINT("info", ("Baikonur, time is %d, BURAN reporting and operational." "THD=0x%lx", time(NULL), thd)); @@ -375,6 +374,7 @@ Event_scheduler::start() THD *new_thd= NULL; bool ret= FALSE; pthread_t th; + struct scheduler_param *scheduler_param_value; DBUG_ENTER("Event_scheduler::start"); LOCK_SCHEDULER_DATA(); @@ -382,21 +382,24 @@ Event_scheduler::start() if (state > INITIALIZED) goto end; - if (!(new_thd= new THD) || init_scheduler_thread(new_thd)) + if (!(new_thd= new THD)) { sql_print_error("SCHEDULER: Cannot init manager event thread."); ret= TRUE; goto end; } + pre_init_event_thread(new_thd); new_thd->system_thread= SYSTEM_THREAD_EVENT_SCHEDULER; new_thd->command= COM_DAEMON; - scheduler_param_value.thd= new_thd; - scheduler_param_value.scheduler= this; + scheduler_param_value= + (struct scheduler_param *)my_malloc(sizeof(struct scheduler_param), MYF(0)); + scheduler_param_value->thd= new_thd; + scheduler_param_value->scheduler= this; DBUG_PRINT("info", ("Forking new thread for scheduduler. THD=0x%lx", new_thd)); if (pthread_create(&th, &connection_attrib, event_scheduler_thread, - (void*)&scheduler_param_value)) + (void*)scheduler_param_value)) { DBUG_PRINT("error", ("cannot create a new thread")); state= INITIALIZED; @@ -588,9 +591,10 @@ Event_scheduler::execute_top(THD *thd, Event_job_data *job_data) pthread_t th; int res= 0; DBUG_ENTER("Event_scheduler::execute_top"); - if (!(new_thd= new THD) || init_scheduler_thread(new_thd)) + if (!(new_thd= new THD)) goto error; + pre_init_event_thread(new_thd); new_thd->system_thread= SYSTEM_THREAD_EVENT_WORKER; job_data->thd= new_thd; DBUG_PRINT("info", ("BURAN %s@%s ready for start t-3..2..1..0..ignition", |