List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:November 20 2006 2:38pm
Subject:bk commit into 5.1 tree (anozdrin:1.2374)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of alik. When alik does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-11-20 17:38:28+03:00, anozdrin@stripped +9 -0
  Polishing:
  1) add support for joinable threads to Thread class;
  2) move checking of thread model to Manager from mysqlmanager.cc,
  because it is needed only for IM-main process.

  server-tools/instance-manager/instance.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +2 -2
    Use Manager::is_linux_threads() instead of global variable.

  server-tools/instance-manager/listener.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +1 -1
    Use Thread::start(DETACHED) instead of Thread::start_detached().

  server-tools/instance-manager/manager.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +72 -9
    1. Use Thread::start(DETACHED) instead of Thread::start_detached();
    2. Move checking of thread model to Manager from mysqlmanager.cc, because
    it is needed only for IM-main process.

  server-tools/instance-manager/manager.h@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +13 -0
    Move checking of thread model to Manager from mysqlmanager.cc, because
    it is needed only for IM-main process.

  server-tools/instance-manager/mysqlmanager.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +0 -28
    Move checking of thread model to Manager from mysqlmanager.cc, because
    it is needed only for IM-main process.

  server-tools/instance-manager/priv.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +0 -8
    Move checking of thread model to Manager from mysqlmanager.cc, because
    it is needed only for IM-main process.

  server-tools/instance-manager/priv.h@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +0 -8
    Move checking of thread model to Manager from mysqlmanager.cc, because
    it is needed only for IM-main process.

  server-tools/instance-manager/thread_registry.cc@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +38 -6
    Add support of joinable threads to Thread class.

  server-tools/instance-manager/thread_registry.h@stripped, 2006-11-20 17:38:25+03:00, anozdrin@stripped +32 -2
    Add support of joinable threads to Thread class.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	anozdrin
# Host:	booka.site
# Root:	/home/alik/MySQL/devel/5.1-rt-im

--- 1.35/server-tools/instance-manager/listener.cc	2006-11-20 17:38:35 +03:00
+++ 1.36/server-tools/instance-manager/listener.cc	2006-11-20 17:38:35 +03:00
@@ -323,7 +323,7 @@ void Listener::handle_new_mysql_connecti
   Mysql_connection *mysql_connection=
     new Mysql_connection(thread_registry, user_map,
                          vio, ++total_connection_count);
-  if (mysql_connection == NULL || mysql_connection->start_detached())
+  if (mysql_connection == NULL || mysql_connection->start(Thread::DETACHED))
   {
     log_error("handle_one_mysql_connection() failed");
     delete mysql_connection;

--- 1.41/server-tools/instance-manager/manager.cc	2006-11-20 17:38:35 +03:00
+++ 1.42/server-tools/instance-manager/manager.cc	2006-11-20 17:38:35 +03:00
@@ -93,6 +93,53 @@ int my_sigwait(const sigset_t *set, int 
 #endif
 
 
+/**********************************************************************
+  LinuxThreadsChecker -- auxilary class to set global linuxthreads flag.
+**********************************************************************/
+
+namespace { /* no-indent */
+
+class LinuxThreadsChecker: public Thread
+{
+public:
+  LinuxThreadsChecker()
+    :main_pid(getpid())
+  { }
+
+public:
+  inline bool is_linux_threads() const
+  {
+    return linux_threads;
+  }
+
+protected:
+  virtual void run()
+  {
+    linux_threads= main_pid != getpid();
+  }
+
+private:
+  pid_t main_pid;
+  bool linux_threads;
+};
+
+}
+
+
+/**********************************************************************
+  Manager implementation
+***********************************************************************/
+
+Guardian *Manager::p_guardian;
+Instance_map *Manager::p_instance_map;
+Thread_registry *Manager::p_thread_registry;
+User_map *Manager::p_user_map;
+
+#ifndef __WIN__
+bool Manager::p_linux_threads;
+#endif // __WIN__
+
+
 void Manager::stop_all_threads()
 {
   /*
@@ -106,14 +153,24 @@ void Manager::stop_all_threads()
   p_thread_registry->deliver_shutdown();
 }
 
-/**********************************************************************
-  Manager implementation
-***********************************************************************/
 
-Guardian *Manager::p_guardian;
-Instance_map *Manager::p_instance_map;
-Thread_registry *Manager::p_thread_registry;
-User_map *Manager::p_user_map;
+bool Manager::check_if_linux_threads()
+{
+  LinuxThreadsChecker checker;
+
+  if (checker.start() || checker.join())
+    return TRUE;
+
+  p_linux_threads= checker.is_linux_threads();
+
+  log_info("Detected threads model: %s.",
+           (const char *) (p_linux_threads ?
+                           "LINUX threads" :
+                           "POSIX threads"));
+
+  return FALSE;
+}
+
 
 /*
   manager - entry point to the main instance manager process: start
@@ -132,6 +189,12 @@ int Manager::main()
   bool shutdown_complete= FALSE;
   pid_t manager_pid= getpid();
 
+  if (check_if_linux_threads())
+  {
+    log_error("Error: can not check if Linux Threads are used.");
+    return 1;
+  }
+
   Thread_registry thread_registry;
   /*
     All objects created in the manager() function live as long as
@@ -228,7 +291,7 @@ int Manager::main()
     permitted to process instances. And before flush_instances() has
     completed, there are no instances to guard.
   */
-  if (guardian.start_detached())
+  if (guardian.start(Thread::DETACHED))
   {
     log_error("Error: can not start Guardian thread.");
     goto err;
@@ -255,7 +318,7 @@ int Manager::main()
 
   /* Initialize the Listener. */
 
-  if (listener.start_detached())
+  if (listener.start(Thread::DETACHED))
   {
     log_error("Error: can not start Listener thread.");
     stop_all_threads();

--- 1.9/server-tools/instance-manager/manager.h	2006-11-20 17:38:35 +03:00
+++ 1.10/server-tools/instance-manager/manager.h	2006-11-20 17:38:35 +03:00
@@ -39,14 +39,27 @@ public:
   static Thread_registry *get_thread_registry() { return p_thread_registry; }
   static User_map *get_user_map() { return p_user_map; }
 
+#ifndef __WIN__
+  static bool is_linux_threads() { return p_linux_threads; }
+#endif // __WIN__
+
 private:
   static void stop_all_threads();
+  static bool check_if_linux_threads();
 
 private:
   static Guardian *p_guardian;
   static Instance_map *p_instance_map;
   static Thread_registry *p_thread_registry;
   static User_map *p_user_map;
+
+#ifndef __WIN__
+  /*
+    This flag is set if Instance Manager is running on the system using
+    LinuxThreads.
+  */
+  static bool p_linux_threads;
+#endif // __WIN__
 };
 
 #endif // INCLUDES_MYSQL_INSTANCE_MANAGER_MANAGER_H

--- 1.21/server-tools/instance-manager/mysqlmanager.cc	2006-11-20 17:38:35 +03:00
+++ 1.22/server-tools/instance-manager/mysqlmanager.cc	2006-11-20 17:38:35 +03:00
@@ -71,7 +71,6 @@ static void daemonize(const char *log_fi
 static void angel();
 static struct passwd *check_user(const char *user);
 static int set_user(const char *user, struct passwd *user_info);
-static bool check_if_linuxthreads();
 #endif
 
 
@@ -111,9 +110,6 @@ int main(int argc, char *argv[])
       }
   }
 
-  if (check_if_linuxthreads())
-    goto main_end; /* out of resources */
-
   if (Options::Daemon::run_as_service)
   {
     /* forks, and returns only in child */
@@ -394,29 +390,5 @@ spawn:
     */
     exit(0);
   }
-}
-
-extern "C" {
-static void *check_if_linuxthreads_thread_func(void *arg)
-{
-  pid_t main_pid= *(pid_t*) arg;
-  linuxthreads= getpid() != main_pid;
-  return NULL; 
-}
-} /* extern "C" */
-
-
-static bool check_if_linuxthreads()
-{
-  pid_t pid= getpid();
-  pthread_t thread_id;
-  int rc;
-
-  rc= pthread_create(&thread_id, NULL, check_if_linuxthreads_thread_func,
-                     (void*) &pid);
-  if (rc == 0)
-    rc= pthread_join(thread_id, NULL);
-
-  return test(rc);
 }
 #endif

--- 1.45/server-tools/instance-manager/instance.cc	2006-11-20 17:38:35 +03:00
+++ 1.46/server-tools/instance-manager/instance.cc	2006-11-20 17:38:35 +03:00
@@ -105,7 +105,7 @@ static int wait_process(My_process_info 
     couldn't use wait(), because it could return in any wait() in the program.
   */
 
-  if (linuxthreads)
+  if (Manager::is_linux_threads())
     wait(NULL);                               /* LinuxThreads were detected */
   else
     waitpid(*pi, NULL, 0);
@@ -564,7 +564,7 @@ int Instance::start()
 
     instance_monitor= new Instance_monitor(this);
 
-    if (instance_monitor == NULL || instance_monitor->start_detached())
+    if (instance_monitor == NULL || instance_monitor->start(Thread::DETACHED))
     {
       delete instance_monitor;
       log_error("Instance::start(): failed to create the monitoring thread"

--- 1.15/server-tools/instance-manager/priv.cc	2006-11-20 17:38:35 +03:00
+++ 1.16/server-tools/instance-manager/priv.cc	2006-11-20 17:38:35 +03:00
@@ -22,14 +22,6 @@
 
 #include "log.h"
 
-#ifndef __WIN__
-/*
-  This flag is set if mysqlmanager has detected that it is running on the
-  system using LinuxThreads
-*/
-bool linuxthreads;
-#endif
-
 /*
   The following string must be less then 80 characters, as
   mysql_connection.cc relies on it

--- 1.14/server-tools/instance-manager/priv.h	2006-11-20 17:38:35 +03:00
+++ 1.15/server-tools/instance-manager/priv.h	2006-11-20 17:38:35 +03:00
@@ -50,14 +50,6 @@ const int MAX_VERSION_LENGTH= 160;
 
 const int MAX_INSTANCE_NAME_SIZE= FN_REFLEN;
 
-#ifndef __WIN__
-/*
-  This flag is set if mysqlmanager has detected that it is running on the
-  system using LinuxThreads
-*/
-extern bool linuxthreads;
-#endif
-
 extern const LEX_STRING mysqlmanager_version;
 
 /* MySQL client-server protocol version: substituted from configure */

--- 1.14/server-tools/instance-manager/thread_registry.cc	2006-11-20 17:38:35 +03:00
+++ 1.15/server-tools/instance-manager/thread_registry.cc	2006-11-20 17:38:35 +03:00
@@ -241,7 +241,7 @@ void Thread_registry::deliver_shutdown()
     log_info("Thread_registry: non-stopped threads:");
 
     for (Thread_info *info= head.next; info != &head; info= info->next)
-      log_info("  - %ld", (long int) info->thread_id);
+      log_info("  - %lu", (unsigned long) info->thread_id);
   }
   else
   {
@@ -345,6 +345,11 @@ int set_stacksize_and_create_thread(pthr
 }
 
 
+Thread::Thread()
+  :id(0)
+{
+}
+
 Thread::~Thread()
 {
 }
@@ -362,17 +367,44 @@ void *Thread::thread_func(void *arg)
 }
 
 
-bool Thread::start_detached()
+bool Thread::start(enum_thread_type thread_type)
 {
-  pthread_t thd_id;
   pthread_attr_t attr;
   int rc;
 
   pthread_attr_init(&attr);
-  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-  rc= set_stacksize_and_create_thread(&thd_id, &attr,
-                                      Thread::thread_func, this);
+
+  if (thread_type == DETACHED)
+  {
+    detached = TRUE;
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+  }
+  else
+  {
+    detached = FALSE;
+  }
+
+  rc= set_stacksize_and_create_thread(&id, &attr, Thread::thread_func, this);
   pthread_attr_destroy(&attr);
 
   return rc != 0;
+}
+
+
+bool Thread::join()
+{
+  if (!id)
+  {
+    log_error("Error: thread has not been started.");
+    return TRUE;
+  }
+
+  if (detached)
+  {
+    log_error("Error: can not join detached thread %lu.",
+              (unsigned long) id);
+    return TRUE;
+  }
+
+  return pthread_join(id, NULL) != 0;
 }

--- 1.9/server-tools/instance-manager/thread_registry.h	2006-11-20 17:38:35 +03:00
+++ 1.10/server-tools/instance-manager/thread_registry.h	2006-11-20 17:38:35 +03:00
@@ -86,16 +86,46 @@ private:
 class Thread
 {
 public:
-  Thread() {}
-  bool start_detached();
+  enum enum_thread_type
+  {
+    DETACHED,
+    JOINABLE
+  };
+public:
+  Thread();
+
+public:
+  inline pthread_t get_thread_id() const;
+  inline bool is_detached() const;
+
+  bool start(enum_thread_type thread_type = JOINABLE);
+  bool join();
+
 protected:
   virtual void run()= 0;
   virtual ~Thread();
+
+private:
+  pthread_t id;
+  bool detached;
+
 private:
   static void *thread_func(void *arg);
+
+private:
   Thread(const Thread & /* rhs */);            /* not implemented */
   Thread &operator=(const Thread & /* rhs */); /* not implemented */
 };
+
+inline pthread_t Thread::get_thread_id() const
+{
+  return id;
+}
+
+inline bool Thread::is_detached() const
+{
+  return detached;
+}
 
 
 /**
Thread
bk commit into 5.1 tree (anozdrin:1.2374)Alexander Nozdrin20 Nov