diff --git a/.travis.yml b/.travis.yml index f65dab24..8e0f61eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,33 +3,64 @@ sudo: false language: cpp -os: linux - -compiler: g++ - -addons: - apt: - packages: - - lcov - -script: +matrix: + include: + - os: linux + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['gcc-5', 'g++-5'] + env: + - COMPILERCC=gcc-5 + - COMPILERCXX=g++-5 + + - os: linux + dist: trusty + compiler: clang + addons: + apt: + sources: ['llvm-toolchain-trusty-4.0'] + packages: ['clang-4.0'] + env: + - COMPILERCC=clang-4.0 + - COMPILERCXX=clang++-4.0 + + + - os: osx + compiler: gcc + env: + - COMPILERCC=gcc + - COMPILERCXX=g++ + + - os: osx + compiler: clang + env: + - COMPILERCC=clang + - COMPILERCXX=clang++ + + + +script: - mkdir build - - cd build - - cmake -DCMAKE_BUILD_TYPE=Release .. - - make VERBOSE=1 - - ctest --verbose + - cd build + - export CC=$COMPILERCC; export CXX=$COMPILERCXX + - cmake .. -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DINSTALL=OFF -DBENCHMARK=ON -DCOVERAGE=OFF + - make + - ctest --verbose + - ./benchmark/benchmark - cd .. -after_success: - - mkdir coverage - - cd coverage - - cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=yes .. - - make - - ctest - - lcov --directory . --capture --output-file coverage.info - - lcov --remove coverage.info '/usr/*' --output-file coverage.info - - lcov --remove coverage.info '*googletest*' --output-file coverage.info - - lcov --remove coverage.info '*.t.cpp' --output-file coverage.info - - lcov --list coverage.info - - bash <(curl -s https://codecov.io/bash) -f coverage.info - - cd .. +# after_success: +# - mkdir coverage +# - cd coverage +# - cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=yes .. +# - make +# - ctest +# - lcov --directory . --capture --output-file coverage.info +# - lcov --remove coverage.info '/usr/*' --output-file coverage.info +# - lcov --remove coverage.info '*googletest*' --output-file coverage.info +# - lcov --remove coverage.info '*.t.cpp' --output-file coverage.info +# - lcov --list coverage.info +# - bash <(curl -s https://codecov.io/bash) -f coverage.info +# - cd .. diff --git a/CMakeLists.txt b/CMakeLists.txt index c266dda1..0b21b64e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,28 +2,42 @@ cmake_minimum_required(VERSION 2.8) project(thread-pool-cpp CXX) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") +option(TESTS "Enable testing" ON) +option(INSTALL "Enable install option" OFF) +option(COVERAGE "Enable code coverage" OFF) +option(BENCHMARK "Build benchmark" ON) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wsign-compare") if(COVERAGE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") endif() -# gtest -enable_testing() -add_subdirectory(googletest) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Tests -add_subdirectory(tests) + +# gtest +if(TESTS) + # Tests + enable_testing() + add_subdirectory(googletest) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include) + add_subdirectory(tests) +endif() + + # Benchmark -add_subdirectory(benchmark) - -# Install -file(GLOB_RECURSE INSTALL_FILES_LIST "${CMAKE_CURRENT_SOURCE_DIR}/include/*") -set_source_files_properties(${INSTALL_FILES_LIST} PROPERTIES HEADER_FILE_ONLY 1) -add_library(HEADER_ONLY_TARGET STATIC ${INSTALL_FILES_LIST}) -set_target_properties(HEADER_ONLY_TARGET PROPERTIES LINKER_LANGUAGE CXX) -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "include") +if(BENCHMARK) + add_subdirectory(benchmark) +endif() + +if(INSTALL) + # Install + file(GLOB_RECURSE INSTALL_FILES_LIST "${CMAKE_CURRENT_SOURCE_DIR}/include/*") + set_source_files_properties(${INSTALL_FILES_LIST} PROPERTIES HEADER_FILE_ONLY 1) + add_library(HEADER_ONLY_TARGET STATIC ${INSTALL_FILES_LIST}) + set_target_properties(HEADER_ONLY_TARGET PROPERTIES LINKER_LANGUAGE CXX) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "include") +endif() diff --git a/include/thread_pool/worker.hpp b/include/thread_pool/worker.hpp index 91e67a37..b352d68f 100644 --- a/include/thread_pool/worker.hpp +++ b/include/thread_pool/worker.hpp @@ -3,6 +3,21 @@ #include #include + +// to solve http://stackoverflow.com/questions/23791060/c-thread-local-storage-clang-503-0-40-mac-osx +#if HAS_CXX11_THREAD_LOCAL + #define ATTRIBUTE_TLS thread_local +#elif defined (__GNUC__) + #define ATTRIBUTE_TLS __thread +#elif defined (_MSC_VER) + #define ATTRIBUTE_TLS __declspec(thread) +#else + // if you are reading this and still want to compile pool, + // you can compile pool by removing ATTRIBUTE_TLS everywhere in the code + #error "Define a thread local storage qualifier for your compiler/platform!" +#endif + + namespace tp { @@ -87,7 +102,7 @@ namespace detail { inline size_t* thread_id() { - static thread_local size_t tss_id = -1u; + static ATTRIBUTE_TLS size_t tss_id = -1u; return &tss_id; } }