got rid of the last recursive mutexes. abstracted the threading primitives (and switched over to use asio's internal ones).

This commit is contained in:
Arvid Norberg
2009-10-20 02:49:56 +00:00
parent a5fb1b3455
commit 8a5b7d5d36
41 changed files with 449 additions and 484 deletions

View File

@@ -68,7 +68,7 @@ natpmp::natpmp(io_service& ios, address const& listen_interface
void natpmp::rebind(address const& listen_interface)
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
error_code ec;
address gateway = get_default_gateway(m_socket.get_io_service(), ec);
@@ -121,7 +121,7 @@ void natpmp::rebind(address const& listen_interface)
bool natpmp::get_mapping(int index, int& local_port, int& external_port, int& protocol) const
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
TORRENT_ASSERT(index < int(m_mappings.size()) && index >= 0);
if (index >= int(m_mappings.size()) || index < 0) return false;
@@ -133,14 +133,14 @@ bool natpmp::get_mapping(int index, int& local_port, int& external_port, int& pr
return true;
}
void natpmp::log(char const* msg, mutex_t::scoped_lock& l)
void natpmp::log(char const* msg, mutex::scoped_lock& l)
{
l.unlock();
m_log_callback(msg);
l.lock();
}
void natpmp::disable(error_code const& ec, mutex_t::scoped_lock& l)
void natpmp::disable(error_code const& ec, mutex::scoped_lock& l)
{
m_disabled = true;
@@ -159,7 +159,7 @@ void natpmp::disable(error_code const& ec, mutex_t::scoped_lock& l)
void natpmp::delete_mapping(int index)
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
TORRENT_ASSERT(index < int(m_mappings.size()) && index >= 0);
if (index >= int(m_mappings.size()) || index < 0) return;
@@ -179,7 +179,7 @@ void natpmp::delete_mapping(int index)
int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
if (m_disabled) return -1;
@@ -201,7 +201,7 @@ int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
return mapping_index;
}
void natpmp::try_next_mapping(int i, mutex_t::scoped_lock& l)
void natpmp::try_next_mapping(int i, mutex::scoped_lock& l)
{
/*
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
@@ -250,7 +250,7 @@ void natpmp::try_next_mapping(int i, mutex_t::scoped_lock& l)
update_mapping(m - m_mappings.begin(), l);
}
void natpmp::update_mapping(int i, mutex_t::scoped_lock& l)
void natpmp::update_mapping(int i, mutex::scoped_lock& l)
{
if (i == m_mappings.size())
{
@@ -283,7 +283,7 @@ void natpmp::update_mapping(int i, mutex_t::scoped_lock& l)
}
}
void natpmp::send_map_request(int i, mutex_t::scoped_lock& l)
void natpmp::send_map_request(int i, mutex::scoped_lock& l)
{
using namespace libtorrent::detail;
@@ -334,7 +334,7 @@ void natpmp::send_map_request(int i, mutex_t::scoped_lock& l)
void natpmp::resend_request(int i, error_code const& e)
{
if (e) return;
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
if (m_currently_mapping != i) return;
// if we're shutting down, don't retry, just move on
@@ -354,7 +354,7 @@ void natpmp::resend_request(int i, error_code const& e)
void natpmp::on_reply(error_code const& e
, std::size_t bytes_transferred)
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
using namespace libtorrent::detail;
if (e)
@@ -538,7 +538,7 @@ void natpmp::update_expiration_timer()
void natpmp::mapping_expired(error_code const& e, int i)
{
if (e) return;
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
char msg[200];
snprintf(msg, sizeof(msg), "mapping %u expired", i);
log(msg, l);
@@ -549,11 +549,11 @@ void natpmp::mapping_expired(error_code const& e, int i)
void natpmp::close()
{
mutex_t::scoped_lock l(m_mutex);
mutex::scoped_lock l(m_mutex);
close_impl(l);
}
void natpmp::close_impl(mutex_t::scoped_lock& l)
void natpmp::close_impl(mutex::scoped_lock& l)
{
m_abort = true;
log("closing", l);