Skip to content

Commit

Permalink
refine code after merging of PR #9
Browse files Browse the repository at this point in the history
  • Loading branch information
inkooboo committed May 16, 2017
1 parent 5d120de commit 2044ae0
Show file tree
Hide file tree
Showing 13 changed files with 607 additions and 611 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
boost*
build*
thread_pool-build*
*.pro.user
*.user
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
cmake_minimum_required(VERSION 3.0)

project(thread-pool-cpp CXX)

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

project(thread-pool-cpp)
add_definitions(-std=c++14 -Wall -Werror -O3)

add_definitions(-std=c++14 -Wall -Werror)

# Get all include files
set(THREAD_POOL_CPP_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
include_directories("${THREAD_POOL_CPP_INC_DIR}")
file(GLOB_RECURSE INSTALL_FILES_LIST "${THREAD_POOL_CPP_INC_DIR}/*")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(tests)
add_subdirectory(benchmark)

# Install as header-only library
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 ${THREAD_POOL_CPP_INC_DIR} DESTINATION "include")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "include")
8 changes: 2 additions & 6 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#benchmark

include_directories("${THREAD_POOL_CPP_INC_DIR}")

find_package(Boost REQUIRED COMPONENTS system)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${Boost_INCLUDE_DIR})

add_executable(benchmark benchmark.cpp)
target_link_libraries(benchmark ${Boost_LIBRARIES} pthread)
target_link_libraries(benchmark pthread)

26 changes: 11 additions & 15 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//#define WITHOUT_ASIO 1

#include <thread_pool.hpp>

#ifndef WITHOUT_ASIO
#ifdef WITH_ASIO
#include <asio_thread_pool.hpp>
#endif

Expand All @@ -14,8 +12,6 @@

using namespace tp;

using ThreadPoolStd = ThreadPool<>;

static const size_t CONCURRENCY = 16;
static const size_t REPOST_COUNT = 1000000;

Expand Down Expand Up @@ -85,20 +81,20 @@ struct Heavy

struct RepostJob
{
// Heavy heavy;
//Heavy heavy;

ThreadPoolStd* thread_pool;
#ifndef WITHOUT_ASIO
ThreadPool* thread_pool;
#ifdef WITH_ASIO
AsioThreadPool* asio_thread_pool;
#endif

volatile size_t counter;
long long int begin_count;
std::promise<void>* waiter;

RepostJob(ThreadPoolStd* thread_pool, std::promise<void>* waiter)
RepostJob(ThreadPool* thread_pool, std::promise<void>* waiter)
: thread_pool(thread_pool)
#ifndef WITHOUT_ASIO
#ifdef WITH_ASIO
,
asio_thread_pool(0)
#endif
Expand All @@ -110,7 +106,7 @@ struct RepostJob
.count();
}

#ifndef WITHOUT_ASIO
#ifdef WITH_ASIO
RepostJob(AsioThreadPool* asio_thread_pool, std::promise<void>* waiter)
: thread_pool(0), asio_thread_pool(asio_thread_pool), counter(0),
waiter(waiter)
Expand All @@ -123,9 +119,9 @@ struct RepostJob

void operator()()
{
if(counter++ < REPOST_COUNT)
if(++counter < REPOST_COUNT)
{
#ifndef WITHOUT_ASIO
#ifdef WITH_ASIO
if(asio_thread_pool)
{
asio_thread_pool->post(*this);
Expand Down Expand Up @@ -159,7 +155,7 @@ int main(int, const char* [])
std::cout << "***thread pool cpp***" << std::endl;

std::promise<void> waiters[CONCURRENCY];
ThreadPoolStd thread_pool;
ThreadPool thread_pool;
for(auto& waiter : waiters)
{
thread_pool.post(RepostJob(&thread_pool, &waiter));
Expand All @@ -171,7 +167,7 @@ int main(int, const char* [])
}
}

#ifndef WITHOUT_ASIO
#ifdef WITH_ASIO
{
std::cout << "***asio thread pool***" << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion cmake/Findthread-pool-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ if (NOT EXISTS "${THREAD_POOL_CPP_INCLUDE_DIR}" AND DEFINED THREAD_POOL_CPP_CLON
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(THREAD_POOL_CPP DEFAULT_MSG THREAD_POOL_CPP_INCLUDE_DIR)
find_package_handle_standard_args(THREAD_POOL_CPP DEFAULT_MSG THREAD_POOL_CPP_INCLUDE_DIR)
2 changes: 1 addition & 1 deletion include/thread_pool.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#include "./thread_pool/thread_pool.hpp"
#include <thread_pool/thread_pool.hpp>
Loading

0 comments on commit 2044ae0

Please sign in to comment.