Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull from upstream #13

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 58 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
44 changes: 29 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
17 changes: 16 additions & 1 deletion include/thread_pool/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
#include <atomic>
#include <thread>


// 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
{

Expand Down Expand Up @@ -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;
}
}
Expand Down