My Project
scheduler.h
00001 #ifndef SCHEDULER_INCLUDED
00002 #define SCHEDULER_INCLUDED
00003 
00004 /* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; version 2 of the License.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00018 
00019 /*
00020   Classes for the thread scheduler
00021 */
00022 
00023 class THD;
00024 
00025 /* Functions used when manipulating threads */
00026 
00027 struct scheduler_functions
00028 {
00029   uint max_threads;
00030   bool (*init)(void);
00031   bool (*init_new_connection_thread)(void);
00032   void (*add_connection)(THD *thd);
00033   void (*thd_wait_begin)(THD *thd, int wait_type);
00034   void (*thd_wait_end)(THD *thd);
00035   void (*post_kill_notification)(THD *thd);
00036   bool (*end_thread)(THD *thd, bool cache_thread);
00037   void (*end)(void);
00038 };
00039 
00040 
00054 enum scheduler_types
00055 {
00056   /*
00057     The default of --thread-handling is the first one in the
00058     thread_handling_names array, this array has to be consistent with
00059     the order in this array, so to change default one has to change
00060     the first entry in this enum and the first entry in the
00061     thread_handling_names array.
00062   */
00063   SCHEDULER_ONE_THREAD_PER_CONNECTION=0,
00064   SCHEDULER_NO_THREADS,
00065   SCHEDULER_TYPES_COUNT
00066 };
00067 
00068 void one_thread_per_connection_scheduler();
00069 void one_thread_scheduler();
00070 
00071 /*
00072  To be used for pool-of-threads (implemeneted differently on various OSs)
00073 */
00074 class thd_scheduler
00075 {
00076 public:
00077   /*
00078     Thread instrumentation for the user job.
00079     This member holds the instrumentation while the user job is not run
00080     by a thread.
00081 
00082     Note that this member is not conditionally declared
00083     (ifdef HAVE_PSI_INTERFACE), because doing so will change the binary
00084     layout of THD, which is exposed to plugin code that may be compiled
00085     differently.
00086   */
00087   PSI_thread *m_psi;
00088 
00089   void *data;                  /* scheduler-specific data structure */
00090 
00091   thd_scheduler();
00092   ~thd_scheduler();
00093 };
00094 
00095 void *thd_get_scheduler_data(THD *thd);
00096 void thd_set_scheduler_data(THD *thd, void *data);
00097 PSI_thread* thd_get_psi(THD *thd);
00098 void thd_set_psi(THD *thd, PSI_thread *psi);
00099 
00100 extern scheduler_functions *thread_scheduler;
00101 
00102 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines