mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / sql / scheduler.cc
blobc135c6ca1d54f54c5c4b0a69bff99a1cb1aafdfb
1 /* Copyright (C) 2007 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17 Implementation for the thread scheduler
20 #ifdef USE_PRAGMA_INTERFACE
21 #pragma implementation
22 #endif
24 #include <mysql_priv.h>
27 'Dummy' functions to be used when we don't need any handling for a scheduler
28 event
31 static bool init_dummy(void) {return 0;}
32 static void post_kill_dummy(THD* thd) {}
33 static void end_dummy(void) {}
34 static bool end_thread_dummy(THD *thd, bool cache_thread) { return 0; }
37 Initialize default scheduler with dummy functions so that setup functions
38 only need to declare those that are relvant for their usage
41 scheduler_functions::scheduler_functions()
42 :init(init_dummy),
43 init_new_connection_thread(init_new_connection_handler_thread),
44 add_connection(0), // Must be defined
45 post_kill_notification(post_kill_dummy),
46 end_thread(end_thread_dummy), end(end_dummy)
51 End connection, in case when we are using 'no-threads'
54 static bool no_threads_end(THD *thd, bool put_in_cache)
56 unlink_thd(thd);
57 pthread_mutex_unlock(&LOCK_thread_count);
58 return 1; // Abort handle_one_connection
63 Initailize scheduler for --thread-handling=no-threads
66 void one_thread_scheduler(scheduler_functions* func)
68 func->max_threads= 1;
69 #ifndef EMBEDDED_LIBRARY
70 func->add_connection= handle_connection_in_main_thread;
71 #endif
72 func->init_new_connection_thread= init_dummy;
73 func->end_thread= no_threads_end;
78 Initialize scheduler for --thread-handling=one-thread-per-connection
81 #ifndef EMBEDDED_LIBRARY
82 void one_thread_per_connection_scheduler(scheduler_functions* func)
84 func->max_threads= max_connections;
85 func->add_connection= create_thread_to_handle_connection;
86 func->end_thread= one_thread_per_connection_end;
88 #endif /* EMBEDDED_LIBRARY */