packages feed

mysql 0.1.3 → 0.1.4

raw patch · 4 files changed

+42/−1 lines, 4 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.4++* Expose mysql_thread_end() as `endThread`+ ## 0.1.3  * Safer concurrency - see https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell
Database/MySQL/Base.hs view
@@ -10,6 +10,12 @@ -- -- A low-level client library for the MySQL database, implemented as -- bindings to the C @mysqlclient@ API.+--+-- The C library is thread-safe, but uses thread-local state.  Therefore,+-- if these bindings are used in a multi-threaded program, "bound" threads+-- should be used (see "Control.Concurrent").  In addition, explicit calls+-- to 'initLibrary', and possibly 'initThread' and 'endThread' may be needed+-- in a multi-threaded program.  module Database.MySQL.Base     (@@ -75,6 +81,7 @@     -- * Concurrency     , initLibrary     , initThread+    , endThread     ) where  import Control.Applicative ((<$>), (<*>))@@ -554,7 +561,12 @@  -- | Call @mysql_library_init@ --+-- A single-threaded program can rely on an implicit initialisation done+-- when making the first connection, but a multi-threaded one should call+-- 'initLibrary' separately, and it should be done before other threads+-- might call into this library, since this function is not thread-safe. -- See <https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell>+-- and <https://dev.mysql.com/doc/refman/5.7/en/c-api-threaded-clients.html> -- for details. initLibrary :: IO () initLibrary = do@@ -566,7 +578,13 @@  -- | Call @mysql_thread_init@ --+-- Again a single-threaded program does not need to call this explicitly.  Even+-- in a multi-threaded one, if each connection is made, used, and destroyed+-- in a single thread, it is sufficient to rely on the 'connect' call to do+-- an implicit thread initialisation.  But in other cases, for example when+-- using a connection pool, each thread requires explicit initialisation. -- See <https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell>+-- and <https://dev.mysql.com/doc/refman/5.7/en/c-api-threaded-clients.html> -- for details. initThread :: IO () initThread = do@@ -575,6 +593,21 @@     then return ()     else throw $ ConnectionError "initThread" (-1)       "mysql_thread_init failed"++-- | Call @mysql_thread_end@+--+-- This is needed at thread exit to avoid a memory leak, except when using+-- a non-debug build of at least version 5.7.9 of the MySQL library.+-- See <https://dev.mysql.com/doc/refman/5.7/en/mysql-thread-end.html>.+-- The threads in question are the /OS threads/, so calling this function+-- is likely to be important when using large numbers of bound threads (see+-- "Control.Concurrent").  Unbound threads - those created with 'forkIO' and+-- friends - share a small number of OS threads, so in those it is hard to+-- call this function safely, and there is little benefit in doing so, but in+-- any case using this library in unbound threads is not recommended  (see+-- <https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell>).+endThread :: IO ()+endThread = mysql_thread_end  withRes :: String -> Result -> (Ptr MYSQL_RES -> IO a) -> IO a withRes func res act = do
Database/MySQL/Base/C.hsc view
@@ -67,6 +67,7 @@     -- * Concurrency     , mysql_library_init     , mysql_thread_init+    , mysql_thread_end     ) where  #include "mysql_signals.h"@@ -289,3 +290,6 @@  foreign import ccall safe "mysql.h" mysql_thread_init     :: IO MyBool++foreign import ccall safe "mysql.h" mysql_thread_end+    :: IO ()
mysql.cabal view
@@ -1,5 +1,5 @@ name:           mysql-version:        0.1.3+version:        0.1.4 homepage:       https://github.com/paul-rouse/mysql bug-reports:    https://github.com/paul-rouse/mysql/issues synopsis:       A low-level MySQL client library.