List:Commits« Previous MessageNext Message »
From:Jonas Oreland Date:November 10 2011 8:26am
Subject:bzr push into mysql-5.1-telco-7.0 branch (jonas.oreland:4649 to 4650)
View as plain text  
 4650 Jonas Oreland	2011-11-10
      ndb - start introducing components in ndb handler
        step 1- Make util thread use initial Ndb_component base class
          This step does not in itself simplify that much
          It basically only removes a bunch of pthread_*-calls
          But it's a start

    added:
      sql/ndb_component.cc
      sql/ndb_component.h
      sql/ndb_util_thread.h
    modified:
      libmysqld/Makefile.am
      sql/Makefile.am
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/ha_ndbcluster_binlog.cc
      sql/ha_ndbcluster_binlog.h
      storage/ndb/CMakeLists.txt
 4649 Jonas Oreland	2011-11-09
      ndb - include mikaels extensions for flexAsynch...

    modified:
      storage/ndb/test/ndbapi/flexAsynch.cpp
=== modified file 'libmysqld/Makefile.am'
--- a/libmysqld/Makefile.am	2011-09-07 22:50:01 +0000
+++ b/libmysqld/Makefile.am	2011-11-10 08:16:52 +0000
@@ -49,7 +49,8 @@ sqlsources = derror.cc field.cc field_co
 	     ha_ndbcluster.cc ha_ndbcluster_cond.cc \
 	ha_ndbcluster_connection.cc ha_ndbinfo.cc \
 	ha_ndb_index_stat.cc \
-	ha_ndbcluster_binlog.cc ndb_conflict_trans.cc ha_partition.cc \
+	ha_ndbcluster_binlog.cc ndb_conflict_trans.cc ndb_component.cc \
+        ha_partition.cc \
 	handler.cc sql_handler.cc \
 	hostname.cc init.cc password.c \
 	item.cc item_buff.cc item_cmpfunc.cc item_create.cc \

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2011-09-07 22:50:01 +0000
+++ b/sql/Makefile.am	2011-11-10 08:16:52 +0000
@@ -141,7 +141,8 @@ libndb_la_SOURCES=	ha_ndbcluster.cc \
 			ha_ndb_index_stat.cc \
 			ha_ndbinfo.cc \
 			ndb_mi.cc \
-			ndb_conflict_trans.cc
+			ndb_conflict_trans.cc \
+                        ndb_component.cc
 
 gen_lex_hash_SOURCES =	gen_lex_hash.cc
 gen_lex_hash_LDFLAGS =  @NOINST_LDFLAGS@

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-10-22 09:38:48 +0000
+++ b/sql/ha_ndbcluster.cc	2011-11-10 08:16:52 +0000
@@ -46,6 +46,8 @@
 #include <ndb_version.h>
 #include "ndb_mi.h"
 #include "ndb_conflict_trans.h"
+#include "ndb_component.h"
+#include "ndb_util_thread.h"
 
 #ifdef ndb_dynamite
 #undef assert
@@ -420,14 +422,6 @@ static int ndb_get_table_statistics(THD
 
 THD *injector_thd= 0;
 
-// Util thread variables
-pthread_t ndb_util_thread;
-int ndb_util_thread_running= 0;
-pthread_mutex_t LOCK_ndb_util_thread;
-pthread_cond_t COND_ndb_util_thread;
-pthread_cond_t COND_ndb_util_ready;
-pthread_handler_t ndb_util_thread_func(void *arg);
-
 // Index stats thread variables
 pthread_t ndb_index_stat_thread;
 int ndb_index_stat_thread_running= 0;
@@ -12251,7 +12245,7 @@ ndbcluster_find_files(handlerton *hton,
 /* Call back after cluster connect */
 static int connect_callback()
 {
-  pthread_mutex_lock(&LOCK_ndb_util_thread);
+  pthread_mutex_lock(&ndb_util_thread.LOCK);
   update_status_variables(NULL, &g_ndb_status,
                           g_ndb_cluster_connection);
 
@@ -12261,8 +12255,8 @@ static int connect_callback()
   while ((node_id= g_ndb_cluster_connection->get_next_node(node_iter)))
     g_node_id_map[node_id]= i++;
 
-  pthread_cond_signal(&COND_ndb_util_thread);
-  pthread_mutex_unlock(&LOCK_ndb_util_thread);
+  pthread_cond_signal(&ndb_util_thread.COND);
+  pthread_mutex_unlock(&ndb_util_thread.LOCK);
   return 0;
 }
 
@@ -12320,13 +12314,10 @@ static int ndbcluster_init(void *p)
   assert(DependencyTracker::InvalidTransactionId ==
          Ndb_binlog_extra_row_info::InvalidTransactionId);
 #endif
+  ndb_util_thread.init();
 
   pthread_mutex_init(&ndbcluster_mutex,MY_MUTEX_INIT_FAST);
-  pthread_mutex_init(&LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST);
-  pthread_cond_init(&COND_ndb_util_thread, NULL);
-  pthread_cond_init(&COND_ndb_util_ready, NULL);
   pthread_cond_init(&COND_ndb_setup_complete, NULL);
-  ndb_util_thread_running= -1;
   pthread_mutex_init(&LOCK_ndb_index_stat_thread, MY_MUTEX_INIT_FAST);
   pthread_cond_init(&COND_ndb_index_stat_thread, NULL);
   pthread_cond_init(&COND_ndb_index_stat_ready, NULL);
@@ -12397,34 +12388,27 @@ static int ndbcluster_init(void *p)
   }
 
   // Create utility thread
-  pthread_t tmp;
-  if (pthread_create(&tmp, &connection_attrib, ndb_util_thread_func, 0))
+  if (ndb_util_thread.start())
   {
     DBUG_PRINT("error", ("Could not create ndb utility thread"));
     my_hash_free(&ndbcluster_open_tables);
     pthread_mutex_destroy(&ndbcluster_mutex);
-    pthread_mutex_destroy(&LOCK_ndb_util_thread);
-    pthread_cond_destroy(&COND_ndb_util_thread);
-    pthread_cond_destroy(&COND_ndb_util_ready);
     pthread_cond_destroy(&COND_ndb_setup_complete);
     ndbcluster_global_schema_lock_deinit();
     goto ndbcluster_init_error;
   }
 
   /* Wait for the util thread to start */
-  pthread_mutex_lock(&LOCK_ndb_util_thread);
-  while (ndb_util_thread_running < 0)
-    pthread_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread);
-  pthread_mutex_unlock(&LOCK_ndb_util_thread);
+  pthread_mutex_lock(&ndb_util_thread.LOCK);
+  while (ndb_util_thread.running < 0)
+    pthread_cond_wait(&ndb_util_thread.COND_ready, &ndb_util_thread.LOCK);
+  pthread_mutex_unlock(&ndb_util_thread.LOCK);
   
-  if (!ndb_util_thread_running)
+  if (!ndb_util_thread.running)
   {
     DBUG_PRINT("error", ("ndb utility thread exited prematurely"));
     my_hash_free(&ndbcluster_open_tables);
     pthread_mutex_destroy(&ndbcluster_mutex);
-    pthread_mutex_destroy(&LOCK_ndb_util_thread);
-    pthread_cond_destroy(&COND_ndb_util_thread);
-    pthread_cond_destroy(&COND_ndb_util_ready);
     pthread_cond_destroy(&COND_ndb_setup_complete);
     ndbcluster_global_schema_lock_deinit();
     goto ndbcluster_init_error;
@@ -12476,6 +12460,7 @@ static int ndbcluster_init(void *p)
   DBUG_RETURN(FALSE);
 
 ndbcluster_init_error:
+  ndb_util_thread.deinit();
   /* disconnect from cluster and free connection resources */
   ndbcluster_disconnect();
   ndbcluster_hton->state= SHOW_OPTION_DISABLED;               // If we couldn't use handler
@@ -12547,13 +12532,12 @@ static int ndbcluster_end(handlerton *ht
   ndb_index_stat_end();
   ndbcluster_disconnect();
 
+  ndb_util_thread.deinit();
+
   // cleanup ndb interface
   ndb_end_internal();
 
   pthread_mutex_destroy(&ndbcluster_mutex);
-  pthread_mutex_destroy(&LOCK_ndb_util_thread);
-  pthread_cond_destroy(&COND_ndb_util_thread);
-  pthread_cond_destroy(&COND_ndb_util_ready);
   pthread_cond_destroy(&COND_ndb_setup_complete);
   pthread_mutex_destroy(&LOCK_ndb_index_stat_thread);
   pthread_cond_destroy(&COND_ndb_index_stat_thread);
@@ -14776,7 +14760,26 @@ ha_ndbcluster::update_table_comment(
 /**
   Utility thread main loop.
 */
-pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
+Ndb_util_thread ndb_util_thread;
+
+Ndb_util_thread::Ndb_util_thread()
+  : running(-1)
+{
+  pthread_mutex_init(&LOCK, MY_MUTEX_INIT_FAST);
+  pthread_cond_init(&COND, NULL);
+  pthread_cond_init(&COND_ready, NULL);
+}
+
+Ndb_util_thread::~Ndb_util_thread()
+{
+  assert(running <= 0);
+  pthread_mutex_destroy(&LOCK);
+  pthread_cond_destroy(&COND);
+  pthread_cond_destroy(&COND_ready);
+}
+
+void
+Ndb_util_thread::do_run()
 {
   THD *thd; /* needs to be first for thread_stack */
   struct timespec abstime;
@@ -14784,21 +14787,18 @@ pthread_handler_t ndb_util_thread_func(v
   uint share_list_size= 0;
   NDB_SHARE **share_list= NULL;
 
-  my_thread_init();
   DBUG_ENTER("ndb_util_thread");
   DBUG_PRINT("enter", ("cache_check_time: %lu", opt_ndb_cache_check_time));
- 
-   pthread_mutex_lock(&LOCK_ndb_util_thread);
+
+  pthread_mutex_lock(&ndb_util_thread.LOCK);
 
   thd= new THD; /* note that contructor of THD uses DBUG_ */
   if (thd == NULL)
   {
     my_errno= HA_ERR_OUT_OF_MEM;
-    DBUG_RETURN(NULL);
+    DBUG_VOID_RETURN;
   }
   THD_CHECK_SENTRY(thd);
-  pthread_detach_this_thread();
-  ndb_util_thread= pthread_self();
 
   thd->thread_stack= (char*)&thd; /* remember where our stack is */
   if (thd->store_globals())
@@ -14821,9 +14821,9 @@ pthread_handler_t ndb_util_thread_func(v
   thd->update_charset();
 
   /* Signal successful initialization */
-  ndb_util_thread_running= 1;
-  pthread_cond_signal(&COND_ndb_util_ready);
-  pthread_mutex_unlock(&LOCK_ndb_util_thread);
+  ndb_util_thread.running= 1;
+  pthread_cond_signal(&ndb_util_thread.COND_ready);
+  pthread_mutex_unlock(&ndb_util_thread.LOCK);
 
   /*
     wait for mysql server to start
@@ -14837,7 +14837,7 @@ pthread_handler_t ndb_util_thread_func(v
     if (ndbcluster_terminating)
     {
       mysql_mutex_unlock(&LOCK_server_started);
-      pthread_mutex_lock(&LOCK_ndb_util_thread);
+      pthread_mutex_lock(&ndb_util_thread.LOCK);
       goto ndb_util_thread_end;
     }
   }
@@ -14846,21 +14846,21 @@ pthread_handler_t ndb_util_thread_func(v
   /*
     Wait for cluster to start
   */
-  pthread_mutex_lock(&LOCK_ndb_util_thread);
+  pthread_mutex_lock(&ndb_util_thread.LOCK);
   while (!g_ndb_status.cluster_node_id && (ndbcluster_hton->slot != ~(uint)0))
   {
     /* ndb not connected yet */
-    pthread_cond_wait(&COND_ndb_util_thread, &LOCK_ndb_util_thread);
+    pthread_cond_wait(&ndb_util_thread.COND, &ndb_util_thread.LOCK);
     if (ndbcluster_terminating)
       goto ndb_util_thread_end;
   }
-  pthread_mutex_unlock(&LOCK_ndb_util_thread);
+  pthread_mutex_unlock(&ndb_util_thread.LOCK);
 
   /* Get thd_ndb for this thread */
   if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd)))
   {
     sql_print_error("Could not allocate Thd_ndb object");
-    pthread_mutex_lock(&LOCK_ndb_util_thread);
+    pthread_mutex_lock(&ndb_util_thread.LOCK);
     goto ndb_util_thread_end;
   }
   set_thd_ndb(thd, thd_ndb);
@@ -14872,14 +14872,14 @@ pthread_handler_t ndb_util_thread_func(v
   set_timespec(abstime, 0);
   for (;;)
   {
-    pthread_mutex_lock(&LOCK_ndb_util_thread);
+    pthread_mutex_lock(&ndb_util_thread.LOCK);
     if (!ndbcluster_terminating)
-      pthread_cond_timedwait(&COND_ndb_util_thread,
-                             &LOCK_ndb_util_thread,
+      pthread_cond_timedwait(&ndb_util_thread.COND,
+                             &ndb_util_thread.LOCK,
                              &abstime);
     if (ndbcluster_terminating) /* Shutting down server */
       goto ndb_util_thread_end;
-    pthread_mutex_unlock(&LOCK_ndb_util_thread);
+    pthread_mutex_unlock(&ndb_util_thread.LOCK);
 #ifdef NDB_EXTRA_DEBUG_UTIL_THREAD
     DBUG_PRINT("ndb_util_thread", ("Started, cache_check_time: %lu",
                                    opt_ndb_cache_check_time));
@@ -15032,7 +15032,7 @@ next:
     set_timespec_nsec(abstime, opt_ndb_cache_check_time * 1000000ULL);
   }
 
-  pthread_mutex_lock(&LOCK_ndb_util_thread);
+  pthread_mutex_lock(&ndb_util_thread.LOCK);
 
 ndb_util_thread_end:
   net_end(&thd->net);
@@ -15048,15 +15048,12 @@ ndb_util_thread_fail:
   delete thd;
   
   /* signal termination */
-  ndb_util_thread_running= 0;
-  pthread_cond_signal(&COND_ndb_util_ready);
-  pthread_mutex_unlock(&LOCK_ndb_util_thread);
+  ndb_util_thread.running= 0;
+  pthread_cond_signal(&ndb_util_thread.COND_ready);
+  pthread_mutex_unlock(&ndb_util_thread.LOCK);
   DBUG_PRINT("exit", ("ndb_util_thread"));
 
   DBUG_LEAVE;                               // Must match DBUG_ENTER()
-  my_thread_end();
-  pthread_exit(0);
-  return NULL;                              // Avoid compiler warnings
 }
 
 /*

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2011-10-17 12:43:31 +0000
+++ b/sql/ha_ndbcluster.h	2011-11-10 08:16:52 +0000
@@ -1090,7 +1090,9 @@ void ndbcluster_print_error(int error, c
 static const char ndbcluster_hton_name[]= "ndbcluster";
 static const int ndbcluster_hton_name_length=sizeof(ndbcluster_hton_name)-1;
 extern int ndbcluster_terminating;
-extern int ndb_util_thread_running;
-extern pthread_cond_t COND_ndb_util_ready;
+
 extern int ndb_index_stat_thread_running;
 extern pthread_cond_t COND_ndb_index_stat_ready;
+
+#include "ndb_util_thread.h"
+extern Ndb_util_thread ndb_util_thread;

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-10-20 16:18:28 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-11-10 08:16:52 +0000
@@ -812,7 +812,7 @@ int ndbcluster_binlog_end(THD *thd)
 {
   DBUG_ENTER("ndbcluster_binlog_end");
 
-  if (ndb_util_thread_running > 0)
+  if (ndb_util_thread.running > 0)
   {
     /*
       Wait for util thread to die (as this uses the injector mutex)
@@ -822,15 +822,15 @@ int ndbcluster_binlog_end(THD *thd)
       be called before ndb_cluster_end().
     */
     sql_print_information("Stopping Cluster Utility thread");
-    pthread_mutex_lock(&LOCK_ndb_util_thread);
+    pthread_mutex_lock(&ndb_util_thread.LOCK);
     /* Ensure mutex are not freed if ndb_cluster_end is running at same time */
-    ndb_util_thread_running++;
+    ndb_util_thread.running++;
     ndbcluster_terminating= 1;
-    pthread_cond_signal(&COND_ndb_util_thread);
-    while (ndb_util_thread_running > 1)
-      pthread_cond_wait(&COND_ndb_util_ready, &LOCK_ndb_util_thread);
-    ndb_util_thread_running--;
-    pthread_mutex_unlock(&LOCK_ndb_util_thread);
+    pthread_cond_signal(&ndb_util_thread.COND);
+    while (ndb_util_thread.running > 1)
+      pthread_cond_wait(&ndb_util_thread.COND_ready, &ndb_util_thread.LOCK);
+    ndb_util_thread.running--;
+    pthread_mutex_unlock(&ndb_util_thread.LOCK);
   }
 
   if (ndb_index_stat_thread_running > 0)

=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h	2011-10-20 16:18:28 +0000
+++ b/sql/ha_ndbcluster_binlog.h	2011-11-10 08:16:52 +0000
@@ -191,8 +191,6 @@ void ndbcluster_global_schema_lock_init(
 void ndbcluster_global_schema_lock_deinit();
 
 extern unsigned char g_node_id_map[max_ndb_nodes];
-extern pthread_mutex_t LOCK_ndb_util_thread;
-extern pthread_cond_t COND_ndb_util_thread;
 extern pthread_mutex_t LOCK_ndb_index_stat_thread;
 extern pthread_cond_t COND_ndb_index_stat_thread;
 extern pthread_mutex_t ndbcluster_mutex;

=== added file 'sql/ndb_component.cc'
--- a/sql/ndb_component.cc	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_component.cc	2011-11-10 08:16:52 +0000
@@ -0,0 +1,143 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#include "ndb_component.h"
+
+Ndb_component::Ndb_component()
+  : m_thread_state(TS_UNINIT)
+{
+}
+
+Ndb_component::~Ndb_component()
+{
+
+}
+
+int
+Ndb_component::init()
+{
+  assert(m_thread_state == TS_UNINIT);
+
+  pthread_mutex_init(&m_start_stop_mutex, MY_MUTEX_INIT_FAST);
+  pthread_cond_init(&m_start_stop_cond, NULL);
+
+  int res= do_init();
+  if (res == 0)
+  {
+    m_thread_state= TS_INIT;
+  }
+  return res;
+}
+
+void *
+Ndb_component_run_C(void * arg)
+{
+  my_thread_init();
+  Ndb_component * self = reinterpret_cast<Ndb_component*>(arg);
+  self->run_impl();
+  my_thread_end();
+  pthread_exit(0);
+  return NULL;                              // Avoid compiler warnings
+}
+
+extern pthread_attr_t connection_attrib; // mysql global pthread attr
+
+int
+Ndb_component::start()
+{
+  assert(m_thread_state == TS_INIT);
+  pthread_mutex_lock(&m_start_stop_mutex);
+  m_thread_state= TS_STARTING;
+  int res= pthread_create(&m_thread, &connection_attrib, Ndb_component_run_C,
+                          this);
+
+  if (res == 0)
+  {
+    while (m_thread_state == TS_STARTING)
+    {
+      pthread_cond_wait(&m_start_stop_cond, &m_start_stop_mutex);
+    }
+    pthread_mutex_unlock(&m_start_stop_mutex);
+    return m_thread_state == TS_RUNNING ? 0 : 1;
+  }
+
+  pthread_mutex_unlock(&m_start_stop_mutex);
+  return res;
+}
+
+void
+Ndb_component::run_impl()
+{
+  pthread_detach_this_thread();
+  pthread_mutex_lock(&m_start_stop_mutex);
+  if (m_thread_state == TS_STARTING)
+  {
+    m_thread_state= TS_RUNNING;
+    pthread_cond_signal(&m_start_stop_cond);
+    pthread_mutex_unlock(&m_start_stop_mutex);
+    do_run();
+    pthread_mutex_lock(&m_start_stop_mutex);
+  }
+  m_thread_state = TS_STOPPED;
+  pthread_cond_signal(&m_start_stop_cond);
+  pthread_mutex_unlock(&m_start_stop_mutex);
+}
+
+bool
+Ndb_component::is_stop_requested()
+{
+  bool res = false;
+  pthread_mutex_lock(&m_start_stop_mutex);
+  res = m_thread_state != TS_RUNNING;
+  pthread_mutex_unlock(&m_start_stop_mutex);
+  return res;
+}
+
+int
+Ndb_component::stop()
+{
+  pthread_mutex_lock(&m_start_stop_mutex);
+  assert(m_thread_state == TS_RUNNING ||
+         m_thread_state == TS_STOPPING ||
+         m_thread_state == TS_STOPPED);
+
+  if (m_thread_state == TS_RUNNING)
+  {
+    m_thread_state= TS_STOPPING;
+  }
+
+  if (m_thread_state == TS_STOPPING)
+  {
+    while (m_thread_state != TS_STOPPED)
+    {
+      pthread_cond_signal(&m_start_stop_cond);
+      pthread_cond_wait(&m_start_stop_cond, &m_start_stop_mutex);
+    }
+  }
+  pthread_mutex_unlock(&m_start_stop_mutex);
+
+  return 0;
+}
+
+int
+Ndb_component::deinit()
+{
+  assert(m_thread_state == TS_STOPPED);
+  pthread_mutex_destroy(&m_start_stop_mutex);
+  pthread_cond_destroy(&m_start_stop_cond);
+  return do_deinit();
+}

=== added file 'sql/ndb_component.h'
--- a/sql/ndb_component.h	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_component.h	2011-11-10 08:16:52 +0000
@@ -0,0 +1,82 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#ifndef HA_NDBCLUSTER_COMPONENT_H
+#define HA_NDBCLUSTER_COMPONENT_H
+
+#include <my_global.h>
+#include <my_pthread.h>
+
+extern "C" void * Ndb_component_run_C(void *);
+
+class Ndb_component
+{
+public:
+  virtual int init();
+  virtual int start();
+  virtual int stop();
+  virtual int deinit();
+
+protected:
+  /**
+   * Con/de-structor is protected...so that sub-class needs to provide own
+   */
+  Ndb_component();
+  virtual ~Ndb_component();
+
+  /**
+   * Component init function
+   */
+  virtual int do_init() = 0;
+
+  /**
+   * Component run function
+   */
+  virtual void do_run() = 0;
+
+  /**
+   * Component deinit function
+   */
+  virtual int do_deinit() = 0;
+
+  /**
+   * For usage in threads main loop
+   */
+  bool is_stop_requested();
+
+private:
+
+  enum ThreadState
+  {
+    TS_UNINIT   = 0,
+    TS_INIT     = 1,
+    TS_STARTING = 2,
+    TS_RUNNING  = 3,
+    TS_STOPPING = 4,
+    TS_STOPPED  = 5
+  };
+
+  ThreadState m_thread_state;
+  pthread_t m_thread;
+  pthread_mutex_t m_start_stop_mutex;
+  pthread_cond_t m_start_stop_cond;
+
+  void run_impl();
+  friend void * Ndb_component_run_C(void *);
+};
+
+#endif

=== added file 'sql/ndb_util_thread.h'
--- a/sql/ndb_util_thread.h	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_util_thread.h	2011-11-10 08:16:52 +0000
@@ -0,0 +1,40 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#ifndef NDB_UTIL_THREAD_H
+#define NDB_UTIL_THREAD_H
+
+#include "ndb_component.h"
+
+class Ndb_util_thread : public Ndb_component
+{
+public:
+  Ndb_util_thread();
+  virtual ~Ndb_util_thread();
+
+  int running;
+  pthread_mutex_t LOCK;
+  pthread_cond_t COND;
+  pthread_cond_t COND_ready;
+
+private:
+  virtual int do_init() { return 0;}
+  virtual void do_run();
+  virtual int do_deinit() { return 0;}
+};
+
+#endif

=== modified file 'storage/ndb/CMakeLists.txt'
--- a/storage/ndb/CMakeLists.txt	2011-09-07 22:50:01 +0000
+++ b/storage/ndb/CMakeLists.txt	2011-11-10 08:16:52 +0000
@@ -149,7 +149,8 @@ SET(NDBCLUSTER_SOURCES
   ../../sql/ha_ndb_index_stat.cc
   ../../sql/ha_ndbinfo.cc
   ../../sql/ndb_mi.cc
-  ../../sql/ndb_conflict_trans.cc)
+  ../../sql/ndb_conflict_trans.cc
+  ../../sql/ndb_component.cc)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/storage/ndb/include)
 
 IF(EXISTS ${CMAKE_SOURCE_DIR}/storage/mysql_storage_engine.cmake)

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.1-telco-7.0 branch (jonas.oreland:4649 to 4650) Jonas Oreland11 Nov