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 | b4825d95472f8d9e2b9892a56c585a035b6230ac (patch) | |
tree | 05d7124cc044205160c4bf4c8bcf8a7bf87dc2d4 /odb/database.hxx | |
parent | 2e258ea80deae21b478c6aa8deae50bd24194c11 (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/database.hxx')
-rw-r--r-- | odb/database.hxx | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/odb/database.hxx b/odb/database.hxx index 7ddbecb..91d8e94 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -28,6 +28,7 @@ #include <odb/exceptions.hxx> #include <odb/details/export.hxx> +#include <odb/details/mutex.hxx> #include <odb/details/c-string.hxx> namespace odb @@ -339,31 +340,34 @@ namespace odb typedef odb::schema_version_migration schema_version_migration_type; schema_version_type - schema_version (const std::string& schema_name = std::string ()) const; + schema_version (const std::string& schema_name = "") const; bool - schema_migration (const std::string& schema_name = std::string ()) const; + schema_migration (const std::string& schema_name = "") const; // Note that there is code that relies on the returned reference // being valid until the version is changed or the database instance // is destroyed. // const schema_version_migration_type& - schema_version_migration ( - const std::string& schema_name = std::string ()) const; + schema_version_migration (const std::string& schema_name = "") const; // Set schema version and migration state manually. // + // Note that the modifier API is not thread-safe. That is, you should + // not modify the schema version while other threads may be accessing + // or modifying the same information. + // void schema_version_migration (schema_version_type, bool migration, - const std::string& schema_name = std::string ()); + const std::string& schema_name = ""); void schema_version_migration (const schema_version_migration_type&, - const std::string& schema_name = std::string ()); + const std::string& schema_name = ""); - // Set default schema version table for all schema names. The table + // Set default schema version table for all the schema names. The table // name should already be quoted if necessary. // void @@ -375,9 +379,9 @@ namespace odb schema_version_table (const std::string& table_name, const std::string& schema_name); - // Schema version sequence number. It is incremented every time - // the schema version or migration flag is changed and can be - // used to detect version changes. The starting value is 1. + // Schema version sequence number. It is incremented every time the + // schema version or migration flag is changed and can be used to + // detect overall version changes. The starting value is 1. // unsigned int schema_version_sequence () const; @@ -485,9 +489,9 @@ namespace odb tracer_type* tracer_; query_factory_map query_factory_map_; - std::string schema_version_table_; + mutable details::mutex mutex_; mutable schema_version_map schema_version_map_; - mutable const schema_version_info* default_schema_version_; // Cached. + std::string schema_version_table_; unsigned int schema_version_seq_; }; } |