Skip to content

Commit 4ccba49

Browse files
committed
Make it easier to disable process executor
By adding a DISALLOW_PROCESS_EXECUTOR build option it's possible to conveniently disable the usage of fork() on non-Window platforms that either don't have fork(), or have an incomplete or inefficient implementation that is to be considered a last resort only. In the same commit the DISALLOW_THREAD_EXECUTOR is used for conditionally compiling the thread executor so that both executors are treated in the same way.
1 parent c2bd13e commit 4ccba49

6 files changed

Lines changed: 20 additions & 3 deletions

File tree

cli/processexecutor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "processexecutor.h"
2424

25-
#if !defined(WIN32) && !defined(__MINGW32__)
25+
#if !defined(DISALLOW_PROCESS_EXECUTOR) && !defined(WIN32) && !defined(__MINGW32__)
2626

2727
#include "cppcheck.h"
2828
#include "errorlogger.h"
@@ -471,4 +471,4 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
471471
mErrorLogger.reportErr(errmsg);
472472
}
473473

474-
#endif // !WIN32
474+
#endif // !DISALLOW_PROCESS_EXECUTOR && !WIN32 && !__MINGW32__

cli/threadexecutor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "threadexecutor.h"
2020

21+
#if !defined(DISALLOW_THREAD_EXECUTOR)
22+
2123
#include "config.h"
2224
#include "cppcheck.h"
2325
#include "errorlogger.h"
@@ -219,3 +221,5 @@ unsigned int ThreadExecutor::check()
219221

220222
return result;
221223
}
224+
225+
#endif // !DISALLOW_THREAD_EXECUTOR

cmake/compilerDefinitions.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ if(DISALLOW_THREAD_EXECUTOR)
5252
add_definitions(-DDISALLOW_THREAD_EXECUTOR)
5353
endif()
5454

55+
if(DISALLOW_PROCESS_EXECUTOR)
56+
add_definitions(-DDISALLOW_PROCESS_EXECUTOR)
57+
endif()
58+
5559
if(MSVC AND DISABLE_CRTDBG_MAP_ALLOC)
5660
add_definitions(-DDISABLE_CRTDBG_MAP_ALLOC)
5761
endif()

cmake/options.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j"
9292
if(DISALLOW_THREAD_EXECUTOR AND WIN32)
9393
message(FATAL_ERROR "Cannot disable usage of ThreadExecutor on Windows as no other executor implementation is currently available")
9494
endif()
95+
option(DISALLOW_PROCESS_EXECUTOR "Disallow usage of ProcessExecutor for -j" OFF)
96+
if(DISALLOW_THREAD_EXECUTOR AND DISALLOW_PROCESS_EXECUTOR)
97+
message(FATAL_ERROR "Cannot disable both ThreadExecutor and ProcessExecutor")
98+
endif()
9599
set(USE_BOOST "Auto" CACHE STRING "Usage of Boost")
96100
set_property(CACHE USE_BOOST PROPERTY STRINGS Auto Off On)
97101
option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF)

cmake/printInfo.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ if(HAVE_RULES)
7878
endif()
7979
message(STATUS)
8080
message(STATUS "DISALLOW_THREAD_EXECUTOR = ${DISALLOW_THREAD_EXECUTOR}")
81+
message(STATUS "DISALLOW_PROCESS_EXECUTOR = ${DISALLOW_PROCESS_EXECUTOR}")
8182
message(STATUS "CMAKE_THREAD_LIBS_INIT = ${CMAKE_THREAD_LIBS_INIT}")
8283
message(STATUS)
8384
message(STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}")

lib/config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,16 @@ static const std::string emptyString;
164164
#define HAS_THREADING_MODEL_THREAD
165165
#define STDCALL __stdcall
166166
#elif ((defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)) || defined(__CPPCHECK__)
167+
#if !defined(DISALLOW_PROCESS_EXECUTOR)
167168
#define HAS_THREADING_MODEL_FORK
169+
#endif
168170
#if !defined(DISALLOW_THREAD_EXECUTOR)
169171
#define HAS_THREADING_MODEL_THREAD
170172
#endif
171173
#define STDCALL
172-
#else
174+
#endif
175+
176+
#if !defined(HAS_THREADING_MODEL_FORK) && !defined(HAS_THREADING_MODEL_THREAD)
173177
#error "No threading model defined"
174178
#endif
175179

0 commit comments

Comments
 (0)