Browse Source

Make use of thread_local optional

Because it doesn't seem to be implemented for
apple-darwin targets.
consistent_macro_prefix
Martchus 4 years ago
parent
commit
52734ebf51
  1. 10
      CMakeLists.txt
  2. 18
      conversion/stringconversion.cpp

10
CMakeLists.txt

@ -134,6 +134,7 @@ set(META_APP_NAME "C++ Utilities")
set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
set(META_REQUIRED_FEATURES cxx_thread_local)
set(META_VERSION_MAJOR 4)
set(META_VERSION_MINOR 14)
set(META_VERSION_PATCH 2)
@ -167,6 +168,15 @@ else()
message(STATUS "Disabling use of escape codes by default.")
endif()
# configure use of thread_local
option(ENABLE_THREAD_LOCAL "enables use of Thread-Local Storage" ON)
if(NOT ENABLE_THREAD_LOCAL)
set_source_files_properties(
conversion/stringconversion.cpp
PROPERTIES COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_NO_THREAD_LOCAL
)
endif()
# include modules to apply configuration
include(BasicConfig)
include(WindowsResources)

18
conversion/stringconversion.cpp

@ -1,5 +1,11 @@
#include "./stringconversion.h"
#ifndef CPP_UTILITIES_NO_THREAD_LOCAL
#include "resources/features.h"
#else
#define CPP_UTILITIES_THREAD_LOCAL
#endif
#include <cstdlib>
#include <iomanip>
#include <memory>
@ -137,7 +143,7 @@ StringData convertString(
*/
StringData convertUtf8ToUtf16LE(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Double> descriptor("UTF-8", "UTF-16LE");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Double> descriptor("UTF-8", "UTF-16LE");
return descriptor.convertString(inputBuffer, inputBufferSize);
}
@ -146,7 +152,7 @@ StringData convertUtf8ToUtf16LE(const char *inputBuffer, std::size_t inputBuffer
*/
StringData convertUtf16LEToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Half> descriptor("UTF-16LE", "UTF-8");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Half> descriptor("UTF-16LE", "UTF-8");
return descriptor.convertString(inputBuffer, inputBufferSize);
}
@ -155,7 +161,7 @@ StringData convertUtf16LEToUtf8(const char *inputBuffer, std::size_t inputBuffer
*/
StringData convertUtf8ToUtf16BE(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Double> descriptor("UTF-8", "UTF-16BE");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Double> descriptor("UTF-8", "UTF-16BE");
return descriptor.convertString(inputBuffer, inputBufferSize);
}
@ -164,7 +170,7 @@ StringData convertUtf8ToUtf16BE(const char *inputBuffer, std::size_t inputBuffer
*/
StringData convertUtf16BEToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Half> descriptor("UTF-16BE", "UTF-8");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Half> descriptor("UTF-16BE", "UTF-8");
return descriptor.convertString(inputBuffer, inputBufferSize);
}
@ -173,7 +179,7 @@ StringData convertUtf16BEToUtf8(const char *inputBuffer, std::size_t inputBuffer
*/
StringData convertLatin1ToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Keep> descriptor("ISO-8859-1", "UTF-8");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Keep> descriptor("ISO-8859-1", "UTF-8");
return descriptor.convertString(inputBuffer, inputBufferSize);
}
@ -182,7 +188,7 @@ StringData convertLatin1ToUtf8(const char *inputBuffer, std::size_t inputBufferS
*/
StringData convertUtf8ToLatin1(const char *inputBuffer, std::size_t inputBufferSize)
{
thread_local ConversionDescriptor<Keep> descriptor("UTF-8", "ISO-8859-1");
CPP_UTILITIES_THREAD_LOCAL ConversionDescriptor<Keep> descriptor("UTF-8", "ISO-8859-1");
return descriptor.convertString(inputBuffer, inputBufferSize);
}

Loading…
Cancel
Save