diff --git a/.gitignore b/.gitignore index accfe6e0..bef4dfe2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ tests/CDSChecker/model-checker/ tests/relacy/freelist.exe tests/relacy/spmchash.exe tests/relacy/log.txt +test_package/build/ +*.pyc diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..f3a1dc10 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,21 @@ +from conans import ConanFile +import os + +class ConcurrentQueue(ConanFile): + name = "concurrentqueue" + url = 'https://github.com/Manu343726/concurrentqueue' + description='A fast multi-producer, multi-consumer lock-free queue for C++11' + license = "Simplified BSD/Boost Software License" + version = "1.0.0" + exports = "*.h" + build_policy = "missing" + generators = 'cmake' + + def package(self): + include_dir = os.path.join('include', 'concurrentqueue') + include_dir2 = os.path.join('include', 'moodycamel') + + self.copy('concurrentqueue.h', dst=include_dir) + self.copy('blockingconcurrentqueue.h', dst=include_dir) + self.copy('concurrentqueue.h', dst=include_dir2) + self.copy('blockingconcurrentqueue.h', dst=include_dir2) diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 00000000..fb4bf179 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,14 @@ +project(concurrentqueue_test_package) +cmake_minimum_required(VERSION 2.8) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() +conan_define_targets() + +add_executable(example main.cpp) +if(NOT MSVC) + target_compile_options(example PRIVATE -std=c++11) +endif() + +find_package(Threads) +target_link_libraries(example PRIVATE CONAN_PKG::concurrentqueue ${CMAKE_THREAD_LIBS_INIT}) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 00000000..7be5a0b0 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,21 @@ +from conans import ConanFile, CMake +import os + +version = os.getenv('CONAN_CONCURRENTQUEUE_VERSION', '1.0.0') +user = os.getenv('CONAN_CONCURRENTQUEUE_USER', 'Manu343726') +channel = os.getenv('CONAN_CONCURRENTQUEUE_CHANNEL', 'testing') + +class TestConcurrentQueue(ConanFile): + settings = 'os', 'compiler', 'build_type', 'arch' + requires = ( + 'concurrentqueue/{}@{}/{}'.format(version, user, channel) + ) + generators = 'cmake' + + def build(self): + cmake = CMake(self.settings) + self.run('cmake {} {}'.format(self.conanfile_directory, cmake.command_line)) + self.run('cmake --build . {}'.format(cmake.build_config)) + + def test(self): + self.run(os.path.join('.', 'bin', 'example')) diff --git a/test_package/main.cpp b/test_package/main.cpp new file mode 100644 index 00000000..51548120 --- /dev/null +++ b/test_package/main.cpp @@ -0,0 +1,53 @@ +/* + * Hello concurrency example from samples.md + */ + +#include +#include +#include + +using namespace moodycamel; + +int main() +{ + ConcurrentQueue q; + int dequeued[100] = { 0 }; + std::thread threads[20]; + + // Producers + for (int i = 0; i != 10; ++i) { + threads[i] = std::thread([&](int i) { + for (int j = 0; j != 10; ++j) { + q.enqueue(i * 10 + j); + } + }, i); + } + + // Consumers + for (int i = 10; i != 20; ++i) { + threads[i] = std::thread([&]() { + int item; + for (int j = 0; j != 20; ++j) { + if (q.try_dequeue(item)) { + ++dequeued[item]; + } + } + }); + } + + // Wait for all threads + for (int i = 0; i != 20; ++i) { + threads[i].join(); + } + + // Collect any leftovers (could be some if e.g. consumers finish before producers) + int item; + while (q.try_dequeue(item)) { + ++dequeued[item]; + } + + // Make sure everything went in and came back out! + for (int i = 0; i != 100; ++i) { + assert(dequeued[i] == 1); + } +}