From cf9c391d8e74497d7396418dc596e7d11365c588 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 15:14:02 +0300 Subject: [PATCH 01/10] Fetch from upstream + update travis --- .travis.yml | 60 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index f65dab24..03d988b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,18 +3,52 @@ sudo: false language: cpp -os: linux +matrix: + include: + - os: linux + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['gcc-5', 'g++-5', 'lcov'] + 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', 'lcov'] + env: + - COMPILERCC=clang-4.0 + - COMPILERCXX=clang++-4.0 + + + - os: osx + compiler: gcc + addons: + brew: + packages: ['lcov'] + env: + - COMPILERCC=gcc + - COMPILERCXX=g++ + + - os: osx + compiler: clang + addons: + brew: + packages: ['lcov'] + env: + - COMPILERCC=clang + - COMPILERCXX=clang++ -compiler: g++ - -addons: - apt: - packages: - - lcov - -script: +script: - mkdir build - - cd build + - cd build + - export CC=$COMPILERCC; export CXX=$COMPILERCXX - cmake -DCMAKE_BUILD_TYPE=Release .. - make VERBOSE=1 - ctest --verbose @@ -27,9 +61,9 @@ after_success: - 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 --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 .. From 1fceac8d0897cf8fc24223bb90462d08d01a422e Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 15:35:50 +0300 Subject: [PATCH 02/10] Fix osx build travis --- .travis.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03d988b2..22773786 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,22 +29,24 @@ matrix: - os: osx compiler: gcc - addons: - brew: - packages: ['lcov'] + before_install: + - brew update + - brew install lcov env: - COMPILERCC=gcc - COMPILERCXX=g++ - os: osx compiler: clang - addons: - brew: - packages: ['lcov'] + before_install: + - brew update + - brew install lcov env: - COMPILERCC=clang - COMPILERCXX=clang++ - + + + script: - mkdir build - cd build From 7af623b20c7072a21f3b949c8f0e8a9edf76cba8 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 16:01:05 +0300 Subject: [PATCH 03/10] Fix thread_local osx problem --- include/thread_pool/worker.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/thread_pool/worker.hpp b/include/thread_pool/worker.hpp index 91e67a37..e048498e 100644 --- a/include/thread_pool/worker.hpp +++ b/include/thread_pool/worker.hpp @@ -3,6 +3,19 @@ #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 // !C++11 && !__GNUC__ && !_MSC_VER + #error "Define a thread local storage qualifier for your compiler/platform!" +#endif + + namespace tp { From 1077ca775456f75ae5c057bebc55708dec9eb86e Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 16:10:52 +0300 Subject: [PATCH 04/10] Try without coverage --- .travis.yml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22773786..aaf3f28a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,18 +29,12 @@ matrix: - os: osx compiler: gcc - before_install: - - brew update - - brew install lcov env: - COMPILERCC=gcc - COMPILERCXX=g++ - os: osx compiler: clang - before_install: - - brew update - - brew install lcov env: - COMPILERCC=clang - COMPILERCXX=clang++ @@ -56,16 +50,16 @@ script: - ctest --verbose - 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 .. From 0ce16f0784f1949d9bf91ecb837fc973f8b92abc Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 16:24:50 +0300 Subject: [PATCH 05/10] Fixes 1 --- .travis.yml | 7 ++++--- CMakeLists.txt | 39 +++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index aaf3f28a..8753c46b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,9 +45,10 @@ script: - mkdir build - cd build - export CC=$COMPILERCC; export CXX=$COMPILERCXX - - cmake -DCMAKE_BUILD_TYPE=Release .. - - make VERBOSE=1 - - ctest --verbose + - cmake .. -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DINSTALL=OFF -DBENCHMARK=ON -DCOVERAGE=OFF + - make + - ctest --verbose + - ./benchmark/benchmark - cd .. # after_success: diff --git a/CMakeLists.txt b/CMakeLists.txt index c266dda1..dd79f3f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,28 +2,39 @@ 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" OFF) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra") 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) +if(TESTS) + # Tests + enable_testing() + add_subdirectory(googletest) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include) + add_subdirectory(tests) +endif() -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Tests -add_subdirectory(tests) # 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() From 544061b6768fcff5b8293052605228301a3804e8 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 16:38:38 +0300 Subject: [PATCH 06/10] Fix 2 --- .travis.yml | 4 ++-- CMakeLists.txt | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8753c46b..8e0f61eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: addons: apt: sources: ['ubuntu-toolchain-r-test'] - packages: ['gcc-5', 'g++-5', 'lcov'] + packages: ['gcc-5', 'g++-5'] env: - COMPILERCC=gcc-5 - COMPILERCXX=g++-5 @@ -21,7 +21,7 @@ matrix: addons: apt: sources: ['llvm-toolchain-trusty-4.0'] - packages: ['clang-4.0', 'lcov'] + packages: ['clang-4.0'] env: - COMPILERCC=clang-4.0 - COMPILERCXX=clang++-4.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index dd79f3f0..c97d5054 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,10 @@ if(COVERAGE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + + # gtest if(TESTS) # Tests @@ -22,7 +26,6 @@ if(TESTS) add_subdirectory(tests) endif() -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) # Benchmark From 397f89b882629c5ad5a64c478db78aa0584e9241 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 16:42:11 +0300 Subject: [PATCH 07/10] Benchmark default ON --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c97d5054..0928ca3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ option(INSTALL "Enable install option" OFF) option(COVERAGE "Enable code coverage" OFF) option(BENCHMARK "Build benchmark" OFF) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra") +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") From 241ad98d930f8ba57a72dbf8605eb102abdf4841 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 19:10:22 +0300 Subject: [PATCH 08/10] Add -Wsign-compare --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0928ca3f..0b21b64e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(thread-pool-cpp CXX) option(TESTS "Enable testing" ON) option(INSTALL "Enable install option" OFF) option(COVERAGE "Enable code coverage" OFF) -option(BENCHMARK "Build benchmark" OFF) +option(BENCHMARK "Build benchmark" ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wsign-compare") if(COVERAGE) From 405cab2e8df0072e332bc5280a5a28ae53135c02 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 20:19:40 +0300 Subject: [PATCH 09/10] Replace thread_local --- include/thread_pool/worker.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/thread_pool/worker.hpp b/include/thread_pool/worker.hpp index e048498e..2d011ce1 100644 --- a/include/thread_pool/worker.hpp +++ b/include/thread_pool/worker.hpp @@ -100,7 +100,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; } } From f84828a5e6fcccf59b4c69ff03385b3f6a9115af Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Mon, 26 Jun 2017 20:28:36 +0300 Subject: [PATCH 10/10] add comment --- include/thread_pool/worker.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/thread_pool/worker.hpp b/include/thread_pool/worker.hpp index 2d011ce1..b352d68f 100644 --- a/include/thread_pool/worker.hpp +++ b/include/thread_pool/worker.hpp @@ -11,7 +11,9 @@ #define ATTRIBUTE_TLS __thread #elif defined (_MSC_VER) #define ATTRIBUTE_TLS __declspec(thread) -#else // !C++11 && !__GNUC__ && !_MSC_VER +#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