remove mutex from tracker_manager (#690)

remove mutex from tracker_manager
This commit is contained in:
Arvid Norberg 2016-05-02 22:22:13 -04:00
parent 045e9316ad
commit f56c1f8b2f
6 changed files with 20 additions and 23 deletions

View File

@ -41,7 +41,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <list>
#include <utility>
#include <mutex>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
@ -66,6 +65,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service.hpp"
#include "libtorrent/aux_/array_view.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/debug.hpp"
namespace libtorrent
{
@ -274,9 +274,6 @@ namespace libtorrent
int m_completion_timeout;
// TODO: 3 is this object really accessed from multiple threads?
mutable std::mutex m_mutex;
// used for timeouts
// this is set when the request has been sent
time_point m_start_time;
@ -339,6 +336,7 @@ namespace libtorrent
class TORRENT_EXTRA_EXPORT tracker_manager final
: boost::noncopyable
, single_threaded
{
public:
@ -398,8 +396,6 @@ namespace libtorrent
private:
mutable std::mutex m_mutex;
// maps transactionid to the udp_tracker_connection
// These must use shared_ptr to avoid a dangling reference
// if a connection is erased while a timeout event is in the queue

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <utility>
#include <ctime>
#include <mutex>
#include <boost/shared_ptr.hpp>
#include <boost/cstdint.hpp>

View File

@ -79,7 +79,6 @@ natpmp::natpmp(io_service& ios
// for this array not to be reallocated, by passing
// around pointers to its elements. so reserve size for now
m_mappings.reserve(10);
TORRENT_ASSERT(is_single_thread());
}
void natpmp::start()

View File

@ -235,8 +235,7 @@ namespace libtorrent
void tracker_manager::remove_request(tracker_connection const* c)
{
std::lock_guard<std::mutex> l(m_mutex);
TORRENT_ASSERT(is_single_thread());
http_conns_t::iterator i = std::find_if(m_http_conns.begin()
, m_http_conns.end()
, boost::bind(&boost::shared_ptr<http_tracker_connection>::get, _1) == c);
@ -261,6 +260,7 @@ namespace libtorrent
boost::shared_ptr<udp_tracker_connection> c
, boost::uint64_t tid)
{
TORRENT_ASSERT(is_single_thread());
m_udp_conns.erase(c->transaction_id());
m_udp_conns[tid] = c;
}
@ -270,7 +270,7 @@ namespace libtorrent
, tracker_request req
, boost::weak_ptr<request_callback> c)
{
std::lock_guard<std::mutex> l(m_mutex);
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(req.num_want >= 0);
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
if (m_abort && req.event != tracker_request::stopped) return;
@ -316,6 +316,7 @@ namespace libtorrent
bool tracker_manager::incoming_packet(udp::endpoint const& ep
, aux::array_view<char const> const buf)
{
TORRENT_ASSERT(is_single_thread());
// ignore packets smaller than 8 bytes
if (buf.size() < 8)
{
@ -350,17 +351,17 @@ namespace libtorrent
return p->on_receive(ep, buf);
}
void tracker_manager::incoming_error(error_code const& ec
, udp::endpoint const& ep)
void tracker_manager::incoming_error(error_code const&
, udp::endpoint const&)
{
TORRENT_UNUSED(ec);
TORRENT_UNUSED(ep);
TORRENT_ASSERT(is_single_thread());
// TODO: 2 implement
}
bool tracker_manager::incoming_packet(char const* hostname
, aux::array_view<char const> const buf)
{
TORRENT_ASSERT(is_single_thread());
// ignore packets smaller than 8 bytes
if (buf.size() < 16) return false;
@ -392,6 +393,7 @@ namespace libtorrent
void tracker_manager::send_hostname(char const* hostname, int const port
, array_view<char const> p, error_code& ec, int const flags)
{
TORRENT_ASSERT(is_single_thread());
m_send_fun_hostname(hostname, port, p, ec, flags);
}
@ -399,13 +401,16 @@ namespace libtorrent
, array_view<char const> p
, error_code& ec, int const flags)
{
TORRENT_ASSERT(is_single_thread());
m_send_fun(ep, p, ec, flags);
}
void tracker_manager::abort_all_requests(bool all)
{
// this is called from the destructor too, which is not subject to the
// single-thread requirement.
TORRENT_ASSERT(all || is_single_thread());
// removes all connections except 'event=stopped'-requests
std::unique_lock<std::mutex> l(m_mutex);
m_abort = true;
http_conns_t close_http_connections;
@ -441,7 +446,6 @@ namespace libtorrent
if (rc) rc->debug_log("aborting: %s", req.url.c_str());
#endif
}
l.unlock();
for (http_conns_t::iterator i = close_http_connections.begin()
, end(close_http_connections.end()); i != end; ++i)
@ -459,13 +463,13 @@ namespace libtorrent
bool tracker_manager::empty() const
{
std::lock_guard<std::mutex> l(m_mutex);
TORRENT_ASSERT(is_single_thread());
return m_http_conns.empty() && m_udp_conns.empty();
}
int tracker_manager::num_requests() const
{
std::lock_guard<std::mutex> l(m_mutex);
TORRENT_ASSERT(is_single_thread());
return int(m_http_conns.size() + m_udp_conns.size());
}
}

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <cctype>
#include <mutex>
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>

View File

@ -90,7 +90,6 @@ upnp::upnp(io_service& ios
, m_last_if_update(min_time())
{
TORRENT_ASSERT(cb);
TORRENT_ASSERT(is_single_thread());
}
void upnp::start()
@ -104,10 +103,7 @@ void upnp::start()
m_mappings.reserve(10);
}
upnp::~upnp()
{
TORRENT_ASSERT(is_single_thread());
}
upnp::~upnp() {}
void upnp::discover_device()
{