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

Add CHAINBASE_CHECK_LOCKING #define

parent 2bf70658
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <fstream> #include <fstream>
#include <iostream>
#include <stdexcept> #include <stdexcept>
#include <typeindex> #include <typeindex>
...@@ -644,6 +645,7 @@ namespace chainbase { ...@@ -644,6 +645,7 @@ namespace chainbase {
void close(); void close();
void flush(); void flush();
void wipe( const bfs::path& dir ); void wipe( const bfs::path& dir );
#ifdef CHAINBASE_CHECK_LOCKING
void set_require_locking( bool enable_require_locking ); void set_require_locking( bool enable_require_locking );
void require_lock_fail( const char* lock_type )const; void require_lock_fail( const char* lock_type )const;
...@@ -659,6 +661,7 @@ namespace chainbase { ...@@ -659,6 +661,7 @@ namespace chainbase {
if( BOOST_UNLIKELY( _enable_require_locking & (_write_lock_count <= 0) ) ) if( BOOST_UNLIKELY( _enable_require_locking & (_write_lock_count <= 0) ) )
require_lock_fail("write"); require_lock_fail("write");
} }
#endif
struct session { struct session {
public: public:
...@@ -860,9 +863,11 @@ namespace chainbase { ...@@ -860,9 +863,11 @@ namespace chainbase {
template< typename Lambda > template< typename Lambda >
auto with_read_lock( Lambda&& callback, uint64_t wait_micro = 1000000 ) -> decltype( (*(Lambda*)nullptr)() ) auto with_read_lock( Lambda&& callback, uint64_t wait_micro = 1000000 ) -> decltype( (*(Lambda*)nullptr)() )
{ {
#ifdef CHAINBASE_CHECK_LOCKING
read_lock lock( _rw_manager->current_lock(), bip::defer_lock_type() ); read_lock lock( _rw_manager->current_lock(), bip::defer_lock_type() );
BOOST_ATTRIBUTE_UNUSED BOOST_ATTRIBUTE_UNUSED
int_incrementer ii( _read_lock_count ); int_incrementer ii( _read_lock_count );
#endif
if( !wait_micro ) if( !wait_micro )
{ {
...@@ -884,9 +889,11 @@ namespace chainbase { ...@@ -884,9 +889,11 @@ namespace chainbase {
if( _read_only ) if( _read_only )
BOOST_THROW_EXCEPTION( std::logic_error( "cannot acquire write lock on read-only process" ) ); BOOST_THROW_EXCEPTION( std::logic_error( "cannot acquire write lock on read-only process" ) );
#ifdef CHAINBASE_CHECK_LOCKING
write_lock lock( _rw_manager->current_lock(), boost::defer_lock_t() ); write_lock lock( _rw_manager->current_lock(), boost::defer_lock_t() );
BOOST_ATTRIBUTE_UNUSED BOOST_ATTRIBUTE_UNUSED
int_incrementer ii( _write_lock_count ); int_incrementer ii( _write_lock_count );
#endif
if( !wait_micro ) if( !wait_micro )
{ {
......
...@@ -130,6 +130,7 @@ namespace chainbase { ...@@ -130,6 +130,7 @@ namespace chainbase {
_index_map.clear(); _index_map.clear();
} }
#ifdef CHAINBASE_CHECK_LOCKING
void database::set_require_locking( bool enable_require_locking ) void database::set_require_locking( bool enable_require_locking )
{ {
_enable_require_locking = enable_require_locking; _enable_require_locking = enable_require_locking;
...@@ -141,6 +142,7 @@ namespace chainbase { ...@@ -141,6 +142,7 @@ namespace chainbase {
std::cerr << err_msg << std::endl; std::cerr << err_msg << std::endl;
BOOST_THROW_EXCEPTION( std::runtime_error( err_msg ) ); BOOST_THROW_EXCEPTION( std::runtime_error( err_msg ) );
} }
#endif
void database::undo() void database::undo()
{ {
......
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