libjxl

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

resizable_parallel_runner_cxx.h (2371B)


      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 resizable_parallel_runner_cxx.h
     10 /// @ingroup libjxl_threads
     11 /// @brief C++ header-only helper for @ref resizable_parallel_runner.h.
     12 ///
     13 /// There's no binary library associated with the header since this is a header
     14 /// only library.
     15 
     16 #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
     17 #define JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
     18 
     19 #include <jxl/memory_manager.h>
     20 #include <jxl/resizable_parallel_runner.h>
     21 
     22 #include <memory>
     23 
     24 #if !(defined(__cplusplus) || defined(c_plusplus))
     25 #error \
     26     "This a C++ only header. Use jxl/jxl_resizable_parallel_runner.h from C" \
     27     "sources."
     28 #endif
     29 
     30 /// Struct to call JxlResizableParallelRunnerDestroy from the
     31 /// JxlResizableParallelRunnerPtr unique_ptr.
     32 struct JxlResizableParallelRunnerDestroyStruct {
     33   /// Calls @ref JxlResizableParallelRunnerDestroy() on the passed runner.
     34   void operator()(void* runner) { JxlResizableParallelRunnerDestroy(runner); }
     35 };
     36 
     37 /// std::unique_ptr<> type that calls JxlResizableParallelRunnerDestroy() 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, JxlResizableParallelRunnerDestroyStruct>
     43     JxlResizableParallelRunnerPtr;
     44 
     45 /// Creates an instance of JxlResizableParallelRunner into a
     46 /// JxlResizableParallelRunnerPtr and initializes it.
     47 ///
     48 /// This function returns a unique_ptr that will call
     49 /// JxlResizableParallelRunnerDestroy() when releasing the pointer. See @ref
     50 /// JxlResizableParallelRunnerCreate 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 /// @return a @c NULL JxlResizableParallelRunnerPtr if the instance can not be
     55 /// allocated or initialized
     56 /// @return initialized JxlResizableParallelRunnerPtr instance otherwise.
     57 static inline JxlResizableParallelRunnerPtr JxlResizableParallelRunnerMake(
     58     const JxlMemoryManager* memory_manager) {
     59   return JxlResizableParallelRunnerPtr(
     60       JxlResizableParallelRunnerCreate(memory_manager));
     61 }
     62 
     63 #endif  // JXL_RESIZABLE_PARALLEL_RUNNER_CXX_H_
     64 
     65 /// @}