diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-28 10:51:12 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-28 10:51:12 +0200 |
commit | 529b9704026fb7db8105f22dd5edbe6db1cdc706 (patch) | |
tree | 40877218bc3fcdf981f9e6fd63c79ddf138c8b28 /odb/mysql/statements-base.hxx | |
parent | e97e47cb1eeac5992d3316da9f005cc576a40611 (diff) |
Make schema version access (but not modification) thread-safe
Also cache the version in statements so that we don't have to lock
the mutex (slow) every time we need to check the version.
Diffstat (limited to 'odb/mysql/statements-base.hxx')
-rw-r--r-- | odb/mysql/statements-base.hxx | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/odb/mysql/statements-base.hxx b/odb/mysql/statements-base.hxx index c0630ef..09d4789 100644 --- a/odb/mysql/statements-base.hxx +++ b/odb/mysql/statements-base.hxx @@ -7,10 +7,12 @@ #include <odb/pre.hxx> +#include <odb/schema-version.hxx> #include <odb/details/shared-ptr.hxx> #include <odb/mysql/version.hxx> -#include <odb/mysql/forward.hxx> // connection +#include <odb/mysql/connection.hxx> +#include <odb/mysql/database.hxx> #include <odb/mysql/details/export.hxx> @@ -29,18 +31,30 @@ namespace odb return conn_; } + // Schema version. database::schema_version_migration() is thread- + // safe which means it is also slow. Cache the result in statements + // so we can avoid the mutex lock. This is thread-safe since if the + // version is updated, then the statements cache will be expired. + // + const schema_version_migration& + version_migration (const char* name = "") const + { + if (svm_ == 0) + svm_ = &conn_.database ().schema_version_migration (name); + + return *svm_; + } + public: virtual ~statements_base (); protected: - statements_base (connection_type& conn) - : conn_ (conn) - { - } + statements_base (connection_type& conn): conn_ (conn), svm_ (0) {} protected: connection_type& conn_; + mutable const schema_version_migration* svm_; }; } } |