diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index 87d65b4d8..19d196e90 100755 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -48,9 +48,20 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(pop) #endif + namespace libtorrent { + // PROFILING CODE +#ifdef TORRENT_PROFILE + + void add_checkpoint(std::string const& str); + void print_checkpoints(); +#define TORRENT_CHECKPOINT(str) libtorrent::add_checkpoint(str) +#else +#define TORRENT_CHECKPOINT(str) void(0) +#endif + // DEBUG API struct logger diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 2e7c5a37c..ac061242b 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -98,6 +98,7 @@ namespace libtorrent detail::session_impl& ses , detail::checker_impl& checker , entry const& metadata + , torrent_info const& tf , boost::filesystem::path const& save_path , address const& net_interface , bool compact_mode diff --git a/src/session.cpp b/src/session.cpp index 5a4cc320c..cd2ab26fc 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -1133,6 +1133,7 @@ namespace libtorrent , bool compact_mode , int block_size) { + TORRENT_CHECKPOINT("++ session::add_torrent()"); // make sure the block_size is an even power of 2 #ifndef NDEBUG for (int i = 0; i < 32; ++i) @@ -1152,17 +1153,13 @@ namespace libtorrent if (ti.begin_files() == ti.end_files()) throw std::runtime_error("no files in torrent"); - { - // lock the session - boost::mutex::scoped_lock l(m_impl.m_mutex); + // lock the session and the checker thread (the order is important!) + boost::mutex::scoped_lock l(m_impl.m_mutex); + boost::mutex::scoped_lock l2(m_checker_impl.m_mutex); - // is the torrent already active? - if (m_impl.find_torrent(ti.info_hash())) - throw duplicate_torrent(); - } - - // lock the checker_thread - boost::mutex::scoped_lock l(m_checker_impl.m_mutex); + // is the torrent already active? + if (m_impl.find_torrent(ti.info_hash())) + throw duplicate_torrent(); // is the torrent currently being checked? if (m_checker_impl.find_torrent(ti.info_hash())) @@ -1172,7 +1169,7 @@ namespace libtorrent // the checker thread and store it before starting // the thread boost::shared_ptr torrent_ptr( - new torrent(m_impl, m_checker_impl, metadata, save_path + new torrent(m_impl, m_checker_impl, metadata, ti, save_path , m_impl.m_listen_interface, compact_mode, block_size)); boost::shared_ptr d( @@ -1188,6 +1185,7 @@ namespace libtorrent // job in its queue m_checker_impl.m_cond.notify_one(); + TORRENT_CHECKPOINT("-- session::add_torrent()"); return torrent_handle(&m_impl, &m_checker_impl, ti.info_hash()); }