Author: wyoung
Date: Wed Mar 19 13:22:20 2008
New Revision: 2249

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2249&view=rev
Log:
- Made Connection::thread_aware(), thread_start() and thread_end()
  static methods, so they can be called before you create your first
  connection.  This breaks the ABI, but we'll "cheat" just for this
  first release past the ABI boundary release.
- Ditto for DBDriver versions of same
- Calling Connection::thread_start() and thread_end() in
  examples/cpool.cpp, as appropriate.  Above changes were necessary to
  make this work sensibly.

Modified:
    trunk/examples/cpool.cpp
    trunk/lib/connection.cpp
    trunk/lib/connection.h
    trunk/lib/dbdriver.cpp
    trunk/lib/dbdriver.h

Modified: trunk/examples/cpool.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/cpool.cpp?rev=2249&r1=2248&r2=2249&view=diff
==============================================================================
--- trunk/examples/cpool.cpp (original)
+++ trunk/examples/cpool.cpp Wed Mar 19 13:22:20 2008
@@ -101,6 +101,16 @@
 static thread_return_t CALLBACK_SPECIFIER
 worker_thread(thread_arg_t running_flag)
 {
+       // Ask the underlying C API to allocate any per-thread resources it
+       // needs, in case it hasn't happened already.  In this particular
+       // program, it's almost guaranteed that the grab() call below will
+       // create a new connection the first time through, and thus allocate
+       // these resources implicitly, but there's a nonzero chance that
+       // this won't happen.  Anyway, this is an example program, meant to
+       // show good style, so we take the high road and ensure the
+       // resources are allocated before we do any queries.
+       Connection::thread_start();
+
        // Pull data from the sample table a bunch of times, releasing the
        // connection we use each time.
        for (size_t i = 0; i < 6; ++i) {
@@ -133,6 +143,9 @@
        // Tell main() that this thread is no longer running
        *reinterpret_cast<bool*>(running_flag) = false;
        
+       // Release the per-thread resources before we exit
+       Connection::thread_end();
+
        return 0;
 }
 #endif

Modified: trunk/lib/connection.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.cpp?rev=2249&r1=2248&r2=2249&view=diff
==============================================================================
--- trunk/lib/connection.cpp (original)
+++ trunk/lib/connection.cpp Wed Mar 19 13:22:20 2008
@@ -353,16 +353,16 @@
 
 
 bool
-Connection::thread_aware() const
-{
-       return driver_->thread_aware();
+Connection::thread_aware()
+{
+       return DBDriver::thread_aware();
 }
 
 
 void
 Connection::thread_end()
 {
-       driver_->thread_end();
+       DBDriver::thread_end();
 }
 
 
@@ -376,7 +376,7 @@
 bool
 Connection::thread_start()
 {
-       return driver_->thread_start();
+       return DBDriver::thread_start();
 }
 
 } // end namespace mysqlpp

Modified: trunk/lib/connection.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.h?rev=2249&r1=2248&r2=2249&view=diff
==============================================================================
--- trunk/lib/connection.h (original)
+++ trunk/lib/connection.h Wed Mar 19 13:22:20 2008
@@ -299,11 +299,11 @@
 
        /// \brief Returns true if both MySQL++ and database driver we're
        /// using were compiled with thread awareness.
-       bool thread_aware() const;
+       static bool thread_aware();
 
        /// \brief Tells the underlying database driver that this thread
        /// is done using the library.
-       void thread_end();
+       static void thread_end();
 
        /// \brief Returns the database server's thread ID for this connection
        ///
@@ -330,7 +330,7 @@
        /// or with any other similar strategy.
        ///
        /// \retval True if there was no problem
-       bool thread_start();
+       static bool thread_start();
 
 protected:
        /// \brief Build an error message in the standard form used whenever

Modified: trunk/lib/dbdriver.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/dbdriver.cpp?rev=2249&r1=2248&r2=2249&view=diff
==============================================================================
--- trunk/lib/dbdriver.cpp (original)
+++ trunk/lib/dbdriver.cpp Wed Mar 19 13:22:20 2008
@@ -227,7 +227,7 @@
 
 
 bool
-DBDriver::thread_aware() const
+DBDriver::thread_aware()
 {
 #if defined(MYSQLPP_PLATFORM_WINDOWS) || defined(HAVE_PTHREAD) || 
defined(HAVE_SYNCH_H)
        // Okay, good, MySQL++ itself is thread-aware, but only return true

Modified: trunk/lib/dbdriver.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/dbdriver.h?rev=2249&r1=2248&r2=2249&view=diff
==============================================================================
--- trunk/lib/dbdriver.h (original)
+++ trunk/lib/dbdriver.h Wed Mar 19 13:22:20 2008
@@ -453,14 +453,14 @@
        /// automatically make your program "thread-safe".  See the
        /// <a href="../userman/threads.html">chapter on threads</a> in the
        /// user manual for more information and guidance.
-       bool thread_aware() const;
+       static bool thread_aware();
 
        /// \brief Tells the underlying MySQL C API library that this thread
        /// is done using the library.
        ///
        /// This exists because the MySQL C API library allocates some 
per-thread
        /// memory which it doesn't release until you call this.
-       void thread_end() { mysql_thread_end(); }
+       static void thread_end() { mysql_thread_end(); }
 
        /// \brief Returns the MySQL server thread ID for this connection
        ///
@@ -486,7 +486,7 @@
        /// any MySQL++ objects.  If you use a DBDriverPool object, this
        /// applies; DBDriverPool isn't smart enough to call this for you,
        /// and the MySQL C API won't do it, either.
-       bool thread_start() { return !mysql_thread_init(); }
+       static bool thread_start() { return !mysql_thread_init(); }
 
        /// \brief Returns a result set from the last-executed query which
        /// we can walk through in linear fashion, which doesn't store all


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to