diff --git a/CMakeModules/PerformFeatureChecks.cmake b/CMakeModules/PerformFeatureChecks.cmake index 16c989983d..63395dc356 100644 --- a/CMakeModules/PerformFeatureChecks.cmake +++ b/CMakeModules/PerformFeatureChecks.cmake @@ -78,6 +78,10 @@ macro(perform_feature_checks) # HAVE_GETTIMEOFDAY is already in use within 2.9 wxWidgets, so use HAVE_GETTIMEOFDAY_FUNC check_symbol_exists(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY_FUNC) + # Check for Posix getc_unlocked() for improved performance over getc(). Fall back to + # getc() on platforms where getc_unlocked() doesn't exist. + check_symbol_exists(getc_unlocked "stdio.h" HAVE_GETC_UNLOCKED) + # Generate config.h. configure_file(${PROJECT_SOURCE_DIR}/CMakeModules/config.h.cmake ${CMAKE_BINARY_DIR}/config.h) diff --git a/CMakeModules/config.h.cmake b/CMakeModules/config.h.cmake index f9cad7c542..35e6e097de 100644 --- a/CMakeModules/config.h.cmake +++ b/CMakeModules/config.h.cmake @@ -50,6 +50,9 @@ #define strnicmp _strnicmp #endif +/* Use Posix getc_unlocked() instead of getc() when it's available. */ +#cmakedefine HAVE_GETC_UNLOCKED + /* Warning!!! Using wxGraphicContext for rendering is experimental. */ #cmakedefine USE_WX_GRAPHICS_CONTEXT 1 diff --git a/common/richio.cpp b/common/richio.cpp index 4ab811d96c..e264f6ba3d 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -28,6 +28,13 @@ #include + +// Fall back to getc() when getc_unlocked() is not available on the target platform. +#if !defined( HAVE_GETC_UNLOCKED ) +#define getc_unlocked getc +#endif + + // This file defines 3 classes useful for working with DSN text files and is named // "richio" after its author, Richard Hollenbeck, aka Dick Hollenbeck.