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/Network
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/Network')
-rw-r--r--Swiften/Network/BOSHConnection.cpp2
-rw-r--r--Swiften/Network/BoostConnection.cpp12
-rw-r--r--Swiften/Network/BoostConnection.h6
-rw-r--r--Swiften/Network/BoostIOServiceThread.cpp4
-rw-r--r--Swiften/Network/BoostIOServiceThread.h4
-rw-r--r--Swiften/Network/BoostTimer.cpp8
-rw-r--r--Swiften/Network/BoostTimer.h4
-rw-r--r--Swiften/Network/PlatformDomainNameResolver.cpp21
-rw-r--r--Swiften/Network/PlatformDomainNameResolver.h15
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.cpp10
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.h12
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnection.cpp2
12 files changed, 50 insertions, 50 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index 757b1db..1c468f1 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -13,10 +13,10 @@
#include <Swiften/Network/BOSHConnection.h>
#include <string>
+#include <thread>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
-#include <boost/thread.hpp>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Base/Concat.h>
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index a987790..0de7b25 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -8,13 +8,13 @@
#include <algorithm>
#include <memory>
+#include <mutex>
#include <string>
#include <boost/asio/placeholders.hpp>
#include <boost/asio/write.hpp>
#include <boost/bind.hpp>
#include <boost/numeric/conversion/cast.hpp>
-#include <boost/thread.hpp>
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/ByteArray.h>
@@ -76,7 +76,7 @@ void BoostConnection::disconnect() {
// Mac OS X apparently exhibits a problem where closing a socket during a write could potentially go into uninterruptable sleep.
// See e.g. http://bugs.python.org/issue7401
// We therefore wait until any pending write finishes, which hopefully should fix our hang on exit during close().
- boost::lock_guard<boost::mutex> lock(writeMutex_);
+ std::lock_guard<std::mutex> lock(writeMutex_);
if (writing_) {
closeSocketAfterNextWrite_ = true;
} else {
@@ -85,14 +85,14 @@ void BoostConnection::disconnect() {
}
void BoostConnection::closeSocket() {
- boost::lock_guard<boost::mutex> lock(readCloseMutex_);
+ std::lock_guard<std::mutex> lock(readCloseMutex_);
boost::system::error_code errorCode;
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode);
socket_.close();
}
void BoostConnection::write(const SafeByteArray& data) {
- boost::lock_guard<boost::mutex> lock(writeMutex_);
+ std::lock_guard<std::mutex> lock(writeMutex_);
if (!writing_) {
writing_ = true;
doWrite(data);
@@ -120,7 +120,7 @@ void BoostConnection::handleConnectFinished(const boost::system::error_code& err
void BoostConnection::doRead() {
readBuffer_ = std::make_shared<SafeByteArray>(BUFFER_SIZE);
- boost::lock_guard<boost::mutex> lock(readCloseMutex_);
+ std::lock_guard<std::mutex> lock(readCloseMutex_);
socket_.async_read_some(
boost::asio::buffer(*readBuffer_),
boost::bind(&BoostConnection::handleSocketRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
@@ -153,7 +153,7 @@ void BoostConnection::handleDataWritten(const boost::system::error_code& error)
eventLoop->postEvent(boost::bind(boost::ref(onDisconnected), WriteError), shared_from_this());
}
{
- boost::lock_guard<boost::mutex> lock(writeMutex_);
+ std::lock_guard<std::mutex> lock(writeMutex_);
if (writeQueue_.empty()) {
writing_ = false;
if (closeSocketAfterNextWrite_) {
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index 82208a1..03122da 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -7,10 +7,10 @@
#pragma once
#include <memory>
+#include <mutex>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
-#include <boost/thread/mutex.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/Base/SafeByteArray.h>
@@ -73,10 +73,10 @@ namespace Swift {
std::shared_ptr<boost::asio::io_service> ioService;
boost::asio::ip::tcp::socket socket_;
std::shared_ptr<SafeByteArray> readBuffer_;
- boost::mutex writeMutex_;
+ std::mutex writeMutex_;
bool writing_;
SafeByteArray writeQueue_;
bool closeSocketAfterNextWrite_;
- boost::mutex readCloseMutex_;
+ std::mutex readCloseMutex_;
};
}
diff --git a/Swiften/Network/BoostIOServiceThread.cpp b/Swiften/Network/BoostIOServiceThread.cpp
index 0b0b7a4..756e660 100644
--- a/Swiften/Network/BoostIOServiceThread.cpp
+++ b/Swiften/Network/BoostIOServiceThread.cpp
@@ -8,6 +8,8 @@
#include <memory>
+#include <boost/bind.hpp>
+
namespace Swift {
BoostIOServiceThread::BoostIOServiceThread(std::shared_ptr<boost::asio::io_service> ioService) {
@@ -17,7 +19,7 @@ BoostIOServiceThread::BoostIOServiceThread(std::shared_ptr<boost::asio::io_servi
}
else {
ioService_ = std::make_shared<boost::asio::io_service>();
- thread_ = new boost::thread(boost::bind(&BoostIOServiceThread::doRun, this));
+ thread_ = new std::thread(boost::bind(&BoostIOServiceThread::doRun, this));
}
}
diff --git a/Swiften/Network/BoostIOServiceThread.h b/Swiften/Network/BoostIOServiceThread.h
index 18d5a5b..b9183fd 100644
--- a/Swiften/Network/BoostIOServiceThread.h
+++ b/Swiften/Network/BoostIOServiceThread.h
@@ -7,9 +7,9 @@
#pragma once
#include <memory>
+#include <thread>
#include <boost/asio/io_service.hpp>
-#include <boost/thread/thread.hpp>
#include <Swiften/Base/API.h>
@@ -36,6 +36,6 @@ namespace Swift {
private:
std::shared_ptr<boost::asio::io_service> ioService_;
- boost::thread* thread_;
+ std::thread* thread_;
};
}
diff --git a/Swiften/Network/BoostTimer.cpp b/Swiften/Network/BoostTimer.cpp
index 846192c..a177504 100644
--- a/Swiften/Network/BoostTimer.cpp
+++ b/Swiften/Network/BoostTimer.cpp
@@ -21,14 +21,14 @@ BoostTimer::BoostTimer(int milliseconds, std::shared_ptr<boost::asio::io_service
BoostTimer::~BoostTimer() {
{
- boost::mutex::scoped_lock lockTimer(timerMutex);
+ std::unique_lock<std::mutex> lockTimer(timerMutex);
timer.reset();
}
}
void BoostTimer::start() {
{
- boost::mutex::scoped_lock lockTimer(timerMutex);
+ std::unique_lock<std::mutex> lockTimer(timerMutex);
shuttingDown = false;
timer->expires_from_now(boost::posix_time::milliseconds(timeout));
timer->async_wait(boost::bind(&BoostTimer::handleTimerTick, shared_from_this(), boost::asio::placeholders::error));
@@ -37,7 +37,7 @@ void BoostTimer::start() {
void BoostTimer::stop() {
{
- boost::mutex::scoped_lock lockTimer(timerMutex);
+ std::unique_lock<std::mutex> lockTimer(timerMutex);
shuttingDown = true;
timer->cancel();
eventLoop->removeEventsFromOwner(shared_from_this());
@@ -50,7 +50,7 @@ void BoostTimer::handleTimerTick(const boost::system::error_code& error) {
}
else {
{
- boost::mutex::scoped_lock lockTimer(timerMutex);
+ std::unique_lock<std::mutex> lockTimer(timerMutex);
if (shuttingDown) {
return;
}
diff --git a/Swiften/Network/BoostTimer.h b/Swiften/Network/BoostTimer.h
index c54b401..68ae28c 100644
--- a/Swiften/Network/BoostTimer.h
+++ b/Swiften/Network/BoostTimer.h
@@ -7,11 +7,11 @@
#pragma once
#include <memory>
+#include <mutex>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/scoped_ptr.hpp>
-#include <boost/thread/mutex.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/EventLoop/EventOwner.h>
@@ -42,7 +42,7 @@ namespace Swift {
int timeout;
std::shared_ptr<boost::asio::io_service> ioService;
boost::scoped_ptr<boost::asio::deadline_timer> timer;
- boost::mutex timerMutex;
+ std::mutex timerMutex;
EventLoop* eventLoop;
bool shuttingDown;
};
diff --git a/Swiften/Network/PlatformDomainNameResolver.cpp b/Swiften/Network/PlatformDomainNameResolver.cpp
index ecb5247..40e385d 100644
--- a/Swiften/Network/PlatformDomainNameResolver.cpp
+++ b/Swiften/Network/PlatformDomainNameResolver.cpp
@@ -6,29 +6,28 @@
#include <Swiften/Network/PlatformDomainNameResolver.h>
-// Putting this early on, because some system types conflict with thread
-#include <Swiften/Network/PlatformDomainNameServiceQuery.h>
-
+#include <algorithm>
+#include <mutex>
#include <string>
+#include <thread>
#include <vector>
+
#include <boost/bind.hpp>
-#include <boost/thread.hpp>
-#include <algorithm>
-#include <string>
+#include <Swiften/EventLoop/EventLoop.h>
#include <Swiften/IDN/IDNConverter.h>
+#include <Swiften/Network/DomainNameAddressQuery.h>
#include <Swiften/Network/HostAddress.h>
-#include <Swiften/EventLoop/EventLoop.h>
#include <Swiften/Network/HostAddressPort.h>
-#include <Swiften/Network/DomainNameAddressQuery.h>
#include <Swiften/Network/PlatformDomainNameAddressQuery.h>
+#include <Swiften/Network/PlatformDomainNameServiceQuery.h>
using namespace Swift;
namespace Swift {
PlatformDomainNameResolver::PlatformDomainNameResolver(IDNConverter* idnConverter, EventLoop* eventLoop) : idnConverter(idnConverter), eventLoop(eventLoop), stopRequested(false) {
- thread = new boost::thread(boost::bind(&PlatformDomainNameResolver::run, this));
+ thread = new std::thread(boost::bind(&PlatformDomainNameResolver::run, this));
}
PlatformDomainNameResolver::~PlatformDomainNameResolver() {
@@ -55,7 +54,7 @@ void PlatformDomainNameResolver::run() {
while (!stopRequested) {
PlatformDomainNameQuery::ref query;
{
- boost::unique_lock<boost::mutex> lock(queueMutex);
+ std::unique_lock<std::mutex> lock(queueMutex);
while (queue.empty()) {
queueNonEmpty.wait(lock);
}
@@ -72,7 +71,7 @@ void PlatformDomainNameResolver::run() {
void PlatformDomainNameResolver::addQueryToQueue(PlatformDomainNameQuery::ref query) {
{
- boost::lock_guard<boost::mutex> lock(queueMutex);
+ std::lock_guard<std::mutex> lock(queueMutex);
queue.push_back(query);
}
queueNonEmpty.notify_one();
diff --git a/Swiften/Network/PlatformDomainNameResolver.h b/Swiften/Network/PlatformDomainNameResolver.h
index 95fa502..4ddb999 100644
--- a/Swiften/Network/PlatformDomainNameResolver.h
+++ b/Swiften/Network/PlatformDomainNameResolver.h
@@ -1,16 +1,15 @@
/*
- * 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 <condition_variable>
#include <deque>
-
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
+#include <mutex>
+#include <thread>
#include <Swiften/Base/API.h>
#include <Swiften/Base/Atomic.h>
@@ -41,9 +40,9 @@ namespace Swift {
IDNConverter* idnConverter;
EventLoop* eventLoop;
Atomic<bool> stopRequested;
- boost::thread* thread;
+ std::thread* thread;
std::deque<PlatformDomainNameQuery::ref> queue;
- boost::mutex queueMutex;
- boost::condition_variable queueNonEmpty;
+ std::mutex queueMutex;
+ std::condition_variable queueNonEmpty;
};
}
diff --git a/Swiften/Network/PlatformNATTraversalWorker.cpp b/Swiften/Network/PlatformNATTraversalWorker.cpp
index 9b5ec2b..f56de0b 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.cpp
+++ b/Swiften/Network/PlatformNATTraversalWorker.cpp
@@ -10,10 +10,10 @@
* See the COPYING file for more information.
*/
-#include "PlatformNATTraversalWorker.h"
+#include <Swiften/Network/PlatformNATTraversalWorker.h>
#include <memory>
-#include <memory>
+
#include <boost/numeric/conversion/cast.hpp>
#include <Swiften/Base/Log.h>
@@ -134,7 +134,7 @@ class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemov
PlatformNATTraversalWorker::PlatformNATTraversalWorker(EventLoop* eventLoop) : eventLoop(eventLoop), stopRequested(false), natPMPSupported(boost::logic::indeterminate), natPMPInterface(nullptr), miniUPnPSupported(boost::logic::indeterminate), miniUPnPInterface(nullptr) {
nullNATTraversalInterface = new NullNATTraversalInterface();
// FIXME: This should be done from start(), and the current start() should be an internal method
- thread = new boost::thread(boost::bind(&PlatformNATTraversalWorker::start, this));
+ thread = new std::thread(boost::bind(&PlatformNATTraversalWorker::start, this));
}
PlatformNATTraversalWorker::~PlatformNATTraversalWorker() {
@@ -194,7 +194,7 @@ void PlatformNATTraversalWorker::start() {
while (!stopRequested) {
PlatformNATTraversalRequest::ref request;
{
- boost::unique_lock<boost::mutex> lock(queueMutex);
+ std::unique_lock<std::mutex> lock(queueMutex);
while (queue.empty()) {
queueNonEmpty.wait(lock);
}
@@ -215,7 +215,7 @@ void PlatformNATTraversalWorker::stop() {
void PlatformNATTraversalWorker::addRequestToQueue(PlatformNATTraversalRequest::ref request) {
{
- boost::lock_guard<boost::mutex> lock(queueMutex);
+ std::lock_guard<std::mutex> lock(queueMutex);
queue.push_back(request);
}
queueNonEmpty.notify_one();
diff --git a/Swiften/Network/PlatformNATTraversalWorker.h b/Swiften/Network/PlatformNATTraversalWorker.h
index 35f4ea6..3607dac 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.h
+++ b/Swiften/Network/PlatformNATTraversalWorker.h
@@ -12,13 +12,13 @@
#pragma once
+#include <condition_variable>
#include <deque>
+#include <mutex>
+#include <thread>
#include <boost/logic/tribool.hpp>
#include <boost/optional.hpp>
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/Base/Atomic.h>
@@ -61,10 +61,10 @@ namespace Swift {
private:
EventLoop* eventLoop;
Atomic<bool> stopRequested;
- boost::thread* thread;
+ std::thread* thread;
std::deque<std::shared_ptr<PlatformNATTraversalRequest> > queue;
- boost::mutex queueMutex;
- boost::condition_variable queueNonEmpty;
+ std::mutex queueMutex;
+ std::condition_variable queueNonEmpty;
NullNATTraversalInterface* nullNATTraversalInterface;
mutable boost::logic::tribool natPMPSupported;
diff --git a/Swiften/Network/SOCKS5ProxiedConnection.cpp b/Swiften/Network/SOCKS5ProxiedConnection.cpp
index 67ef4ad..ab678af 100644
--- a/Swiften/Network/SOCKS5ProxiedConnection.cpp
+++ b/Swiften/Network/SOCKS5ProxiedConnection.cpp
@@ -13,9 +13,9 @@
#include <Swiften/Network/SOCKS5ProxiedConnection.h>
#include <iostream>
+#include <thread>
#include <boost/bind.hpp>
-#include <boost/thread.hpp>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Base/Log.h>