Skip to content
Snippets Groups Projects
Commit f1d63fb5 authored by theoreticalbts's avatar theoreticalbts
Browse files

Allow lock checks to be enabled at runtime (disabled by default)

parent 3c3e51a9
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@
#include <boost/multi_index_container.hpp>
#include <boost/chrono.hpp>
#include <boost/config.hpp>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
......@@ -638,18 +639,19 @@ namespace chainbase {
void close();
void flush();
void wipe( const bfs::path& dir );
void set_require_locking( bool enable_require_locking );
void require_lock_fail( const char* lock_type )const;
void require_read_lock()const
{
if( _read_only && (_read_lock_count <= 0) )
if( _enable_require_locking && _read_only && (_read_lock_count <= 0) )
require_lock_fail("read");
}
void require_write_lock()
{
if( _write_lock_count <= 0 )
if( _enable_require_locking && (_write_lock_count <= 0) )
require_lock_fail("write");
}
......@@ -918,6 +920,7 @@ namespace chainbase {
int32_t _read_lock_count = 0;
int32_t _write_lock_count = 0;
bool _enable_require_locking = false;
};
template<typename Object, typename... Args>
......
......@@ -130,6 +130,11 @@ namespace chainbase {
_index_map.clear();
}
void database::set_require_locking( bool enable_require_locking )
{
_enable_require_locking = enable_require_locking;
}
void database::require_lock_fail( const char* lock_type )const
{
std::string err_msg = "require_" + std::string( lock_type ) + "_lock() failed";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment