mirror of https://github.com/bitcoin/bitcoin.git
kernel: Add interrupt function to C header
Calling interrupt can halt long-running functions associated with objects that were created through the passed-in context.
This commit is contained in:
parent
0459e9ac29
commit
8d9088c5db
|
@ -672,6 +672,11 @@ btck_Context* btck_context_copy(const btck_Context* context)
|
|||
return btck_Context::copy(context);
|
||||
}
|
||||
|
||||
int btck_context_interrupt(btck_Context* context)
|
||||
{
|
||||
return (*btck_Context::get(context)->m_interrupt)() ? 0 : -1;
|
||||
}
|
||||
|
||||
void btck_context_destroy(btck_Context* context)
|
||||
{
|
||||
delete context;
|
||||
|
|
|
@ -689,6 +689,16 @@ BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_cr
|
|||
BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_copy(
|
||||
const btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* @brief Interrupt can be used to halt long-running validation functions like
|
||||
* when reindexing, importing or processing blocks.
|
||||
*
|
||||
* @param[in] context Non-null.
|
||||
* @return 0 if the interrupt was successfully, non-zero otherwise.
|
||||
*/
|
||||
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_interrupt(
|
||||
btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* Destroy the context.
|
||||
*/
|
||||
|
|
|
@ -657,6 +657,11 @@ public:
|
|||
Context()
|
||||
: Handle{btck_context_create(ContextOptions{}.get())} {}
|
||||
|
||||
bool interrupt()
|
||||
{
|
||||
return btck_context_interrupt(get()) == 0;
|
||||
}
|
||||
|
||||
friend class ChainstateManagerOptions;
|
||||
};
|
||||
|
||||
|
|
|
@ -670,6 +670,8 @@ BOOST_AUTO_TEST_CASE(btck_chainman_in_memory_tests)
|
|||
|
||||
BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "blocks" / "index"));
|
||||
BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "chainstate"));
|
||||
|
||||
BOOST_CHECK(context.interrupt());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
|
||||
|
|
Loading…
Reference in New Issue