From 603ceda21e85d8568ec6197db9bc9293dda3b483 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 21 Nov 2018 13:04:14 -0500 Subject: upgrade salticidae --- test/CMakeLists.txt | 3 -- test/test_concurrent_queue.cpp | 68 ------------------------------------------ 2 files changed, 71 deletions(-) delete mode 100644 test/test_concurrent_queue.cpp (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e4c7a1b..f8796d0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,6 +4,3 @@ include_directories(../src/ add_executable(test_secp256k1 test_secp256k1.cpp) target_link_libraries(test_secp256k1 hotstuff_static) - -add_executable(test_concurrent_queue test_concurrent_queue.cpp) -target_link_libraries(test_concurrent_queue salticidae_static pthread) diff --git a/test/test_concurrent_queue.cpp b/test/test_concurrent_queue.cpp deleted file mode 100644 index 7412213..0000000 --- a/test/test_concurrent_queue.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "salticidae/event.h" -#include "concurrentqueue/blockingconcurrentqueue.h" -#include -#include - -class VeriPool { - int fin_fd[2]; - moodycamel::BlockingConcurrentQueue in_queue; - moodycamel::BlockingConcurrentQueue out_queue; - std::thread notifier; - std::vector workers; - public: - VeriPool(size_t nworker) { - pipe(fin_fd); - // finish notifier thread - notifier = std::thread([this]() { - while (true) - { - int item; - out_queue.wait_dequeue(item); - write(fin_fd[1], &item, sizeof(item)); - } - }); - for (size_t i = 0; i < nworker; i++) - { - workers.push_back(std::thread([this]() { - while (true) - { - int item; - in_queue.wait_dequeue(item); - fprintf(stderr, "%lu working on %d\n", std::this_thread::get_id(), item); - out_queue.enqueue(item * 1000); - } - })); - } - } - - ~VeriPool() { - notifier.detach(); - for (auto &w: workers) w.detach(); - close(fin_fd[0]); - close(fin_fd[1]); - } - - void submit(int item) { - in_queue.enqueue(item); - } - - int get_fd() { - return fin_fd[0]; - } -}; - -int main() { - VeriPool p(2); - salticidae::EventContext ec; - salticidae::Event ev; - ev = salticidae::Event(ec, p.get_fd(), EV_READ, [&ev](int fd, short) { - int item; - read(fd, &item, sizeof(item)); - printf("finished %d\n", item); - ev.add(); - }); - for (int i = 0; i < 10000; i++) - p.submit(i); - ev.add(); - ec.dispatch(); -} -- cgit v1.2.3