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:
4 files changed
+22
No files matched your search
@@ -676,6 +676,11 @@ btck_Context* btck_context_copy(const btck_Context* context)
|
|||||||
return btck_Context::copy(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)
|
void btck_context_destroy(btck_Context* context)
|
||||||
{
|
{
|
||||||
delete context;
|
delete context;
|
||||||
|
|||||||
@@ -704,6 +704,16 @@ BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_cr
|
|||||||
BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_copy(
|
BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_copy(
|
||||||
const btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
|
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 successful, non-zero otherwise.
|
||||||
|
*/
|
||||||
|
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_interrupt(
|
||||||
|
btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the context.
|
* Destroy the context.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -651,6 +651,11 @@ public:
|
|||||||
|
|
||||||
Context()
|
Context()
|
||||||
: Handle{btck_context_create(ContextOptions{}.get())} {}
|
: Handle{btck_context_create(ContextOptions{}.get())} {}
|
||||||
|
|
||||||
|
bool interrupt()
|
||||||
|
{
|
||||||
|
return btck_context_interrupt(get()) == 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
|
class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
|
||||||
|
|||||||
@@ -634,6 +634,8 @@ BOOST_AUTO_TEST_CASE(btck_chainman_in_memory_tests)
|
|||||||
BOOST_CHECK(std::filesystem::exists(in_memory_test_directory.m_directory / "blocks"));
|
BOOST_CHECK(std::filesystem::exists(in_memory_test_directory.m_directory / "blocks"));
|
||||||
BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "blocks" / "index"));
|
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(!std::filesystem::exists(in_memory_test_directory.m_directory / "chainstate"));
|
||||||
|
|
||||||
|
BOOST_CHECK(context.interrupt());
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
|
BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
|
||||||
|
|||||||
Reference in new issue
Block a user