From 123ea0e49d927574fdab1ea3916764a2adb1bcee Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sun, 5 Jan 2014 17:43:33 -0500 Subject: [PATCH] OSC: port concurrentqueue to Qt. Fix duplicate OSC messages --- MainWindow.cpp | 5 +++-- OscInterface.cpp | 4 ++-- concurrentqueue.h | 25 ++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 5a273b1..4b731e2 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -709,9 +709,10 @@ void MainWindow::pollOscInterface() void MainWindow::applyOscCommand(QVariantList & command) { bool VERBOSE = true; + if (VERBOSE) { - std::cout << "Receive OSC: "; + std::cout << "MainWindow::applyOscCommand: Receive OSC: "; for (int i = 0; i < command.size(); ++i) { if (command.at(i).type() == QVariant::Int) @@ -728,7 +729,7 @@ void MainWindow::applyOscCommand(QVariantList & command) } else { - std::cout << "??? "; + std::cout << "(?) "; } } std::cout << std::endl; diff --git a/OscInterface.cpp b/OscInterface.cpp index 32fc26a..fd5e728 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -35,7 +35,7 @@ OscInterface::OscInterface( receiving_enabled_ = true; if (receiving_enabled_) { - std::cout << "Listening osc_udp://localhost:" << listen_port << std::endl; + std::cout << "Listening osc.udp://localhost:" << listen_port << std::endl; // receiver_.addHandler("/ping", "", ping_cb, this); // receiver_.addHandler("/pong", "", pong_cb, this); // receiver_.addHandler("/image/path", "s", image_path_cb, this); @@ -170,7 +170,7 @@ int OscInterface::genericHandler(const char *path, default: break; } - context->push_command(message); } + context->push_command(message); return 0; // handled } diff --git a/concurrentqueue.h b/concurrentqueue.h index 18f3f68..4f5dfc7 100644 --- a/concurrentqueue.h +++ b/concurrentqueue.h @@ -29,38 +29,37 @@ #define _CONCURRENT_QUEUE_H_ #include -#include -#include +#include +#include template class ConcurrentQueue { private: std::queue queue_; - mutable boost::mutex mutex_; - boost::condition_variable condition_; + QMutex mutex_; + QWaitCondition condition_; public: ConcurrentQueue() : queue_(), mutex_(), condition_() {} void push(Data const& data) { - boost::mutex::scoped_lock lock(mutex_); + QMutexLocker locker(&mutex_); queue_.push(data); - lock.unlock(); - condition_.notify_one(); + condition_.wakeOne(); } bool empty() const { - boost::mutex::scoped_lock lock(mutex_); + QMutexLocker locker(&mutex_); return queue_.empty(); } bool try_pop(Data& popped_value) { - boost::mutex::scoped_lock lock(mutex_); - if(queue_.empty()) + QMutexLocker locker(&mutex_); + if (queue_.empty()) { return false; } @@ -72,10 +71,10 @@ class ConcurrentQueue void wait_and_pop(Data& popped_value) { - boost::mutex::scoped_lock lock(mutex_); - while(queue_.empty()) + QMutexLocker locker(&mutex_); + while (queue_.empty()) { - condition_.wait(lock); + condition_.wait(&mutex_); } popped_value = queue_.front();