From 8f3d3956b1e837c726859eb8bbe19dad79c54a42 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 29 Apr 2017 23:55:46 +0300 Subject: Add hxx extension for headers and lib prefix for library dirs --- libbrep/database-lock.hxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libbrep/database-lock.hxx (limited to 'libbrep/database-lock.hxx') diff --git a/libbrep/database-lock.hxx b/libbrep/database-lock.hxx new file mode 100644 index 0000000..60d57a4 --- /dev/null +++ b/libbrep/database-lock.hxx @@ -0,0 +1,43 @@ +// file : libbrep/database-lock.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBREP_DATABASE_LOCK_HXX +#define LIBBREP_DATABASE_LOCK_HXX + +#include // database, transaction +#include + +#include +#include + +namespace brep +{ + struct database_locked: std::exception + { + virtual char const* + what () const throw () {return "database locked";} + }; + + // Try to "lock" the PostgreSQL database in the constructor and release the + // lock in the destructor. Throw database_locked if the database is already + // locked by someone else. May also throw odb::pgsql::database_exception. + // + // This mechanism is used by the brep loader and schema migration tool to + // make sure they don't step on each others toes. + // + // Note: movable but not copyable. + // + class database_lock + { + public: + explicit + database_lock (odb::pgsql::database&); + + private: + odb::pgsql::connection_ptr connection_; + unique_ptr transaction_; + }; +} + +#endif // LIBBREP_DATABASE_LOCK_HXX -- cgit v1.1