diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b980f245..82c37f0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,7 +187,7 @@ target_compile_definitions(test_cluster_client PUBLIC -D__MOCK__) target_include_directories(test_cluster_client PUBLIC ${CMAKE_SOURCE_DIR}/src/mock) ## test_blockstore, test_shit -#add_executable(test_blockstore test_blockstore.cpp timerfd_interval.cpp) +#add_executable(test_blockstore test_blockstore.cpp) #target_link_libraries(test_blockstore blockstore) #add_executable(test_shit test_shit.cpp osd_peering_pg.cpp) #target_link_libraries(test_shit ${LIBURING_LIBRARIES} m) diff --git a/src/test_blockstore.cpp b/src/test_blockstore.cpp index d1a1ae88..16af03ef 100644 --- a/src/test_blockstore.cpp +++ b/src/test_blockstore.cpp @@ -2,7 +2,6 @@ // License: VNPL-1.1 (see README.md for details) #include -#include "timerfd_interval.h" #include "blockstore.h" int main(int narg, char *args[]) @@ -13,10 +12,6 @@ int main(int narg, char *args[]) config["data_device"] = "./test_data.bin"; ring_loop_t *ringloop = new ring_loop_t(512); blockstore_t *bs = new blockstore_t(config, ringloop); - timerfd_interval tick_tfd(ringloop, 1, []() - { - printf("tick 1s\n"); - }); blockstore_op_t op; int main_state = 0; diff --git a/src/timerfd_interval.cpp b/src/timerfd_interval.cpp deleted file mode 100644 index b18b1149..00000000 --- a/src/timerfd_interval.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Vitaliy Filippov, 2019+ -// License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details) - -#include -#include -#include -#include "timerfd_interval.h" - -timerfd_interval::timerfd_interval(ring_loop_t *ringloop, int seconds, std::function cb) -{ - wait_state = 0; - timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); - if (timerfd < 0) - { - throw std::runtime_error(std::string("timerfd_create: ") + strerror(errno)); - } - struct itimerspec exp = { - .it_interval = { seconds, 0 }, - .it_value = { seconds, 0 }, - }; - if (timerfd_settime(timerfd, 0, &exp, NULL)) - { - throw std::runtime_error(std::string("timerfd_settime: ") + strerror(errno)); - } - consumer.loop = [this]() { loop(); }; - ringloop->register_consumer(&consumer); - this->ringloop = ringloop; - this->callback = cb; -} - -timerfd_interval::~timerfd_interval() -{ - ringloop->unregister_consumer(&consumer); - close(timerfd); -} - -void timerfd_interval::loop() -{ - if (wait_state == 1) - { - return; - } - struct io_uring_sqe *sqe = ringloop->get_sqe(); - if (!sqe) - { - wait_state = 0; - return; - } - struct ring_data_t *data = ((ring_data_t*)sqe->user_data); - my_uring_prep_poll_add(sqe, timerfd, POLLIN); - data->callback = [&](ring_data_t *data) - { - if (data->res < 0) - { - throw std::runtime_error(std::string("waiting for timer failed: ") + strerror(-data->res)); - } - uint64_t n; - read(timerfd, &n, 8); - wait_state = 0; - callback(); - }; - wait_state = 1; - ringloop->submit(); -} diff --git a/src/timerfd_interval.h b/src/timerfd_interval.h deleted file mode 100644 index 9e4f4a17..00000000 --- a/src/timerfd_interval.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Vitaliy Filippov, 2019+ -// License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details) - -#pragma once - -#include "ringloop.h" - -class timerfd_interval -{ - int wait_state; - int timerfd; - ring_loop_t *ringloop; - ring_consumer_t consumer; - std::function callback; -public: - timerfd_interval(ring_loop_t *ringloop, int seconds, std::function cb); - ~timerfd_interval(); - void loop(); -};