libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

thread_parallel_runner_cxx.h (2404B)


      1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style
      4 // license that can be found in the LICENSE file.
      5 
      6 /// @addtogroup libjxl_cpp
      7 /// @{
      8 ///
      9 /// @file thread_parallel_runner_cxx.h
     10 /// @brief C++ header-only helper for @ref thread_parallel_runner.h.
     11 ///
     12 /// There's no binary library associated with the header since this is a header
     13 /// only library.
     14 
     15 #ifndef JXL_THREAD_PARALLEL_RUNNER_CXX_H_
     16 #define JXL_THREAD_PARALLEL_RUNNER_CXX_H_
     17 
     18 #include <jxl/memory_manager.h>
     19 #include <jxl/thread_parallel_runner.h>
     20 
     21 #include <cstddef>
     22 #include <memory>
     23 
     24 #if !(defined(__cplusplus) || defined(c_plusplus))
     25 #error \
     26     "This a C++ only header. Use jxl/jxl_thread_parallel_runner.h from C" \
     27     "sources."
     28 #endif
     29 
     30 /// Struct to call JxlThreadParallelRunnerDestroy from the
     31 /// JxlThreadParallelRunnerPtr unique_ptr.
     32 struct JxlThreadParallelRunnerDestroyStruct {
     33   /// Calls @ref JxlThreadParallelRunnerDestroy() on the passed runner.
     34   void operator()(void* runner) { JxlThreadParallelRunnerDestroy(runner); }
     35 };
     36 
     37 /// std::unique_ptr<> type that calls JxlThreadParallelRunnerDestroy() when
     38 /// releasing the runner.
     39 ///
     40 /// Use this helper type from C++ sources to ensure the runner is destroyed and
     41 /// their internal resources released.
     42 typedef std::unique_ptr<void, JxlThreadParallelRunnerDestroyStruct>
     43     JxlThreadParallelRunnerPtr;
     44 
     45 /// Creates an instance of JxlThreadParallelRunner into a
     46 /// JxlThreadParallelRunnerPtr and initializes it.
     47 ///
     48 /// This function returns a unique_ptr that will call
     49 /// JxlThreadParallelRunnerDestroy() when releasing the pointer. See @ref
     50 /// JxlThreadParallelRunnerCreate for details on the instance creation.
     51 ///
     52 /// @param memory_manager custom allocator function. It may be NULL. The memory
     53 ///        manager will be copied internally.
     54 /// @param num_worker_threads the number of worker threads to create.
     55 /// @return a @c NULL JxlThreadParallelRunnerPtr if the instance can not be
     56 /// allocated or initialized
     57 /// @return initialized JxlThreadParallelRunnerPtr instance otherwise.
     58 static inline JxlThreadParallelRunnerPtr JxlThreadParallelRunnerMake(
     59     const JxlMemoryManager* memory_manager, size_t num_worker_threads) {
     60   return JxlThreadParallelRunnerPtr(
     61       JxlThreadParallelRunnerCreate(memory_manager, num_worker_threads));
     62 }
     63 
     64 #endif  // JXL_THREAD_PARALLEL_RUNNER_CXX_H_
     65 
     66 /// @}