diff options
author | Tobias Markmann <tm@ayena.de> | 2016-04-08 08:40:49 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-04-12 14:12:45 (GMT) |
commit | b9ad76af13fc1d253845e027f91f22039bf14f9c (patch) | |
tree | c70d592a6bbbaae96e818e1de92e82e53390f393 /Swiften/EventLoop/EventLoop.cpp | |
parent | 4e6713df2d55dc1b2970d9c3b619d2a415e1264f (diff) | |
download | swift-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/EventLoop.cpp')
-rw-r--r-- | Swiften/EventLoop/EventLoop.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
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); } |