| 1 |
#include <algorithm> |
| 2 |
#include <future> |
| 3 |
#include <thread> |
| 4 |
#include <vector> |
| 5 |
|
| 6 |
namespace CVD |
| 7 |
{ |
| 8 |
namespace internal |
| 9 |
{ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
template <typename F> |
| 14 |
void Slice(int height, int slice_height, F function) |
| 15 |
{ |
| 16 |
slice_height = std::max(1, slice_height); |
| 17 |
std::vector<std::future<void>> futures; |
| 18 |
for(int i = 0, j = 0; j < height; ++i, j += slice_height) |
| 19 |
{ |
| 20 |
int end = std::min(height, j + slice_height); |
| 21 |
futures.push_back(std::async(function, i, j, end - j)); |
| 22 |
} |
| 23 |
for(auto& future : futures) |
| 24 |
{ |
| 25 |
future.get(); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
} |
| 30 |
} |