Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc246806

Browse files
committed
Refactored thread_pool from the utils sub-directory (and namespace) into concurrency.
1 parent5f6cce5 commitc246806

File tree

11 files changed

+127
-61
lines changed

11 files changed

+127
-61
lines changed

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ message(STATUS " CPP-NETLIB_DISABLE_LOGGING: ${CPP-NETLIB_DISABLE_LOGGING}\t(
113113
add_subdirectory(uri)
114114
add_subdirectory(message)
115115
add_subdirectory(logging)
116+
add_subdirectory(concurrency)

‎concurrency/CMakeLists.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Glyn Matthews 2012.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
add_subdirectory(src)
7+
8+
if(CPP-NETLIB_BUILD_TESTS)
9+
enable_testing()
10+
add_subdirectory(test)
11+
endif(CPP-NETLIB_BUILD_TESTS)

‎concurrency/src/CMakeLists.txt‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Glyn Matthews 2012.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src)
7+
8+
if (${CMAKE_CXX_COMPILER_ID}MATCHES GNU)
9+
if (HAVE_STD11)
10+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11")
11+
elseif (HAVE_STD0X)
12+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++0x")
13+
endif()
14+
elseif (${CMAKE_CXX_COMPILER_ID}MATCHES Clang)
15+
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
16+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11 -stdlib=libc++")
17+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11 -stdlib=libc++")
18+
endif()
19+
20+
set(CPP-NETLIB_CONCURRENCY_SRCS thread_pool.cpp)
21+
add_library(cppnetlib-concurrency ${CPP-NETLIB_CONCURRENCY_SRCS})
22+
foreach (src_file ${CPP-NETLIB_CONCURRENCY_SRCS})
23+
if (${CMAKE_CXX_COMPILER_ID}MATCHES GNU)
24+
set_source_files_properties(${src_file}
25+
PROPERTIESCOMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
26+
elseif (${CMAKE_CXX_COMPILER_ID}MATCHES Clang)
27+
set_source_files_properties(${src_file}
28+
PROPERTIESCOMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
29+
endif()
30+
endforeach(src_file)

‎include/network/utils/thread_pool.hpp‎renamed to ‎concurrency/src/network/concurrency/thread_pool.hpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright 2010 Dean Michael Berris.
22
// Copyright 2012 Google, Inc.
3+
// Copyright (c) Glyn Matthews 2012.
34
// Distributed under the Boost Software License, Version 1.0.
45
// (See accompanying file LICENSE_1_0.txt or copy at
56
// http://www.boost.org/LICENSE_1_0.txt)
67

7-
#ifndefNETWORK_UTILS_THREAD_POOL_HPP_20101020
8-
#defineNETWORK_UTILS_THREAD_POOL_HPP_20101020
8+
#ifndefNETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
9+
#defineNETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
910

1011
#include<cstddef>
1112
#include<thread>
@@ -14,7 +15,7 @@
1415
#include<vector>
1516
#include<boost/asio/io_service.hpp>
1617

17-
namespacenetwork {namespaceutils {
18+
namespacenetwork {namespaceconcurrency {
1819

1920
typedef std::shared_ptr<boost::asio::io_service> io_service_ptr;
2021
typedef std::shared_ptr<std::vector<std::thread>> worker_threads_ptr;
@@ -46,7 +47,7 @@ namespace network { namespace utils {
4647
l.swap(r);
4748
}
4849

49-
}// namespaceutils
50+
}// namespaceconcurrency
5051
}// namespace network
5152

52-
#endif/*NETWORK_UTILS_THREAD_POOL_HPP_20101020*/
53+
#endif/*NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020*/

‎include/network/utils/thread_pool.ipp‎renamed to ‎concurrency/src/network/concurrency/thread_pool.ipp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
22
// Copyright 2011 Google, Inc.
3+
// Copyright (c) Glyn Matthews 2012.
34
// Distributed under the Boost Software License, Version 1.0.
45
// (See accompanying file LICENSE_1_0.txt or copy at
56
// http://www.boost.org/LICENSE_1_0.txt)
67

7-
#ifndefNETWORK_UTILS_THREAD_POOL_IPP_20111021
8-
#defineNETWORK_UTILS_THREAD_POOL_IPP_20111021
8+
#ifndefNETWORK_CONCURRENCY_THREAD_POOL_IPP_20111021
9+
#defineNETWORK_CONCURRENCY_THREAD_POOL_IPP_20111021
910

1011
#include<vector>
1112
#include<thread>
12-
#include<network/utils/thread_pool.hpp>
13+
#include<network/concurrency/thread_pool.hpp>
1314
#include<boost/scope_exit.hpp>
1415

15-
namespacenetwork {namespaceutils {
16+
namespacenetwork {namespaceconcurrency {
1617

1718
structthread_pool_pimpl {
1819
thread_pool_pimpl(std::size_t threads =1,
@@ -109,7 +110,7 @@ namespace network { namespace utils {
109110
delete pimpl;
110111
}
111112

112-
}// namespaceutils
113+
}// namespaceconcurrency
113114
}// namespace network
114115

115-
#endif/*NETWORK_UTILS_THREAD_POOL_IPP_20111021*/
116+
#endif/*NETWORK_CONCURRENCY_THREAD_POOL_IPP_20111021*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Glyn Matthews 2012.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
#ifndef __NETWORK_UTILS_THREAD_POOL_INC__
8+
#define__NETWORK_UTILS_THREAD_POOL_INC__
9+
10+
#include<network/concurrency/thread_pool.hpp>
11+
12+
namespacenetwork {
13+
namespaceutils {
14+
typedef ::network::concurrency::thread_pool thread_pool;
15+
}// namespace utils
16+
}// namespace network
17+
18+
19+
#endif// __NETWORK_UTILS_THREAD_POOL_INC__
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
22
// Copyright 2011 Google, Inc.
3+
// Copyright (c) Glyn Matthews 2012.
34
// Distributed under the Boost Software License, Version 1.0.
45
// (See accompanying file LICENSE_1_0.txt or copy at
56
// http://www.boost.org/LICENSE_1_0.txt)
67

7-
#include<network/utils/thread_pool.ipp>
8+
#include<network/concurrency/thread_pool.ipp>

‎concurrency/test/CMakeLists.txt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Glyn Matthews 2012.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
include_directories(${CPP-NETLIB_SOURCE_DIR}/concurrency/src)
7+
8+
if (${CMAKE_CXX_COMPILER_ID}MATCHES GNU)
9+
if (HAVE_STD11)
10+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11")
11+
elseif (HAVE_STD0X)
12+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++0x")
13+
endif()
14+
elseif (${CMAKE_CXX_COMPILER_ID}MATCHES Clang)
15+
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
16+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11 -stdlib=libc++")
17+
set(CPP-NETLIB_CXXFLAGS"-Wall -std=c++11 -stdlib=libc++")
18+
endif()
19+
20+
set_source_files_properties(thread_pool_test.cpp
21+
PROPERTIESCOMPILE_FLAGS"-Wall")
22+
add_executable(cpp-netlib-thread_pool_test thread_pool_test.cpp)
23+
target_link_libraries(cpp-netlib-thread_pool_test
24+
cppnetlib-concurrency
25+
${Boost_LIBRARIES}
26+
${CMAKE_THREAD_LIBS_INIT})
27+
set_target_properties(cpp-netlib-thread_pool_test
28+
PROPERTIESRUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
29+
add_test(cpp-netlib-thread_pool_test ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-thread_pool_test)
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11

22
// Copyright 2010 Dean Michael Berris.
33
// Copyright 2012 Google, Inc.
4+
// Copyright (c) Glyn Matthews 2012.
45
// Distributed under the Boost Software License, Version 1.0.
56
// (See accompanying file LICENSE_1_0.txt or copy at
67
// http://www.boost.org/LICENSE_1_0.txt)
78

89
#ifdef BUILD_SHARED_LIBS
910
#defineBOOST_TEST_DYN_LINK
1011
#endif
11-
#defineBOOST_TEST_MODULEutilsthread pool test
12+
#defineBOOST_TEST_MODULE thread pool test
1213
#include<boost/config/warning_disable.hpp>
1314
#include<boost/test/unit_test.hpp>
14-
#include<network/utils/thread_pool.hpp>
15+
#include<network/concurrency/thread_pool.hpp>
1516
#include<boost/bind.hpp>
1617

17-
usingnamespacenetwork;
18+
using network::concurrency::thread_pool;
1819

1920
// This test specifies the requirements for a thread pool interface. At the
2021
// very least any thread pool implementation should be able to pass the simple
@@ -25,29 +26,29 @@ using namespace network;
2526
//
2627

2728
BOOST_AUTO_TEST_CASE( default_constructor ) {
28-
utils::thread_pool pool;
29-
BOOST_CHECK_EQUAL(pool.thread_count(),std::size_t(1));
29+
thread_pool pool;
30+
BOOST_CHECK_EQUAL(pool.thread_count(),std::size_t(1));
3031
}
3132

3233
structfoo {
33-
foo() : val_(0) {}
34-
voidbar(int val) {
35-
val_ += val;
36-
}
37-
intconstval()const {
38-
return val_;
39-
}
34+
foo() : val_(0) {}
35+
voidbar(int val) {
36+
val_ += val;
37+
}
38+
intconstval()const {
39+
return val_;
40+
}
4041
protected:
41-
int val_;
42+
int val_;
4243
};
4344

4445
BOOST_AUTO_TEST_CASE( post_work ) {
45-
foo instance;
46-
{
47-
utils::thread_pool pool;
48-
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance,1)));
49-
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance,2)));
50-
// require that pool is destroyed here, RAII baby
51-
}
52-
BOOST_CHECK_EQUAL(instance.val(),3);
46+
foo instance;
47+
{
48+
thread_pool pool;
49+
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance,1)));
50+
BOOST_CHECK_NO_THROW(pool.post(boost::bind(&foo::bar, &instance,2)));
51+
// require that pool is destroyed here, RAII baby
52+
}
53+
BOOST_CHECK_EQUAL(instance.val(),3);
5354
}

‎libs/network/src/CMakeLists.txt‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,6 @@ elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
172172
endif()
173173
endforeach(src_file)
174174

175-
set(CPP-NETLIB_UTILS_THREAD_POOL_SRCS utils/thread_pool.cpp)
176-
add_library(cppnetlib-utils-thread_pool ${CPP-NETLIB_UTILS_THREAD_POOL_SRCS})
177-
foreach (src_file ${CPP-NETLIB_UTILS_THREAD_POOL_SRCS})
178-
if (${CMAKE_CXX_COMPILER_ID}MATCHES GNU)
179-
set_source_files_properties(${src_file}
180-
PROPERTIESCOMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
181-
elseif (${CMAKE_CXX_COMPILER_ID}MATCHES Clang)
182-
set_source_files_properties(${src_file}
183-
PROPERTIESCOMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
184-
endif()
185-
endforeach(src_file)
186-
187175
set(CPP-NETLIB_CONSTANTS_SRCS constants.cpp)
188176
add_library(cppnetlib-constants ${CPP-NETLIB_CONSTANTS_SRCS})
189177
foreach (src_file ${CPP-NETLIB_CONSTANTS_SRCS})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp