summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2016-02-08 19:00:57 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-02-08 19:00:57 +0000
commit7c7c508ffce4240eb11fc6a3f09edbe8916aef3a (patch)
tree2e898abca1044dee0535f8970217af0afcfdffce
parent9d630188159868589992116dd5d67cecf17bf257 (diff)
parent9642b321825431e8eada62f808fbc6bdc5a769d3 (diff)
downloadextras-7c7c508ffce4240eb11fc6a3f09edbe8916aef3a.tar.gz
Merge "libfec: fix thread count calculation"
-rw-r--r--libfec/fec_process.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/libfec/fec_process.cpp b/libfec/fec_process.cpp
index 3b2846c6..6e0ddd11 100644
--- a/libfec/fec_process.cpp
+++ b/libfec/fec_process.cpp
@@ -62,11 +62,13 @@ ssize_t process(fec_handle *f, uint8_t *buf, size_t count, uint64_t offset,
uint64_t start = (offset / FEC_BLOCKSIZE) * FEC_BLOCKSIZE;
size_t blocks = fec_div_round_up(count, FEC_BLOCKSIZE);
- if ((size_t)threads > blocks) {
- threads = (int)blocks;
+ size_t count_per_thread = fec_div_round_up(blocks, threads) * FEC_BLOCKSIZE;
+ size_t max_threads = fec_div_round_up(count, count_per_thread);
+
+ if ((size_t)threads > max_threads) {
+ threads = (int)max_threads;
}
- size_t count_per_thread = fec_div_round_up(blocks, threads) * FEC_BLOCKSIZE;
size_t left = count;
uint64_t pos = offset;
uint64_t end = start + count_per_thread;