Skip to content

Commit

Permalink
replace <execution> verification
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Jul 15, 2023
1 parent cdb480a commit a0555ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cmake_minimum_required(VERSION 3.18)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
cmake_policy(SET CMP0075 NEW)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -39,12 +40,20 @@ option(ENABLE_OPENGL "Enable canvas rendering with OpenGL." OFF)

include(FetchContent)
include(GNUInstallDirs)
include(CheckIncludeFileCXX)

find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(TBB REQUIRED)

# check if <execution> is available
set(CMAKE_REQUIRED_LIBRARIES TBB::tbb)
check_include_file_cxx(execution HAVE_STD_EXECUTION_H)
if (HAVE_STD_EXECUTION_H)
target_compile_definitions(ueberzug PRIVATE HAVE_STD_EXECUTION_H)
endif()

find_package(Microsoft.GSL CONFIG QUIET)
if (NOT Microsoft.GSL_FOUND)
option(GSL_TEST OFF)
Expand Down
14 changes: 8 additions & 6 deletions src/canvas/iterm2/iterm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

#include <spdlog/spdlog.h>
#include <fmt/format.h>
#if !defined(__cpp_lib_execution) || (__cpp_lib_execution < 201902L)
# include <oneapi/tbb.h>
#else

#ifdef HAVE_STD_EXECUTION_H
# include <execution>
#else
# include <oneapi/tbb.h>
#endif

namespace fs = std::filesystem;
Expand Down Expand Up @@ -96,10 +97,11 @@ auto Iterm2::process_chunks(const std::string_view filename, int chunk_size, siz
chunks.push_back(std::move(chunk));
}

#if !defined(__cpp_lib_execution) || (__cpp_lib_execution < 201902L)
oneapi::tbb::parallel_for_each(std::begin(chunks), std::end(chunks), Iterm2Chunk());
#else
#ifdef HAVE_STD_EXECUTION_H
std::for_each(std::execution::par_unseq, std::begin(chunks), std::end(chunks), Iterm2Chunk::process_chunk);
#else
oneapi::tbb::parallel_for_each(std::begin(chunks), std::end(chunks), Iterm2Chunk());
#endif

return chunks;
}
14 changes: 8 additions & 6 deletions src/canvas/kitty/kitty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
#include <fmt/format.h>

#include <iostream>
#if !defined(__cpp_lib_execution) || (__cpp_lib_execution < 201902L)
# include <oneapi/tbb.h>
#else

#ifdef HAVE_STD_EXECUTION_H
# include <execution>
#else
# include <oneapi/tbb.h>
#endif

Kitty::Kitty(std::unique_ptr<Image> new_image, std::shared_ptr<std::mutex> stdout_mutex):
Expand Down Expand Up @@ -98,11 +99,12 @@ auto Kitty::process_chunks() -> std::vector<KittyChunk>
}
chunks.emplace_back(ptr + idx * chunk_size, last_chunk_size);

#if !defined(__cpp_lib_execution) || (__cpp_lib_execution < 201902L)
oneapi::tbb::parallel_for_each(std::begin(chunks), std::end(chunks), KittyChunk());
#else
#ifdef HAVE_STD_EXECUTION_H
std::for_each(std::execution::par_unseq, std::begin(chunks), std::end(chunks), KittyChunk::process_chunk);
#else
oneapi::tbb::parallel_for_each(std::begin(chunks), std::end(chunks), KittyChunk());
#endif

return chunks;
}

0 comments on commit a0555ee

Please sign in to comment.