50#ifndef DOXYGEN_SHOULD_SKIP_THIS
57 template <
typename Functor1,
typename Functor2 >
58 void DatabaseTable::_threadProcessDatabase_(Functor1& exec_func, Functor2& undo_func) {
63 if (nb_threads == 1) {
64 const std::size_t db_size = this->
nbRows();
65 exec_func(std::size_t(0), db_size, 0);
70 const std::vector< std::pair< std::size_t, std::size_t > > ranges
76 std::vector< std::thread > threads;
77 threads.reserve(nb_threads);
78 std::vector< std::exception_ptr > func_exceptions(nb_threads,
nullptr);
81 auto real_exec_func = [&exec_func](std::size_t
begin,
84 std::exception_ptr& exc) ->
void {
87 }
catch (...) { exc = std::current_exception(); }
91 for (std::size_t i = std::size_t(0); i < nb_threads; ++i) {
92 threads.push_back(std::thread(std::ref(real_exec_func),
96 std::ref(func_exceptions[i])));
100 std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
103 bool exception_raised =
false;
104 for (
const auto& exc: func_exceptions) {
105 if (exc !=
nullptr) {
106 exception_raised =
true;
111 if (exception_raised) {
114 auto real_undo_func = [&undo_func](std::size_t
begin,
117 std::exception_ptr& exc) ->
void {
120 }
catch (...) { exc = std::current_exception(); }
125 std::vector< std::exception_ptr > undo_func_exceptions(nb_threads,
nullptr);
126 for (std::size_t i = std::size_t(0); i < nb_threads; ++i) {
128 if (func_exceptions[i] ==
nullptr)
129 threads.push_back(std::thread(std::ref(real_undo_func),
133 std::ref(undo_func_exceptions[i])));
137 std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
140 for (
const auto& exc: func_exceptions) {
141 if (exc !=
nullptr) { std::rethrow_exception(exc); }
const iterator & end() const noexcept
std::size_t nbProcessingThreads_() const
std::size_t nbRows() const noexcept
std::vector< std::pair< std::size_t, std::size_t > > rangesProcessingThreads_(const std::size_t nb_threads) const
The class representing a tabular database stored in RAM.
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities