diff options
44 files changed, 143 insertions, 160 deletions
diff --git a/3rdParty/Boost/SConscript b/3rdParty/Boost/SConscript index 6172777..6d04c0d 100644 --- a/3rdParty/Boost/SConscript +++ b/3rdParty/Boost/SConscript @@ -69,7 +69,6 @@ elif env.get("BOOST_BUNDLED", False) : "src/libs/date_time/src/gregorian/gregorian_types.cpp", "src/libs/date_time/src/posix_time/posix_time_types.cpp", "src/libs/system/src/error_code.cpp", - "src/libs/thread/src/tss_null.cpp", "src/libs/filesystem/src/codecvt_error_category.cpp", "src/libs/filesystem/src/operations.cpp", "src/libs/filesystem/src/path.cpp", @@ -149,18 +148,6 @@ elif env.get("BOOST_BUNDLED", False) : "src/libs/program_options/src/parsers.cpp", ] - if env["PLATFORM"] != "win32" : - sources += [ - "src/libs/thread/src/pthread/once.cpp", - "src/libs/thread/src/pthread/once_atomic.cpp", - "src/libs/thread/src/pthread/thread.cpp"] - else : - sources += [ - "win32_stubs.cpp", - "src/libs/thread/src/win32/thread.cpp", - "src/libs/thread/src/win32/tss_dll.cpp", - "src/libs/thread/src/win32/tss_pe.cpp"] - myenv.MergeFlags(myenv["BOOST_FLAGS"]) myenv.StaticLibrary("Swiften_Boost", sources) diff --git a/Sluift/main.cpp b/Sluift/main.cpp index 85fa17d..05c7179 100644 --- a/Sluift/main.cpp +++ b/Sluift/main.cpp @@ -6,6 +6,7 @@ #include <string> #include <vector> +#include <iostream> #include <lua.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Base/Platform.h> diff --git a/Swiften/Base/Atomic.h b/Swiften/Base/Atomic.h index 9640500..ae065d4 100644 --- a/Swiften/Base/Atomic.h +++ b/Swiften/Base/Atomic.h @@ -1,13 +1,12 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/thread.hpp> -#include <boost/thread/locks.hpp> +#include <mutex> namespace Swift { @@ -24,7 +23,7 @@ class Atomic { * Synchronized write access. */ Atomic<ValueType>& operator=(const ValueType& newValue) { - boost::lock_guard<boost::mutex> lock(valueMutex_); + std::lock_guard<std::mutex> lock(valueMutex_); value_ = newValue; return *this; } @@ -33,12 +32,12 @@ class Atomic { * Synchronized read access. */ operator ValueType() { - boost::lock_guard<boost::mutex> lock(valueMutex_); + std::lock_guard<std::mutex> lock(valueMutex_); return value_; } private: - boost::mutex valueMutex_; + std::mutex valueMutex_; ValueType value_; }; diff --git a/Swiften/Base/sleep.cpp b/Swiften/Base/sleep.cpp index 5a0d729..48eae51 100644 --- a/Swiften/Base/sleep.cpp +++ b/Swiften/Base/sleep.cpp @@ -1,25 +1,18 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Base/sleep.h> -#include <boost/thread.hpp> -#include <boost/version.hpp> +#include <chrono> +#include <thread> namespace Swift { void sleep(unsigned int msecs) { - boost::xtime xt; -#if BOOST_VERSION >= 105000 - boost::xtime_get(&xt, boost::TIME_UTC_); -#else - boost::xtime_get(&xt, boost::TIME_UTC); -#endif - xt.nsec += msecs*1000000; - boost::thread::sleep(xt); + std::this_thread::sleep_for(std::chrono::milliseconds(msecs)); } } 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_); diff --git a/Swiften/Examples/BenchTool/BenchTool.cpp b/Swiften/Examples/BenchTool/BenchTool.cpp index d56baed..97d760d 100644 --- a/Swiften/Examples/BenchTool/BenchTool.cpp +++ b/Swiften/Examples/BenchTool/BenchTool.cpp @@ -5,9 +5,9 @@ */ #include <iostream> +#include <thread> #include <boost/bind.hpp> -#include <boost/thread.hpp> #include <Swiften/Base/sleep.h> #include <Swiften/Client/Client.h> diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp index 8c2df38..607038f 100644 --- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp +++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp @@ -5,9 +5,9 @@ */ #include <iostream> +#include <thread> #include <boost/bind.hpp> -#include <boost/thread.hpp> #include <Swiften/Client/Client.h> #include <Swiften/Client/ClientXMLTracer.h> diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp index 87e595d..0b46b41 100644 --- a/Swiften/Examples/SendMessage/SendMessage.cpp +++ b/Swiften/Examples/SendMessage/SendMessage.cpp @@ -5,9 +5,9 @@ */ #include <iostream> +#include <thread> #include <boost/bind.hpp> -#include <boost/thread.hpp> #include <Swiften/Client/Client.h> #include <Swiften/Client/ClientXMLTracer.h> diff --git a/Swiften/History/SQLiteHistoryStorage.cpp b/Swiften/History/SQLiteHistoryStorage.cpp index d5ef8ad..ed15a2a 100644 --- a/Swiften/History/SQLiteHistoryStorage.cpp +++ b/Swiften/History/SQLiteHistoryStorage.cpp @@ -30,7 +30,7 @@ inline std::string getEscapedString(const std::string& s) { namespace Swift { SQLiteHistoryStorage::SQLiteHistoryStorage(const boost::filesystem::path& file) : db_(nullptr) { - thread_ = new boost::thread(boost::bind(&SQLiteHistoryStorage::run, this)); + thread_ = new std::thread(boost::bind(&SQLiteHistoryStorage::run, this)); sqlite3_open(pathToString(file).c_str(), &db_); if (!db_) { diff --git a/Swiften/History/SQLiteHistoryStorage.h b/Swiften/History/SQLiteHistoryStorage.h index b0223f5..57f0d35 100644 --- a/Swiften/History/SQLiteHistoryStorage.h +++ b/Swiften/History/SQLiteHistoryStorage.h @@ -6,9 +6,10 @@ #pragma once +#include <thread> + #include <boost/filesystem/path.hpp> #include <boost/optional.hpp> -#include <boost/thread.hpp> #include <Swiften/Base/API.h> #include <Swiften/History/HistoryStorage.h> @@ -38,6 +39,6 @@ namespace Swift { boost::optional<long long> getIDFromJID(const JID& jid) const; sqlite3* db_; - boost::thread* thread_; + std::thread* thread_; }; } diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index c7abe45..6825443 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -12,7 +12,7 @@ #include <string> #ifdef SWIFTEN_CACHE_JID_PREP -#include <boost/thread/mutex.hpp> +#include <mutex> #include <boost/unordered_map.hpp> #endif #include <boost/assign/list_of.hpp> @@ -35,7 +35,7 @@ using namespace Swift; #ifdef SWIFTEN_CACHE_JID_PREP typedef boost::unordered_map<std::string, std::string> PrepCache; -static boost::mutex namePrepCacheMutex; +static std::mutex namePrepCacheMutex; static PrepCache nodePrepCache; static PrepCache domainPrepCache; static PrepCache resourcePrepCache; @@ -189,7 +189,7 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep); resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep); #else - boost::mutex::scoped_lock lock(namePrepCacheMutex); + std::unique_lock<std::mutex> lock(namePrepCacheMutex); std::pair<PrepCache::iterator, bool> r; diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp index e6d8b94..9cfe3cd 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp @@ -51,7 +51,7 @@ std::shared_ptr<DNSSDResolveHostnameQuery> BonjourQuerier::createResolveHostname void BonjourQuerier::addRunningQuery(std::shared_ptr<BonjourQuery> query) { { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); + std::lock_guard<std::mutex> lock(runningQueriesMutex); runningQueries.push_back(query); } runningQueriesAvailableEvent.notify_one(); @@ -60,7 +60,7 @@ void BonjourQuerier::addRunningQuery(std::shared_ptr<BonjourQuery> query) { void BonjourQuerier::removeRunningQuery(std::shared_ptr<BonjourQuery> query) { { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); + std::lock_guard<std::mutex> lock(runningQueriesMutex); erase(runningQueries, query); } } @@ -72,7 +72,7 @@ void BonjourQuerier::interruptSelect() { void BonjourQuerier::start() { assert(!thread); - thread = new boost::thread(boost::bind(&BonjourQuerier::run, shared_from_this())); + thread = new std::thread(boost::bind(&BonjourQuerier::run, shared_from_this())); } void BonjourQuerier::stop() { @@ -93,7 +93,7 @@ void BonjourQuerier::run() { fd_set fdSet; int maxSocket; { - boost::unique_lock<boost::mutex> lock(runningQueriesMutex); + std::unique_lock<std::mutex> lock(runningQueriesMutex); if (runningQueries.empty()) { runningQueriesAvailableEvent.wait(lock); if (runningQueries.empty()) { @@ -123,7 +123,7 @@ void BonjourQuerier::run() { } { - boost::lock_guard<boost::mutex> lock(runningQueriesMutex); + std::lock_guard<std::mutex> lock(runningQueriesMutex); foreach(std::shared_ptr<BonjourQuery> query, runningQueries) { if (FD_ISSET(query->getSocketID(), &fdSet)) { query->processResult(); diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index 199eeb2..77326bc 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h @@ -8,9 +8,8 @@ #include <list> #include <memory> - -#include <boost/thread/mutex.hpp> -#include <boost/thread/thread.hpp> +#include <mutex> +#include <thread> #include <Swiften/Base/ByteArray.h> #include <Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h> @@ -46,11 +45,11 @@ namespace Swift { private: EventLoop* eventLoop; bool stopRequested; - boost::thread* thread; - boost::mutex runningQueriesMutex; + std::thread* thread; + std::mutex runningQueriesMutex; std::list< std::shared_ptr<BonjourQuery> > runningQueries; int interruptSelectReadSocket; int interruptSelectWriteSocket; - boost::condition_variable runningQueriesAvailableEvent; + std::condition_variable runningQueriesAvailableEvent; }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp index 5f9a98f..b4448c7 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.cpp @@ -18,12 +18,12 @@ BonjourQuery::~BonjourQuery() { } void BonjourQuery::processResult() { - boost::lock_guard<boost::mutex> lock(sdRefMutex); + std::lock_guard<std::mutex> lock(sdRefMutex); DNSServiceProcessResult(sdRef); } int BonjourQuery::getSocketID() const { - boost::lock_guard<boost::mutex> lock(sdRefMutex); + std::lock_guard<std::mutex> lock(sdRefMutex); return DNSServiceRefSockFD(sdRef); } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h index 5520158..d3cebe4 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h @@ -7,8 +7,7 @@ #pragma once #include <memory> - -#include <boost/thread/mutex.hpp> +#include <mutex> #include <dns_sd.h> @@ -35,7 +34,7 @@ namespace Swift { protected: EventLoop* eventLoop; std::shared_ptr<BonjourQuerier> querier; - mutable boost::mutex sdRefMutex; + mutable std::mutex sdRefMutex; DNSServiceRef sdRef; }; } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h index 776b434..8b2e955 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h @@ -6,8 +6,9 @@ #pragma once +#include <mutex> + #include <boost/numeric/conversion/cast.hpp> -#include <boost/thread.hpp> #include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventLoop.h> @@ -43,7 +44,7 @@ namespace Swift { } void updateServiceInfo(const ByteArray& txtRecord) { - boost::lock_guard<boost::mutex> lock(sdRefMutex); + std::lock_guard<std::mutex> lock(sdRefMutex); DNSServiceUpdateRecord(sdRef, nullptr, 0, boost::numeric_cast<unsigned short>(txtRecord.size()), vecptr(txtRecord), 0); } 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> diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp index 9684234..5cb1765 100644 --- a/Swiften/QA/ClientTest/ClientTest.cpp +++ b/Swiften/QA/ClientTest/ClientTest.cpp @@ -5,9 +5,9 @@ */ #include <iostream> +#include <thread> #include <boost/bind.hpp> -#include <boost/thread.hpp> #include <Swiften/Client/Client.h> #include <Swiften/Client/ClientXMLTracer.h> diff --git a/Swiften/QA/ReconnectTest/ReconnectTest.cpp b/Swiften/QA/ReconnectTest/ReconnectTest.cpp index 27c7e23..af3369c 100644 --- a/Swiften/QA/ReconnectTest/ReconnectTest.cpp +++ b/Swiften/QA/ReconnectTest/ReconnectTest.cpp @@ -4,8 +4,9 @@ * See the COPYING file for more information. */ +#include <thread> + #include <boost/bind.hpp> -#include <boost/thread.hpp> #include <Swiften/Client/Client.h> #include <Swiften/Client/ClientXMLTracer.h> |