51#ifndef DOXYGEN_SHOULD_SKIP_THIS
58 template <
typename Functor1,
typename Functor2 >
59 void DatabaseTable::_threadProcessDatabase_(Functor1& exec_func, Functor2& undo_func) {
64 if (nb_threads == 1) {
65 const std::size_t db_size = this->
nbRows();
66 exec_func(std::size_t(0), db_size, 0);
71 const std::vector< std::pair< std::size_t, std::size_t > > ranges
77 std::vector< std::thread > threads;
78 threads.reserve(nb_threads);
79 std::vector< std::exception_ptr > func_exceptions(nb_threads,
nullptr);
82 auto real_exec_func = [&exec_func](std::size_t
begin,
85 std::exception_ptr& exc) ->
void {
88 }
catch (...) { exc = std::current_exception(); }
92 for (std::size_t i = std::size_t(0); i < nb_threads; ++i) {
93 threads.push_back(std::thread(std::ref(real_exec_func),
97 std::ref(func_exceptions[i])));
101 std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
104 bool exception_raised =
false;
105 for (
const auto& exc: func_exceptions) {
106 if (exc !=
nullptr) {
107 exception_raised =
true;
112 if (exception_raised) {
115 auto real_undo_func = [&undo_func](std::size_t
begin,
118 std::exception_ptr& exc) ->
void {
121 }
catch (...) { exc = std::current_exception(); }
126 std::vector< std::exception_ptr > undo_func_exceptions(nb_threads,
nullptr);
127 for (std::size_t i = std::size_t(0); i < nb_threads; ++i) {
129 if (func_exceptions[i] ==
nullptr)
130 threads.push_back(std::thread(std::ref(real_undo_func),
134 std::ref(undo_func_exceptions[i])));
138 std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
141 for (
const auto& exc: func_exceptions) {
142 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