Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ tests/CDSChecker/model-checker/
tests/relacy/freelist.exe
tests/relacy/spmchash.exe
tests/relacy/log.txt
test_package/build/
*.pyc
21 changes: 21 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
21 changes: 21 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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'))
53 changes: 53 additions & 0 deletions test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Hello concurrency example from samples.md
*/

#include <moodycamel/concurrentqueue.h>
#include <cassert>
#include <thread>

using namespace moodycamel;

int main()
{
ConcurrentQueue<int> 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);
}
}