diff options
Diffstat (limited to 'lib/threads')
-rw-r--r-- | lib/threads/libjxl_threads.pc.in | 1 | ||||
-rw-r--r-- | lib/threads/thread_parallel_runner.cc | 3 | ||||
-rw-r--r-- | lib/threads/thread_parallel_runner_internal.cc | 6 | ||||
-rw-r--r-- | lib/threads/thread_parallel_runner_test.cc | 26 |
4 files changed, 19 insertions, 17 deletions
diff --git a/lib/threads/libjxl_threads.pc.in b/lib/threads/libjxl_threads.pc.in index 4abd783..50b937a 100644 --- a/lib/threads/libjxl_threads.pc.in +++ b/lib/threads/libjxl_threads.pc.in @@ -10,3 +10,4 @@ Requires.private: @JPEGXL_THREADS_LIBRARY_REQUIRES@ Libs: -L${libdir} -ljxl_threads Libs.private: -lm Cflags: -I${includedir} +Cflags.private: -DJXL_THREADS_STATIC_DEFINE diff --git a/lib/threads/thread_parallel_runner.cc b/lib/threads/thread_parallel_runner.cc index b9cf4aa..0d5b962 100644 --- a/lib/threads/thread_parallel_runner.cc +++ b/lib/threads/thread_parallel_runner.cc @@ -88,9 +88,10 @@ void JxlThreadParallelRunnerDestroy(void* runner_opaque) { jpegxl::ThreadParallelRunner* runner = reinterpret_cast<jpegxl::ThreadParallelRunner*>(runner_opaque); if (runner) { + JxlMemoryManager local_memory_manager = runner->memory_manager; // Call destructor directly since custom free function is used. runner->~ThreadParallelRunner(); - ThreadMemoryManagerFree(&runner->memory_manager, runner); + ThreadMemoryManagerFree(&local_memory_manager, runner); } } diff --git a/lib/threads/thread_parallel_runner_internal.cc b/lib/threads/thread_parallel_runner_internal.cc index e868622..2b05ad9 100644 --- a/lib/threads/thread_parallel_runner_internal.cc +++ b/lib/threads/thread_parallel_runner_internal.cc @@ -173,14 +173,8 @@ void ThreadParallelRunner::ThreadFunc(ThreadParallelRunner* self, } ThreadParallelRunner::ThreadParallelRunner(const int num_worker_threads) -#if defined(__EMSCRIPTEN__) - : num_worker_threads_(0), num_threads_(1) { - // TODO(eustas): find out if pthreads would work for us. - (void)num_worker_threads; -#else : num_worker_threads_(num_worker_threads), num_threads_(std::max(num_worker_threads, 1)) { -#endif PROFILER_ZONE("ThreadParallelRunner ctor"); threads_.reserve(num_worker_threads_); diff --git a/lib/threads/thread_parallel_runner_test.cc b/lib/threads/thread_parallel_runner_test.cc index 7ff260e..2293b5c 100644 --- a/lib/threads/thread_parallel_runner_test.cc +++ b/lib/threads/thread_parallel_runner_test.cc @@ -3,6 +3,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include <atomic> + #include "gtest/gtest.h" #include "lib/jxl/base/data_parallel.h" #include "lib/jxl/base/thread_pool_internal.h" @@ -29,8 +31,8 @@ TEST(ThreadParallelRunnerTest, TestPool) { std::vector<int> mementos(num_tasks); for (int begin = 0; begin < 32; ++begin) { std::fill(mementos.begin(), mementos.end(), 0); - pool.Run( - begin, begin + num_tasks, jxl::ThreadPool::SkipInit(), + EXPECT_TRUE(RunOnPool( + &pool, begin, begin + num_tasks, jxl::ThreadPool::NoInit, [begin, num_tasks, &mementos](const int task, const int thread) { // Parameter is in the given range EXPECT_GE(task, begin); @@ -38,7 +40,8 @@ TEST(ThreadParallelRunnerTest, TestPool) { // Store mementos to be sure we visited each task. mementos.at(task - begin) = 1000 + task; - }); + }, + "TestPool")); for (int task = begin; task < begin + num_tasks; ++task) { EXPECT_EQ(1000 + task, mementos.at(task - begin)); } @@ -58,8 +61,8 @@ TEST(ThreadParallelRunnerTest, TestSmallAssignments) { std::atomic<uint64_t> id_bits{0}; std::atomic<int> num_calls{0}; - pool.Run( - 0, num_threads, jxl::ThreadPool::SkipInit(), + EXPECT_TRUE(RunOnPool( + &pool, 0, num_threads, jxl::ThreadPool::NoInit, [&num_calls, num_threads, &id_bits](const int task, const int thread) { num_calls.fetch_add(1, std::memory_order_relaxed); @@ -68,7 +71,8 @@ TEST(ThreadParallelRunnerTest, TestSmallAssignments) { while ( !id_bits.compare_exchange_weak(bits, bits | (1ULL << thread))) { } - }); + }, + "TestSmallAssignments")); // Correct number of tasks. EXPECT_EQ(num_threads, num_calls.load()); @@ -95,10 +99,12 @@ TEST(ThreadParallelRunnerTest, TestCounter) { alignas(128) Counter counters[kNumThreads]; const int kNumTasks = kNumThreads * 19; - pool.Run(0, kNumTasks, jxl::ThreadPool::SkipInit(), - [&counters](const int task, const int thread) { - counters[thread].counter += task; - }); + EXPECT_TRUE(RunOnPool( + &pool, 0, kNumTasks, jxl::ThreadPool::NoInit, + [&counters](const int task, const int thread) { + counters[thread].counter += task; + }, + "TestCounter")); int expected = 0; for (int i = 0; i < kNumTasks; ++i) { |