Skip to content

Commit

Permalink
Check that the C++11 future feature is supported
Browse files Browse the repository at this point in the history
The mingw cross compiler for windows can be built with either a
posix thread model or a win32 thread model. The win32 thread model does
not fully support future. So we detect if future compilation works and
disable multithreading if not.

Fixes issue #178
  • Loading branch information
gbendy authored and jaromil committed Dec 8, 2023
1 parent 659e409 commit 448be4b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/filter/kaleid0sc0pe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include(CheckIncludeFileCXX)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)

cmake_policy(SET CMP0056 NEW)
cmake_policy(SET CMP0066 NEW)
Expand Down Expand Up @@ -59,4 +60,10 @@ else()
endif()
endif()

check_cxx_source_compiles("
#include <future>
int main(){ std::future<void> f; return 0;}" HAS_WORKING_FUTURE)
if (NOT HAS_WORKING_FUTURE)
add_definitions(-DNO_FUTURE)
endif()
install (TARGETS ${TARGET} LIBRARY DESTINATION ${LIBDIR})
18 changes: 18 additions & 0 deletions src/filter/kaleid0sc0pe/kaleid0sc0pe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include "kaleid0sc0pe.h"
#include <memory>
#include <cstring>
#ifndef NO_FUTURE
#include <future>
#endif

#ifdef __SSE2__
#define USE_SSE2
Expand Down Expand Up @@ -612,6 +614,21 @@ std::int32_t Kaleid0sc0pe::process(const void* in_frame, void* out_frame)
if (m_n_segments == 0) {
init();
}
#ifdef NO_FUTURE
Block block(reinterpret_cast<const std::uint8_t*>(in_frame),
reinterpret_cast<std::uint8_t*>(out_frame),
0, 0,
m_width - 1, m_height - 1);
#ifdef __SSE2__
if (m_edge_reflect) {
process_block(&block);
} else {
process_block_bg(&block);
}
#else
process_block(&block);
#endif
#else
if (m_n_threads == 1) {
Block block(reinterpret_cast<const std::uint8_t*>(in_frame),
reinterpret_cast<std::uint8_t*>(out_frame),
Expand Down Expand Up @@ -655,6 +672,7 @@ std::int32_t Kaleid0sc0pe::process(const void* in_frame, void* out_frame)
f.wait();
}
}
#endif

return 0;
}
Expand Down

0 comments on commit 448be4b

Please sign in to comment.