summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-04-08 08:40:49 (GMT)
committerTobias Markmann <tm@ayena.de>2016-04-12 14:12:45 (GMT)
commitb9ad76af13fc1d253845e027f91f22039bf14f9c (patch)
treec70d592a6bbbaae96e818e1de92e82e53390f393 /Swiften/EventLoop
parent4e6713df2d55dc1b2970d9c3b619d2a415e1264f (diff)
downloadswift-b9ad76af13fc1d253845e027f91f22039bf14f9c.zip
swift-b9ad76af13fc1d253845e027f91f22039bf14f9c.tar.bz2
Use C++11 threading library instead of Boost.Thread
This cuts down our dependency on Boost further. Another benefit is that mutex classes of C++11 standard library are recognized by TSAN. Test-Information: Unit and integration tests pass on OS X 10.11.4. Change-Id: Id4dcdb42e3d5155e107ce1d7618acbf26f913b6f
Diffstat (limited to 'Swiften/EventLoop')
-rw-r--r--Swiften/EventLoop/BoostASIOEventLoop.cpp4
-rw-r--r--Swiften/EventLoop/BoostASIOEventLoop.h4
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEventLoop.h6
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEventLoop.mm6
-rw-r--r--Swiften/EventLoop/DummyEventLoop.cpp6
-rw-r--r--Swiften/EventLoop/DummyEventLoop.h8
-rw-r--r--Swiften/EventLoop/EventLoop.cpp15
-rw-r--r--Swiften/EventLoop/EventLoop.h6
-rw-r--r--Swiften/EventLoop/Qt/QtEventLoop.h10
-rw-r--r--Swiften/EventLoop/SimpleEventLoop.cpp6
-rw-r--r--Swiften/EventLoop/SimpleEventLoop.h8
-rw-r--r--Swiften/EventLoop/SingleThreadedEventLoop.cpp8
-rw-r--r--Swiften/EventLoop/SingleThreadedEventLoop.h9
-rw-r--r--Swiften/EventLoop/UnitTest/EventLoopTest.cpp3
-rw-r--r--Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp5
15 files changed, 53 insertions, 51 deletions
diff --git a/Swiften/EventLoop/BoostASIOEventLoop.cpp b/Swiften/EventLoop/BoostASIOEventLoop.cpp
index bab8b54..30143b9 100644
--- a/Swiften/EventLoop/BoostASIOEventLoop.cpp
+++ b/Swiften/EventLoop/BoostASIOEventLoop.cpp
@@ -20,14 +20,14 @@ BoostASIOEventLoop::~BoostASIOEventLoop() {
void BoostASIOEventLoop::handleASIOEvent() {
{
- boost::recursive_mutex::scoped_lock lock(isEventInASIOEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInASIOEventLoopMutex_);
isEventInASIOEventLoop_ = false;
}
handleNextEvents();
}
void BoostASIOEventLoop::eventPosted() {
- boost::recursive_mutex::scoped_lock lock(isEventInASIOEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInASIOEventLoopMutex_);
if (!isEventInASIOEventLoop_) {
isEventInASIOEventLoop_ = true;
ioService_->post(boost::bind(&BoostASIOEventLoop::handleASIOEvent, this));
diff --git a/Swiften/EventLoop/BoostASIOEventLoop.h b/Swiften/EventLoop/BoostASIOEventLoop.h
index 41304c4..3f74a60 100644
--- a/Swiften/EventLoop/BoostASIOEventLoop.h
+++ b/Swiften/EventLoop/BoostASIOEventLoop.h
@@ -7,9 +7,9 @@
#pragma once
#include <memory>
+#include <mutex>
#include <boost/asio/io_service.hpp>
-#include <boost/thread.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/EventLoop/Event.h>
@@ -30,6 +30,6 @@ namespace Swift {
std::shared_ptr<boost::asio::io_service> ioService_;
bool isEventInASIOEventLoop_;
- boost::recursive_mutex isEventInASIOEventLoopMutex_;
+ std::recursive_mutex isEventInASIOEventLoopMutex_;
};
}
diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.h b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h
index bbe8390..7f20e6c 100644
--- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.h
+++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/thread.hpp>
+#include <mutex>
#include <Swiften/EventLoop/EventLoop.h>
@@ -23,6 +23,6 @@ namespace Swift {
private:
bool isEventInCocoaEventLoop_;
- boost::recursive_mutex isEventInCocoaEventLoopMutex_;
+ std::recursive_mutex isEventInCocoaEventLoopMutex_;
};
}
diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm
index de7c1de..b8ab621 100644
--- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm
+++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Isode Limited.
+ * Copyright (c) 2015-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -20,14 +20,14 @@ CocoaEventLoop::~CocoaEventLoop() {
void CocoaEventLoop::handleNextCocoaEvent() {
{
- boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInCocoaEventLoopMutex_);
isEventInCocoaEventLoop_ = false;
}
handleNextEvents();
}
void CocoaEventLoop::eventPosted() {
- boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInCocoaEventLoopMutex_);
if (!isEventInCocoaEventLoop_) {
isEventInCocoaEventLoop_ = true;
diff --git a/Swiften/EventLoop/DummyEventLoop.cpp b/Swiften/EventLoop/DummyEventLoop.cpp
index 6eb730a..d47124b 100644
--- a/Swiften/EventLoop/DummyEventLoop.cpp
+++ b/Swiften/EventLoop/DummyEventLoop.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -27,12 +27,12 @@ void DummyEventLoop::processEvents() {
}
bool DummyEventLoop::hasEvents() {
- boost::lock_guard<boost::mutex> lock(hasEventsMutex_);
+ std::lock_guard<std::mutex> lock(hasEventsMutex_);
return hasEvents_;
}
void DummyEventLoop::eventPosted() {
- boost::lock_guard<boost::mutex> lock(hasEventsMutex_);
+ std::lock_guard<std::mutex> lock(hasEventsMutex_);
hasEvents_ = true;
}
diff --git a/Swiften/EventLoop/DummyEventLoop.h b/Swiften/EventLoop/DummyEventLoop.h
index b78c1a6..e411096 100644
--- a/Swiften/EventLoop/DummyEventLoop.h
+++ b/Swiften/EventLoop/DummyEventLoop.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -7,9 +7,7 @@
#pragma once
#include <deque>
-
-#include <boost/thread/locks.hpp>
-#include <boost/thread/mutex.hpp>
+#include <mutex>
#include <Swiften/Base/API.h>
#include <Swiften/EventLoop/EventLoop.h>
@@ -28,6 +26,6 @@ namespace Swift {
private:
bool hasEvents_;
- boost::mutex hasEventsMutex_;
+ std::mutex hasEventsMutex_;
};
}
diff --git a/Swiften/EventLoop/EventLoop.cpp b/Swiften/EventLoop/EventLoop.cpp
index 730ee0a..eefbf65 100644
--- a/Swiften/EventLoop/EventLoop.cpp
+++ b/Swiften/EventLoop/EventLoop.cpp
@@ -8,12 +8,12 @@
#include <algorithm>
#include <cassert>
+#include <vector>
#include <boost/bind.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/optional.hpp>
-#include <boost/thread/locks.hpp>
#include <Swiften/Base/Log.h>
#include <Swiften/Base/foreach.h>
@@ -49,11 +49,11 @@ void EventLoop::handleNextEvents() {
bool callEventPosted = handlingEvents_;
if (!handlingEvents_) {
handlingEvents_ = true;
- boost::recursive_mutex::scoped_lock lock(removeEventsMutex_);
+ std::unique_lock<std::recursive_mutex> lock(removeEventsMutex_);
{
std::vector<Event> nextEvents;
{
- boost::recursive_mutex::scoped_lock lock(eventsMutex_);
+ std::unique_lock<std::recursive_mutex> lock(eventsMutex_);
for (int n = 0; ((n < eventsBatched) && !events_.empty()); n++) {
nextEvents.push_back(events_.front());
events_.pop_front();
@@ -78,7 +78,7 @@ void EventLoop::postEvent(boost::function<void ()> callback, std::shared_ptr<Eve
Event event(owner, callback);
bool callEventPosted = false;
{
- boost::recursive_mutex::scoped_lock lock(eventsMutex_);
+ std::unique_lock<std::recursive_mutex> lock(eventsMutex_);
callEventPosted = events_.empty();
@@ -92,8 +92,11 @@ void EventLoop::postEvent(boost::function<void ()> callback, std::shared_ptr<Eve
}
void EventLoop::removeEventsFromOwner(std::shared_ptr<EventOwner> owner) {
- boost::recursive_mutex::scoped_lock removeLock(removeEventsMutex_);
- boost::recursive_mutex::scoped_lock lock(eventsMutex_);
+ std::unique_lock<std::recursive_mutex> removeLock(removeEventsMutex_, std::defer_lock);
+ std::unique_lock<std::recursive_mutex> eventsLock(eventsMutex_, std::defer_lock);
+
+ std::lock(removeLock, eventsLock);
+
events_.remove_if(lambda::bind(&Event::owner, lambda::_1) == owner);
}
diff --git a/Swiften/EventLoop/EventLoop.h b/Swiften/EventLoop/EventLoop.h
index c7f7760..282de15 100644
--- a/Swiften/EventLoop/EventLoop.h
+++ b/Swiften/EventLoop/EventLoop.h
@@ -7,9 +7,9 @@
#pragma once
#include <list>
+#include <mutex>
#include <boost/function.hpp>
-#include <boost/thread.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/EventLoop/Event.h>
@@ -65,7 +65,7 @@ namespace Swift {
unsigned int nextEventID_;
std::list<Event> events_;
bool handlingEvents_;
- boost::recursive_mutex eventsMutex_;
- boost::recursive_mutex removeEventsMutex_;
+ std::recursive_mutex eventsMutex_;
+ std::recursive_mutex removeEventsMutex_;
};
}
diff --git a/Swiften/EventLoop/Qt/QtEventLoop.h b/Swiften/EventLoop/Qt/QtEventLoop.h
index 3f5e93c..b1644c2 100644
--- a/Swiften/EventLoop/Qt/QtEventLoop.h
+++ b/Swiften/EventLoop/Qt/QtEventLoop.h
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <boost/thread.hpp>
+#include <mutex>
#include <QCoreApplication>
#include <QEvent>
@@ -24,7 +24,7 @@ namespace Swift {
protected:
virtual void eventPosted() {
- boost::recursive_mutex::scoped_lock lock(isEventInQtEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInQtEventLoopMutex_);
if (!isEventInQtEventLoop_) {
isEventInQtEventLoop_ = true;
QCoreApplication::postEvent(this, new Event());
@@ -35,7 +35,7 @@ namespace Swift {
Event* event = dynamic_cast<Event*>(qevent);
if (event) {
{
- boost::recursive_mutex::scoped_lock lock(isEventInQtEventLoopMutex_);
+ std::unique_lock<std::recursive_mutex> lock(isEventInQtEventLoopMutex_);
isEventInQtEventLoop_ = false;
}
handleNextEvents();
@@ -54,6 +54,6 @@ namespace Swift {
};
bool isEventInQtEventLoop_;
- boost::recursive_mutex isEventInQtEventLoopMutex_;
+ std::recursive_mutex isEventInQtEventLoopMutex_;
};
}
diff --git a/Swiften/EventLoop/SimpleEventLoop.cpp b/Swiften/EventLoop/SimpleEventLoop.cpp
index 37fecd9..2397016 100644
--- a/Swiften/EventLoop/SimpleEventLoop.cpp
+++ b/Swiften/EventLoop/SimpleEventLoop.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -21,7 +21,7 @@ SimpleEventLoop::~SimpleEventLoop() {
void SimpleEventLoop::doRun(bool breakAfterEvents) {
while (isRunning_) {
{
- boost::unique_lock<boost::mutex> lock(eventAvailableMutex_);
+ std::unique_lock<std::mutex> lock(eventAvailableMutex_);
while (!eventAvailable_) {
eventAvailableCondition_.wait(lock);
}
@@ -49,7 +49,7 @@ void SimpleEventLoop::doStop() {
void SimpleEventLoop::eventPosted() {
{
- boost::unique_lock<boost::mutex> lock(eventAvailableMutex_);
+ std::unique_lock<std::mutex> lock(eventAvailableMutex_);
eventAvailable_ = true;
}
eventAvailableCondition_.notify_one();
diff --git a/Swiften/EventLoop/SimpleEventLoop.h b/Swiften/EventLoop/SimpleEventLoop.h
index 98b3554..fe5f509 100644
--- a/Swiften/EventLoop/SimpleEventLoop.h
+++ b/Swiften/EventLoop/SimpleEventLoop.h
@@ -6,8 +6,8 @@
#pragma once
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
+#include <condition_variable>
+#include <mutex>
#include <Swiften/Base/API.h>
#include <Swiften/EventLoop/EventLoop.h>
@@ -41,7 +41,7 @@ namespace Swift {
bool isRunning_;
bool eventAvailable_;
- boost::mutex eventAvailableMutex_;
- boost::condition_variable eventAvailableCondition_;
+ std::mutex eventAvailableMutex_;
+ std::condition_variable eventAvailableCondition_;
};
}
diff --git a/Swiften/EventLoop/SingleThreadedEventLoop.cpp b/Swiften/EventLoop/SingleThreadedEventLoop.cpp
index 093b913..acb6e4d 100644
--- a/Swiften/EventLoop/SingleThreadedEventLoop.cpp
+++ b/Swiften/EventLoop/SingleThreadedEventLoop.cpp
@@ -30,7 +30,7 @@ SingleThreadedEventLoop::~SingleThreadedEventLoop() {
}
void SingleThreadedEventLoop::waitForEvents() {
- boost::unique_lock<boost::mutex> lock(eventAvailableMutex_);
+ std::unique_lock<std::mutex> lock(eventAvailableMutex_);
while (!eventAvailable_ && !shouldShutDown_) {
eventAvailableCondition_.wait(lock);
}
@@ -41,20 +41,20 @@ void SingleThreadedEventLoop::waitForEvents() {
void SingleThreadedEventLoop::handleEvents() {
{
- boost::lock_guard<boost::mutex> lock(eventAvailableMutex_);
+ std::lock_guard<std::mutex> lock(eventAvailableMutex_);
eventAvailable_ = false;
}
handleNextEvents();
}
void SingleThreadedEventLoop::stop() {
- boost::unique_lock<boost::mutex> lock(eventAvailableMutex_);
+ std::unique_lock<std::mutex> lock(eventAvailableMutex_);
shouldShutDown_ = true;
eventAvailableCondition_.notify_one();
}
void SingleThreadedEventLoop::eventPosted() {
- boost::lock_guard<boost::mutex> lock(eventAvailableMutex_);
+ std::lock_guard<std::mutex> lock(eventAvailableMutex_);
eventAvailable_ = true;
eventAvailableCondition_.notify_one();
}
diff --git a/Swiften/EventLoop/SingleThreadedEventLoop.h b/Swiften/EventLoop/SingleThreadedEventLoop.h
index eb897bf..9f8cb0a 100644
--- a/Swiften/EventLoop/SingleThreadedEventLoop.h
+++ b/Swiften/EventLoop/SingleThreadedEventLoop.h
@@ -12,11 +12,10 @@
#pragma once
+#include <condition_variable>
+#include <mutex>
#include <vector>
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
-
#include <Swiften/EventLoop/EventLoop.h>
// DESCRIPTION:
@@ -61,7 +60,7 @@ namespace Swift {
bool shouldShutDown_;
bool eventAvailable_;
- boost::mutex eventAvailableMutex_;
- boost::condition_variable eventAvailableCondition_;
+ std::mutex eventAvailableMutex_;
+ std::condition_variable eventAvailableCondition_;
};
}
diff --git a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
index 55715d0..00a4376 100644
--- a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
+++ b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
@@ -4,8 +4,9 @@
* See the COPYING file for more information.
*/
+#include <thread>
+
#include <boost/bind.hpp>
-#include <boost/thread.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
diff --git a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
index 167fe45..3d096d3 100644
--- a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
+++ b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
@@ -4,8 +4,9 @@
* See the COPYING file for more information.
*/
+#include <thread>
+
#include <boost/bind.hpp>
-#include <boost/thread.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -30,7 +31,7 @@ class SimpleEventLoopTest : public CppUnit::TestFixture {
void testRun() {
SimpleEventLoop testling;
- boost::thread thread(boost::bind(&SimpleEventLoopTest::runIncrementingThread, this, &testling));
+ std::thread thread(boost::bind(&SimpleEventLoopTest::runIncrementingThread, this, &testling));
testling.run();
CPPUNIT_ASSERT_EQUAL(10, counter_);