From 9c7543730c710002b9004a0b9d0e9bb42a3d59d5 Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Thu, 26 Apr 2012 16:32:22 +0200 Subject: [PATCH 1/3] CMake compliant file to build test and samples of the library. Tested under Linux and Windows. --- CMakeLists.txt | 24 ++++++++++++++++++++++++ examples/CMakeLists.txt | 12 ++++++++++++ tests/CMakeLists.txt | 14 ++++++++++++++ tests/benchmark/CMakeLists.txt | 4 ++++ tests/cache_tests.cpp | 2 +- tests/concurrent_queue_tests.cpp | 2 +- tests/concurrent_slot_tests.cpp | 2 +- 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 examples/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/benchmark/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8cafb1f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +PROJECT(Concurrent_utils CXX) +ENABLE_TESTING() + +add_definitions(-DBOOST_ALL_DYN_LINK) +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +SET(BOOST_MIN_VERSION "1.40.0") +FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} COMPONENTS thread date_time unit_test_framework REQUIRED) +IF(Boost_FOUND) + INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) + IF(UNIX) + list( APPEND Boost_LIBRARIES pthread) + ENDIF(UNIX) +ELSE(Boost_FOUND) + MESSAGE(FATAL_ERROR + "Can't find BOOST libraries") +ENDIF(Boost_FOUND) + +INCLUDE_DIRECTORIES(./) +ADD_SUBDIRECTORY(examples) +ADD_SUBDIRECTORY(tests) + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..0fb22af --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,12 @@ +ADD_EXECUTABLE(BoundedQueueSingleWorker BoundedQueueSingleWorker.cpp) +ADD_EXECUTABLE(ConcurrentSlot ConcurrentSlot.cpp) +ADD_EXECUTABLE(LookAheadCache LookAheadCache.cpp) +ADD_EXECUTABLE(QueueManyWorkers QueueManyWorkers.cpp) +ADD_EXECUTABLE(QueueSingleWorker QueueSingleWorker.cpp) + +#LINK libraries +TARGET_LINK_LIBRARIES(BoundedQueueSingleWorker ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(ConcurrentSlot ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(LookAheadCache ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(QueueManyWorkers ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(QueueSingleWorker ${Boost_LIBRARIES}) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..ff7a13b --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,14 @@ + +ADD_EXECUTABLE(concurrent_slot_tests concurrent_slot_tests.cpp) +ADD_EXECUTABLE(concurrent_queue_tests concurrent_queue_tests.cpp) +ADD_EXECUTABLE(cache_tests cache_tests.cpp) + +TARGET_LINK_LIBRARIES(concurrent_slot_tests ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(concurrent_queue_tests ${Boost_LIBRARIES}) +TARGET_LINK_LIBRARIES(cache_tests ${Boost_LIBRARIES}) + +ADD_TEST(concurrent_slot_tests concurrent_slot_tests) +ADD_TEST(concurrent_queue_tests concurrent_queue_tests) +ADD_TEST(cache_tests cache_tests) + +ADD_SUBDIRECTORY(benchmark) \ No newline at end of file diff --git a/tests/benchmark/CMakeLists.txt b/tests/benchmark/CMakeLists.txt new file mode 100644 index 0000000..658af18 --- /dev/null +++ b/tests/benchmark/CMakeLists.txt @@ -0,0 +1,4 @@ + +ADD_EXECUTABLE(cache_benchmark_tests cache_benchmark_tests.cpp) +TARGET_LINK_LIBRARIES(cache_benchmark_tests ${Boost_LIBRARIES}) +ADD_TEST(cache_benchmark_tests cache_benchmark_tests) diff --git a/tests/cache_tests.cpp b/tests/cache_tests.cpp index c525fcc..3281886 100644 --- a/tests/cache_tests.cpp +++ b/tests/cache_tests.cpp @@ -3,7 +3,7 @@ #include #define BOOST_TEST_MODULE CacheTestModule -#include +#include using namespace std; using namespace concurrent::cache; diff --git a/tests/concurrent_queue_tests.cpp b/tests/concurrent_queue_tests.cpp index 9f28601..a99f2aa 100644 --- a/tests/concurrent_queue_tests.cpp +++ b/tests/concurrent_queue_tests.cpp @@ -8,7 +8,7 @@ #include #define BOOST_TEST_MODULE ConcurrentQueueTestModule -#include +#include using namespace std; diff --git a/tests/concurrent_slot_tests.cpp b/tests/concurrent_slot_tests.cpp index c8aab55..7cd64fd 100644 --- a/tests/concurrent_slot_tests.cpp +++ b/tests/concurrent_slot_tests.cpp @@ -8,7 +8,7 @@ #include #define BOOST_TEST_MODULE ConcurrentSlotTestModule -#include +#include using namespace concurrent; From f0bae2206dbb7569845fedcbf6db1f2f12f1f774 Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Thu, 26 Apr 2012 16:33:08 +0200 Subject: [PATCH 2/3] Fix minor issue. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cafb1f..a24ca76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,10 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(Concurrent_utils CXX) ENABLE_TESTING() +IF(WIN32) add_definitions(-DBOOST_ALL_DYN_LINK) +ENDIF(WIN32) + set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) SET(BOOST_MIN_VERSION "1.40.0") From 24a7b2e2a55719d88242a0de4f62aa6bbae687ed Mon Sep 17 00:00:00 2001 From: TheFrenchLeaf Date: Fri, 27 Apr 2012 10:58:34 +0200 Subject: [PATCH 3/3] Fix display in debug mode. --- concurrent/cache/lookahead_cache.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/concurrent/cache/lookahead_cache.hpp b/concurrent/cache/lookahead_cache.hpp index 84b56f4..3828775 100644 --- a/concurrent/cache/lookahead_cache.hpp +++ b/concurrent/cache/lookahead_cache.hpp @@ -69,7 +69,7 @@ struct lookahead_cache { boost::mutex::scoped_lock lock(m_WorkerMutex); do { unit = nextWorkUnit(); - D_( std::cout << "next unit is : " << unit.filename << std::endl); + D_( std::cout << "next unit is : " << unit << std::endl); boost::mutex::scoped_lock lock(m_CacheMutex); switch (m_SharedCache.update(unit)) { case FULL: