build system and module refactoring + simple histogram scratch (#20)
* scratch adding histogram to image views Histograms should come from some sort of histogram service. This is currently just a POC. * custom logger implementation w/o spdlog * missing cmake file * fix tests * use operator<< over direct stream exposure * rm print header * add threading test + refactor towards interface libraries omits the need for =target_include_directories= calls /everywhere/ * rm print header * rm constexpr * templated thread_pool * fix doxyfile * default enable doc building * czi reader refactor * rm erroneous include expression * clang-format * single lib include with PUBLIC visibility * compile imgui stdlib * clang format * documentation update centralize `LogLevelToString` to `ILog.hpp` update docs and examples
This commit is contained in:
committed by
Maximilian Kueffner
parent
b37814204f
commit
c00c2c71ac
@@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "simple_thread_pool.hpp"
|
||||
|
||||
TEST(SimpleThreadPoolTest, MutatesFromDifferentThread)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
using namespace pixelarium::utils;
|
||||
std::mutex mut;
|
||||
constexpr auto vecsize{10};
|
||||
std::vector<int> mutation_vector(vecsize, 0);
|
||||
|
||||
auto mutate = [&mutation_vector](int val, int loc) -> void { mutation_vector.at(loc) = val; };
|
||||
|
||||
for (auto i{0}; i < vecsize; ++i)
|
||||
{
|
||||
pixelarium_pool::enqueue(
|
||||
[&mutate, i]()
|
||||
{
|
||||
const auto wait = std::chrono::milliseconds(i);
|
||||
std::this_thread::sleep_for(wait);
|
||||
mutate(i, i);
|
||||
});
|
||||
}
|
||||
|
||||
// wait until each spawned task finished
|
||||
while (!pixelarium_pool::Joinable()) std::this_thread::sleep_for(5ms);
|
||||
|
||||
EXPECT_EQ(mutation_vector.size(), vecsize);
|
||||
for (auto i{0}; i < vecsize; ++i)
|
||||
{
|
||||
EXPECT_EQ(mutation_vector.at(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
// TEST(SimpleThreadPoolTest, ZeroThreads)
|
||||
// {
|
||||
// using namespace pixelarium::utils;
|
||||
// // Creating a thread pool with 0 threads should not throw an exception
|
||||
// // and should be joinable immediately.
|
||||
// simple_thread_pool<0> pool;
|
||||
// EXPECT_TRUE(pool.Joinable());
|
||||
|
||||
// // Enqueuing a task on a 0-thread pool should not crash.
|
||||
// // The task will never run, but the enqueue operation should be valid.
|
||||
// pool.enqueue([]() {});
|
||||
// EXPECT_FALSE(pool.Joinable()); // Now it's not joinable because there's a task
|
||||
// EXPECT_EQ(pool.RunningTasks(), 0); // No tasks are running
|
||||
|
||||
// // Destructor should also handle the 0-thread case gracefully.
|
||||
// }
|
||||
Reference in New Issue
Block a user