Date: Tuesday, January 31, 2006 @ 11:15:46
  Author: zsolt
    Path: /cvsroot/carob/libmysequoia/src

Modified: MySQLAPI.cpp (1.35 -> 1.36)

- introduced critical section for library initialization
- implemented mysql_set_server_option()


--------------+
 MySQLAPI.cpp |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)


Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.35 libmysequoia/src/MySQLAPI.cpp:1.36
--- libmysequoia/src/MySQLAPI.cpp:1.35  Mon Jan 30 13:45:56 2006
+++ libmysequoia/src/MySQLAPI.cpp       Tue Jan 31 11:15:46 2006
@@ -34,6 +34,7 @@
 #include <log4cxx/basicconfigurator.h>
 #include <log4cxx/propertyconfigurator.h>
 #include <log4cxx/helpers/exception.h>
+#include <log4cxx/helpers/criticalsection.h>
 
 /* C lib includes */
 #include <climits>
@@ -43,6 +44,7 @@
 
 LoggerPtr logger(Logger::getLogger("MySQLAPI"));
 
+CriticalSection library_init;
 static bool library_initialized = false;
 
 /**
@@ -72,6 +74,20 @@
   return (CarobStmt *) stmt->mem_root.used;
 }
 
+/**
+ * Initialize the library if it was not initialized already.
+ */
+void
+initLibraryIfNeeded()
+{
+  library_init.lock();
+  bool init = !library_initialized;
+  library_init.unlock();
+  
+  if (init)
+    mysql_server_init(0, 0, 0);
+}
+
 /* Library initialization, shutdown */
 
 /*Gets or initializes a MYSQL structure. */
@@ -80,9 +96,7 @@
 {
   my_bool free_in_close = false;
 
-  // TODO make it thread safe
-  if (!library_initialized)
-    mysql_server_init(0, 0, 0);
+  initLibraryIfNeeded();
 
   // we can start logging only after the library was initialized
   LOG4CXX_DEBUG(logger, "Entering mysql_init: mysql=" << mysql);
@@ -132,6 +146,8 @@
 int STDCALL
 mysql_server_init (int argc, char **argv, char **groups)
 {
+  library_init.lock();
+  
   // initialize logging 
   PropertyConfigurator::configure(LOGGER_CONFIG_FILE);
 
@@ -139,10 +155,11 @@
   
   tzset();
 
-  // TODO make it thread safe
   library_initialized = true;
 
   LOG4CXX_DEBUG(logger, "Leaving mysql_server_init.");
+  
+  library_init.unlock();
   return 0;
 }
 
@@ -193,9 +210,7 @@
 
   MYSQL *result;
   
-  // TODO make it thread safe
-  if (!library_initialized)
-    mysql_server_init(0, 0, 0);
+  initLibraryIfNeeded();
 
   if (mysql)
   {
@@ -322,6 +337,16 @@
   return result;
 }
 
+/* Sets an option for the connection (like multi-statements). */
+int STDCALL
+mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
+{
+  //nothing todo, because multi-statements are always supported
+  LOG4CXX_DEBUG(logger, "Entering mysql_set_server_option: mysql=" << mysql << 
" option=" << option);
+  LOG4CXX_DEBUG(logger, "Leaving mysql_set_server_option.");
+  return 0;
+}
+
 /* Checks whether the connection to the server is working, reconnecting as 
necessary. */
 int STDCALL
 mysql_ping (MYSQL * mysql)

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to