mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-21 00:26:16 +00:00
Merge branch 'master' into c++11
Conflicts: src/core/manager.cc src/thread_base.cc
This commit is contained in:
@@ -17,7 +17,6 @@ EXTRA_DIST= \
|
|||||||
rak/partial_queue.h \
|
rak/partial_queue.h \
|
||||||
rak/priority_queue.h \
|
rak/priority_queue.h \
|
||||||
rak/priority_queue_default.h \
|
rak/priority_queue_default.h \
|
||||||
rak/ranges.h \
|
|
||||||
rak/regex.h \
|
rak/regex.h \
|
||||||
rak/socket_address.h \
|
rak/socket_address.h \
|
||||||
rak/string_manip.h \
|
rak/string_manip.h \
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT(rtorrent, 0.8.9, jaris@ifi.uio.no)
|
AC_INIT(rtorrent, 0.9.0, jaris@ifi.uio.no)
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE
|
AM_INIT_AUTOMAKE
|
||||||
AM_CONFIG_HEADER(config.h)
|
AM_CONFIG_HEADER(config.h)
|
||||||
@@ -41,7 +41,7 @@ PKG_CHECK_MODULES(libcurl, libcurl >= 7.15.4,
|
|||||||
CXXFLAGS="$CXXFLAGS $libcurl_CFLAGS";
|
CXXFLAGS="$CXXFLAGS $libcurl_CFLAGS";
|
||||||
LIBS="$LIBS $libcurl_LIBS")
|
LIBS="$LIBS $libcurl_LIBS")
|
||||||
|
|
||||||
PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.12.9,
|
PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.13.0,
|
||||||
CXXFLAGS="$CXXFLAGS $libtorrent_CFLAGS";
|
CXXFLAGS="$CXXFLAGS $libtorrent_CFLAGS";
|
||||||
LIBS="$LIBS $libtorrent_LIBS")
|
LIBS="$LIBS $libtorrent_LIBS")
|
||||||
|
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ libsub_core_a_SOURCES = \
|
|||||||
manager.h \
|
manager.h \
|
||||||
poll_manager.cc \
|
poll_manager.cc \
|
||||||
poll_manager.h \
|
poll_manager.h \
|
||||||
poll_manager_epoll.cc \
|
|
||||||
poll_manager_epoll.h \
|
|
||||||
poll_manager_kqueue.cc \
|
|
||||||
poll_manager_kqueue.h \
|
|
||||||
poll_manager_select.cc \
|
|
||||||
poll_manager_select.h \
|
|
||||||
range_map.h \
|
range_map.h \
|
||||||
view.cc \
|
view.cc \
|
||||||
view.h \
|
view.h \
|
||||||
|
|||||||
@@ -642,6 +642,9 @@ DownloadList::confirm_finished(Download* download) {
|
|||||||
|
|
||||||
DL_TRIGGER_EVENT(download, "event.download.finished");
|
DL_TRIGGER_EVENT(download, "event.download.finished");
|
||||||
|
|
||||||
|
if (find(infohash) != end())
|
||||||
|
return;
|
||||||
|
|
||||||
// if (download->resume_flags() != ~uint32_t())
|
// if (download->resume_flags() != ~uint32_t())
|
||||||
// throw torrent::internal_error("DownloadList::confirm_finished(...) download->resume_flags() != ~uint32_t().");
|
// throw torrent::internal_error("DownloadList::confirm_finished(...) download->resume_flags() != ~uint32_t().");
|
||||||
|
|
||||||
@@ -655,8 +658,7 @@ DownloadList::confirm_finished(Download* download) {
|
|||||||
// being hashed.
|
// being hashed.
|
||||||
download->set_resume_flags(~uint32_t());
|
download->set_resume_flags(~uint32_t());
|
||||||
|
|
||||||
if (find(infohash) != end() &&
|
if (!download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1)
|
||||||
!download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1)
|
|
||||||
resume(download,
|
resume(download,
|
||||||
torrent::Download::start_no_create |
|
torrent::Download::start_no_create |
|
||||||
torrent::Download::start_skip_tracker |
|
torrent::Download::start_skip_tracker |
|
||||||
|
|||||||
+2
-4
@@ -71,9 +71,7 @@
|
|||||||
#include "download_store.h"
|
#include "download_store.h"
|
||||||
#include "http_queue.h"
|
#include "http_queue.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "poll_manager_epoll.h"
|
#include "poll_manager.h"
|
||||||
#include "poll_manager_kqueue.h"
|
|
||||||
#include "poll_manager_select.h"
|
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
@@ -204,7 +202,7 @@ Manager::get_address_throttle(const sockaddr* addr) {
|
|||||||
// Most of this should be possible to move out.
|
// Most of this should be possible to move out.
|
||||||
void
|
void
|
||||||
Manager::initialize_second() {
|
Manager::initialize_second() {
|
||||||
torrent::Http::set_factory(tr1::bind(&CurlStack::new_object, m_httpStack));
|
torrent::Http::slot_factory() = std::tr1::bind(&CurlStack::new_object, m_httpStack);
|
||||||
m_httpQueue->slot_factory(sigc::mem_fun(m_httpStack, &CurlStack::new_object));
|
m_httpQueue->slot_factory(sigc::mem_fun(m_httpStack, &CurlStack::new_object));
|
||||||
|
|
||||||
CurlStack::global_init();
|
CurlStack::global_init();
|
||||||
|
|||||||
+24
-40
@@ -39,71 +39,55 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <rak/error_number.h>
|
#include <rak/error_number.h>
|
||||||
|
#include <torrent/poll_epoll.h>
|
||||||
|
#include <torrent/poll_kqueue.h>
|
||||||
|
#include <torrent/poll_select.h>
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "poll_manager.h"
|
#include "poll_manager.h"
|
||||||
#include "poll_manager_epoll.h"
|
|
||||||
#include "poll_manager_kqueue.h"
|
|
||||||
#include "poll_manager_select.h"
|
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
PollManager::PollManager(torrent::Poll* poll) :
|
torrent::Poll*
|
||||||
m_poll(poll) {
|
create_poll() {
|
||||||
|
|
||||||
if (m_poll == NULL)
|
|
||||||
throw std::logic_error("PollManager::PollManager(...) received poll == NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManager::~PollManager() {
|
|
||||||
delete m_poll;
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManager*
|
|
||||||
PollManager::create_poll_manager() {
|
|
||||||
PollManager* pollManager = NULL;
|
|
||||||
Log* log = &control->core()->get_log_important();
|
Log* log = &control->core()->get_log_important();
|
||||||
|
|
||||||
const char* poll = getenv("RTORRENT_POLL");
|
const char* poll_name = getenv("RTORRENT_POLL");
|
||||||
|
|
||||||
int maxOpen = sysconf(_SC_OPEN_MAX);
|
int maxOpen = sysconf(_SC_OPEN_MAX);
|
||||||
|
|
||||||
if (poll != NULL) {
|
torrent::Poll* poll = NULL;
|
||||||
if (!strcmp(poll, "epoll"))
|
|
||||||
pollManager = PollManagerEPoll::create(maxOpen);
|
|
||||||
else if (!strcmp(poll, "kqueue"))
|
|
||||||
pollManager = PollManagerKQueue::create(maxOpen);
|
|
||||||
else if (!strcmp(poll, "select"))
|
|
||||||
pollManager = PollManagerSelect::create(maxOpen);
|
|
||||||
|
|
||||||
if (pollManager == NULL)
|
if (poll_name != NULL) {
|
||||||
log->push_front(std::string("Cannot enable '") + poll + "' based polling.");
|
if (!strcmp(poll_name, "epoll"))
|
||||||
|
poll = torrent::PollEPoll::create(maxOpen);
|
||||||
|
else if (!strcmp(poll_name, "kqueue"))
|
||||||
|
poll = torrent::PollKQueue::create(maxOpen);
|
||||||
|
else if (!strcmp(poll_name, "select"))
|
||||||
|
poll = torrent::PollSelect::create(maxOpen);
|
||||||
|
|
||||||
|
if (poll == NULL)
|
||||||
|
log->push_front(std::string("Cannot enable '") + poll_name + "' based polling.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pollManager != NULL)
|
if (poll != NULL)
|
||||||
log->push_front(std::string("Using '") + poll + "' based polling.");
|
log->push_front(std::string("Using '") + poll_name + "' based polling.");
|
||||||
|
|
||||||
else if ((pollManager = PollManagerEPoll::create(maxOpen)) != NULL)
|
else if ((poll = torrent::PollEPoll::create(maxOpen)) != NULL)
|
||||||
log->push_front("Using 'epoll' based polling.");
|
log->push_front("Using 'epoll' based polling.");
|
||||||
|
|
||||||
else if ((pollManager = PollManagerKQueue::create(maxOpen)) != NULL)
|
else if ((poll = torrent::PollKQueue::create(maxOpen)) != NULL)
|
||||||
log->push_front("Using 'kqueue' based polling.");
|
log->push_front("Using 'kqueue' based polling.");
|
||||||
|
|
||||||
else if ((pollManager = PollManagerSelect::create(maxOpen)) != NULL)
|
else if ((poll = torrent::PollSelect::create(maxOpen)) != NULL)
|
||||||
log->push_front("Using 'select' based polling.");
|
log->push_front("Using 'select' based polling.");
|
||||||
|
|
||||||
else
|
else
|
||||||
throw std::runtime_error("Could not create any PollManager.");
|
throw std::runtime_error("Could not create any Poll object.");
|
||||||
|
|
||||||
return pollManager;
|
return poll;
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManager::check_error() {
|
|
||||||
if (rak::error_number::current().value() != rak::error_number::e_intr)
|
|
||||||
throw std::runtime_error("Poll::work(): " + std::string(rak::error_number::current().c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-27
@@ -45,33 +45,7 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
// CurlStack really should be somewhere else, but that won't happen
|
torrent::Poll* create_poll();
|
||||||
// until they add an epoll friendly API.
|
|
||||||
|
|
||||||
class PollManager {
|
|
||||||
public:
|
|
||||||
typedef sigc::signal0<void> Signal;
|
|
||||||
|
|
||||||
PollManager(torrent::Poll* poll);
|
|
||||||
virtual ~PollManager();
|
|
||||||
|
|
||||||
unsigned int get_open_max() const { return m_poll->open_max(); }
|
|
||||||
|
|
||||||
torrent::Poll* get_torrent_poll() { return m_poll; }
|
|
||||||
|
|
||||||
virtual void poll(rak::timer timeout) = 0;
|
|
||||||
virtual void poll_simple(rak::timer timeout) = 0;
|
|
||||||
|
|
||||||
static PollManager* create_poll_manager();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PollManager(const PollManager&);
|
|
||||||
void operator = (const PollManager&);
|
|
||||||
|
|
||||||
void check_error();
|
|
||||||
|
|
||||||
torrent::Poll* m_poll;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <torrent/poll_epoll.h>
|
|
||||||
#include <torrent/torrent.h>
|
|
||||||
|
|
||||||
#include "poll_manager_epoll.h"
|
|
||||||
#include "thread_base.h"
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
PollManagerEPoll*
|
|
||||||
PollManagerEPoll::create(int maxOpenSockets) {
|
|
||||||
torrent::PollEPoll* p = torrent::PollEPoll::create(maxOpenSockets);
|
|
||||||
|
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
else
|
|
||||||
return new PollManagerEPoll(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManagerEPoll::~PollManagerEPoll() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerEPoll::poll(rak::timer timeout) {
|
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
|
||||||
// resolution.
|
|
||||||
torrent::perform();
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
|
|
||||||
int status = static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerEPoll::poll_simple(rak::timer timeout) {
|
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
|
||||||
// resolution.
|
|
||||||
timeout = timeout + 1000;
|
|
||||||
|
|
||||||
if (static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#ifndef RTORRENT_CORE_POLL_MANAGER_EPOLL_H
|
|
||||||
#define RTORRENT_CORE_POLL_MANAGER_EPOLL_H
|
|
||||||
|
|
||||||
#include "poll_manager.h"
|
|
||||||
|
|
||||||
namespace torrent {
|
|
||||||
class PollEPoll;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
class PollManagerEPoll : public PollManager {
|
|
||||||
public:
|
|
||||||
static PollManagerEPoll* create(int maxOpenSockets);
|
|
||||||
~PollManagerEPoll();
|
|
||||||
|
|
||||||
torrent::Poll* get_torrent_poll();
|
|
||||||
|
|
||||||
void poll(rak::timer timeout);
|
|
||||||
void poll_simple(rak::timer timeout);
|
|
||||||
|
|
||||||
private:
|
|
||||||
PollManagerEPoll(torrent::Poll* p) : PollManager(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <torrent/exceptions.h>
|
|
||||||
#include <torrent/poll_kqueue.h>
|
|
||||||
#include <torrent/torrent.h>
|
|
||||||
|
|
||||||
#include "poll_manager_kqueue.h"
|
|
||||||
#include "thread_base.h"
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
PollManagerKQueue*
|
|
||||||
PollManagerKQueue::create(int maxOpenSockets) {
|
|
||||||
torrent::PollKQueue* p = torrent::PollKQueue::create(maxOpenSockets);
|
|
||||||
|
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
else
|
|
||||||
return new PollManagerKQueue(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManagerKQueue::~PollManagerKQueue() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerKQueue::poll(rak::timer timeout) {
|
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
|
||||||
// resolution.
|
|
||||||
torrent::perform();
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
|
|
||||||
int status = static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerKQueue::poll_simple(rak::timer timeout) {
|
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
|
||||||
// resolution.
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
if (static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#ifndef RTORRENT_CORE_POLL_MANAGER_KQUEUE_H
|
|
||||||
#define RTORRENT_CORE_POLL_MANAGER_KQUEUE_H
|
|
||||||
|
|
||||||
#include "poll_manager.h"
|
|
||||||
|
|
||||||
namespace torrent {
|
|
||||||
class PollKQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
class PollManagerKQueue : public PollManager {
|
|
||||||
public:
|
|
||||||
static PollManagerKQueue* create(int maxOpenSockets);
|
|
||||||
~PollManagerKQueue();
|
|
||||||
|
|
||||||
torrent::Poll* get_torrent_poll();
|
|
||||||
|
|
||||||
void poll(rak::timer timeout);
|
|
||||||
void poll_simple(rak::timer timeout);
|
|
||||||
|
|
||||||
private:
|
|
||||||
PollManagerKQueue(torrent::Poll* p) : PollManager(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <rak/allocators.h>
|
|
||||||
#include <torrent/exceptions.h>
|
|
||||||
#include <torrent/poll_select.h>
|
|
||||||
#include <torrent/torrent.h>
|
|
||||||
|
|
||||||
#include "poll_manager_select.h"
|
|
||||||
#include "thread_base.h"
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) {
|
|
||||||
#if defined USE_VARIABLE_FDSET
|
|
||||||
m_setSize = (m_poll->open_max() + 7) / 8;
|
|
||||||
|
|
||||||
char* buffer = rak::cacheline_allocator<char>::alloc_size(3 * m_setSize);
|
|
||||||
std::memset(buffer, 0, 3 * m_setSize);
|
|
||||||
|
|
||||||
m_readSet = (fd_set*)buffer;
|
|
||||||
m_writeSet = (fd_set*)(buffer += m_setSize);
|
|
||||||
m_errorSet = (fd_set*)(buffer += m_setSize);
|
|
||||||
#else
|
|
||||||
#error Only variable fdset supported atm.
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManagerSelect*
|
|
||||||
PollManagerSelect::create(int maxOpenSockets) {
|
|
||||||
torrent::PollSelect* p = torrent::PollSelect::create(maxOpenSockets);
|
|
||||||
|
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return new PollManagerSelect(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
PollManagerSelect::~PollManagerSelect() {
|
|
||||||
free(m_readSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerSelect::poll(rak::timer timeout) {
|
|
||||||
torrent::perform();
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
std::memset(m_readSet, 0, m_setSize);
|
|
||||||
std::memset(m_writeSet, 0, m_setSize);
|
|
||||||
std::memset(m_errorSet, 0, m_setSize);
|
|
||||||
|
|
||||||
unsigned int maxFd = static_cast<torrent::PollSelect*>(m_poll)->fdset(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
|
|
||||||
timeval t = timeout.tval();
|
|
||||||
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
|
|
||||||
int status = select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollSelect*>(m_poll)->perform(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PollManagerSelect::poll_simple(rak::timer timeout) {
|
|
||||||
torrent::PollSelect* currentPoll = static_cast<torrent::PollSelect*>(m_poll);
|
|
||||||
|
|
||||||
timeout = timeout + 1000;
|
|
||||||
std::memset(m_readSet, 0, 3 * m_setSize);
|
|
||||||
|
|
||||||
unsigned int maxFd = currentPoll->fdset(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
|
|
||||||
timeval t = timeout.tval();
|
|
||||||
|
|
||||||
if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
currentPoll->perform(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
// rTorrent - BitTorrent client
|
|
||||||
// Copyright (C) 2005-2011, Jari Sundell
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
//
|
|
||||||
// In addition, as a special exception, the copyright holders give
|
|
||||||
// permission to link the code of portions of this program with the
|
|
||||||
// OpenSSL library under certain conditions as described in each
|
|
||||||
// individual source file, and distribute linked combinations
|
|
||||||
// including the two.
|
|
||||||
//
|
|
||||||
// You must obey the GNU General Public License in all respects for
|
|
||||||
// all of the code used other than OpenSSL. If you modify file(s)
|
|
||||||
// with this exception, you may extend this exception to your version
|
|
||||||
// of the file(s), but you are not obligated to do so. If you do not
|
|
||||||
// wish to do so, delete this exception statement from your version.
|
|
||||||
// If you delete this exception statement from all source files in the
|
|
||||||
// program, then also delete it here.
|
|
||||||
//
|
|
||||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
|
||||||
//
|
|
||||||
// Skomakerveien 33
|
|
||||||
// 3185 Skoppum, NORWAY
|
|
||||||
|
|
||||||
#ifndef RTORRENT_CORE_POLL_MANAGER_SELECT_H
|
|
||||||
#define RTORRENT_CORE_POLL_MANAGER_SELECT_H
|
|
||||||
|
|
||||||
#include "poll_manager.h"
|
|
||||||
|
|
||||||
namespace torrent {
|
|
||||||
class PollSelect;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
|
|
||||||
class lt_cacheline_aligned PollManagerSelect : public PollManager {
|
|
||||||
public:
|
|
||||||
static PollManagerSelect* create(int maxOpenSockets);
|
|
||||||
~PollManagerSelect();
|
|
||||||
|
|
||||||
void poll(rak::timer timeout);
|
|
||||||
void poll_simple(rak::timer timeout);
|
|
||||||
|
|
||||||
private:
|
|
||||||
PollManagerSelect(torrent::Poll* p);
|
|
||||||
|
|
||||||
unsigned int m_setSize;
|
|
||||||
fd_set* m_readSet;
|
|
||||||
fd_set* m_writeSet;
|
|
||||||
fd_set* m_errorSet;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -195,10 +195,10 @@ print_download_status(char* first, char* last, core::Download* d) {
|
|||||||
first = print_buffer(first, last, "Checking hash [%2i%%]",
|
first = print_buffer(first, last, "Checking hash [%2i%%]",
|
||||||
(d->download()->chunks_hashed() * 100) / d->download()->file_list()->size_chunks());
|
(d->download()->chunks_hashed() * 100) / d->download()->file_list()->size_chunks());
|
||||||
|
|
||||||
} else if (d->tracker_list()->has_active()) {
|
} else if (d->tracker_list()->has_active_not_scrape()) {
|
||||||
torrent::TrackerList::iterator itr =
|
torrent::TrackerList::iterator itr =
|
||||||
std::find_if(d->tracker_list()->begin(), d->tracker_list()->end(),
|
std::find_if(d->tracker_list()->begin(), d->tracker_list()->end(),
|
||||||
std::mem_fun(&torrent::Tracker::is_busy));
|
std::mem_fun(&torrent::Tracker::is_busy_not_scrape));
|
||||||
char status[128];
|
char status[128];
|
||||||
|
|
||||||
(*itr)->get_status(status, sizeof(status));
|
(*itr)->get_status(status, sizeof(status));
|
||||||
|
|||||||
@@ -83,11 +83,6 @@ WindowTrackerList::redraw() {
|
|||||||
while (range.first != range.second) {
|
while (range.first != range.second) {
|
||||||
torrent::Tracker* tracker = tl->at(range.first);
|
torrent::Tracker* tracker = tl->at(range.first);
|
||||||
|
|
||||||
// m_canvas->print(0, pos, "[%c] [S/L %5i/%5i] %s",
|
|
||||||
// tracker->is_enabled() ? (tracker->is_open() ? '*' : ' ') : '-',
|
|
||||||
// tracker->scrape_complete(), tracker->scrape_incomplete(),
|
|
||||||
// tracker->url().c_str());
|
|
||||||
|
|
||||||
if (tracker->group() == group)
|
if (tracker->group() == group)
|
||||||
m_canvas->print(0, pos, "%2i:", group++);
|
m_canvas->print(0, pos, "%2i:", group++);
|
||||||
|
|
||||||
@@ -95,30 +90,27 @@ WindowTrackerList::redraw() {
|
|||||||
tracker->url().c_str());
|
tracker->url().c_str());
|
||||||
|
|
||||||
if (pos < m_canvas->height())
|
if (pos < m_canvas->height())
|
||||||
m_canvas->print(4, pos++, "Id: %s Counters: %uf / %us (%u) %s %s S/L/D: %u/%u/%u (%u/%u)",
|
m_canvas->print(0, pos++, "%s Id: %s Counters: %uf / %us (%u) %s S/L/D: %u/%u/%u (%u/%u)",
|
||||||
|
tracker->is_busy() ? "req " : " ",
|
||||||
rak::copy_escape_html(tracker->tracker_id()).c_str(),
|
rak::copy_escape_html(tracker->tracker_id()).c_str(),
|
||||||
tracker->failed_counter(),
|
tracker->failed_counter(),
|
||||||
tracker->success_counter(),
|
tracker->success_counter(),
|
||||||
tracker->scrape_counter(),
|
tracker->scrape_counter(),
|
||||||
tracker->is_usable() ? " on" : tracker->is_enabled() ? "err" : "off",
|
tracker->is_usable() ? " on" : tracker->is_enabled() ? "err" : "off",
|
||||||
tracker->is_busy() ? "req" : " ",
|
|
||||||
tracker->scrape_complete(),
|
tracker->scrape_complete(),
|
||||||
tracker->scrape_incomplete(),
|
tracker->scrape_incomplete(),
|
||||||
tracker->scrape_downloaded(),
|
tracker->scrape_downloaded(),
|
||||||
tracker->latest_new_peers(),
|
tracker->latest_new_peers(),
|
||||||
tracker->latest_sum_peers());
|
tracker->latest_sum_peers());
|
||||||
|
|
||||||
// m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s Timer: %u/%u",
|
|
||||||
// rak::copy_escape_html(tracker->tracker_id()).c_str(),
|
|
||||||
// range.first == tl->focus() ? "yes" : " no",
|
|
||||||
// tracker->is_enabled() ? "yes" : " no",
|
|
||||||
// tracker->is_open() ? "yes" : " no",
|
|
||||||
// tracker->normal_interval(),
|
|
||||||
// tracker->min_interval());
|
|
||||||
|
|
||||||
if (range.first == *m_focus) {
|
if (range.first == *m_focus) {
|
||||||
m_canvas->set_attr(0, pos - 2, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
|
m_canvas->set_attr(4, pos - 2, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
|
||||||
m_canvas->set_attr(0, pos - 1, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
|
m_canvas->set_attr(4, pos - 1, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tracker->is_busy()) {
|
||||||
|
m_canvas->set_attr(0, pos - 2, 4, A_REVERSE, COLOR_PAIR(0));
|
||||||
|
m_canvas->set_attr(0, pos - 1, 4, A_REVERSE, COLOR_PAIR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
range.first++;
|
range.first++;
|
||||||
|
|||||||
+1
-1
@@ -876,7 +876,7 @@ main(int argc, char** argv) {
|
|||||||
rak::priority_queue_perform(&taskScheduler, cachedTime);
|
rak::priority_queue_perform(&taskScheduler, cachedTime);
|
||||||
|
|
||||||
// Do shutdown check before poll, not after.
|
// Do shutdown check before poll, not after.
|
||||||
main_thread->poll_manager()->poll(client_next_timeout(control));
|
main_thread->poll()->do_poll(client_next_timeout(control).usec());
|
||||||
}
|
}
|
||||||
|
|
||||||
control->core()->download_list()->session_save();
|
control->core()->download_list()->session_save();
|
||||||
|
|||||||
+9
-22
@@ -107,21 +107,13 @@ public:
|
|||||||
|
|
||||||
void throw_shutdown_exception() { throw torrent::shutdown_exception(); }
|
void throw_shutdown_exception() { throw torrent::shutdown_exception(); }
|
||||||
|
|
||||||
ThreadBase::ThreadBase() :
|
ThreadBase::ThreadBase() {
|
||||||
m_state(STATE_UNKNOWN),
|
m_taskShutdown.set_slot(rak::ptr_fn(&throw_shutdown_exception));
|
||||||
m_pollManager(NULL) {
|
|
||||||
// Init the poll manager in a special init function called by the
|
|
||||||
// thread itself. Need to be careful with what external stuff
|
|
||||||
// create_poll_manager calls in that case.
|
|
||||||
std::memset(&m_thread, 0, sizeof(pthread_t));
|
|
||||||
|
|
||||||
m_taskShutdown.set_slot(std::tr1::bind(&throw_shutdown_exception));
|
|
||||||
|
|
||||||
m_threadQueue = new thread_queue_hack;
|
m_threadQueue = new thread_queue_hack;
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadBase::~ThreadBase() {
|
ThreadBase::~ThreadBase() {
|
||||||
delete m_pollManager;
|
|
||||||
delete m_threadQueue;
|
delete m_threadQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,24 +141,19 @@ ThreadBase::client_next_timeout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
ThreadBase::event_loop(ThreadBase* threadBase) {
|
ThreadBase::event_loop(ThreadBase* thread) {
|
||||||
// Setup stuff...
|
thread->m_state = STATE_ACTIVE;
|
||||||
threadBase->m_state = STATE_ACTIVE;
|
|
||||||
|
|
||||||
// Set local poll and priority queue.
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Check for new queued items set by other threads.
|
// Check for new queued items set by other threads.
|
||||||
if (!threadBase->m_threadQueue->empty())
|
if (!thread->m_threadQueue->empty())
|
||||||
threadBase->call_queued_items();
|
thread->call_queued_items();
|
||||||
|
|
||||||
// // Remember to add global lock thing to the main poll loop ++.
|
rak::priority_queue_perform(&thread->m_taskScheduler, cachedTime);
|
||||||
|
|
||||||
rak::priority_queue_perform(&threadBase->m_taskScheduler, cachedTime);
|
thread->m_poll->do_poll(thread->client_next_timeout().usec(), torrent::Poll::poll_worker_thread);
|
||||||
|
|
||||||
threadBase->m_pollManager->poll_simple(threadBase->client_next_timeout());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (torrent::shutdown_exception& e) {
|
} catch (torrent::shutdown_exception& e) {
|
||||||
@@ -175,7 +162,7 @@ ThreadBase::event_loop(ThreadBase* threadBase) {
|
|||||||
release_global_lock();
|
release_global_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
threadBase->m_state = STATE_INACTIVE;
|
thread->m_state = STATE_INACTIVE;
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+3
-18
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <torrent/thread_base.h>
|
#include <torrent/utils/thread_base.h>
|
||||||
|
|
||||||
#include "rak/priority_queue_default.h"
|
#include "rak/priority_queue_default.h"
|
||||||
#include "core/poll_manager.h"
|
#include "core/poll_manager.h"
|
||||||
@@ -50,26 +50,15 @@ struct thread_queue_hack;
|
|||||||
|
|
||||||
struct thread_queue_hack;
|
struct thread_queue_hack;
|
||||||
|
|
||||||
class ThreadBase : public torrent::ThreadBase {
|
class ThreadBase : public torrent::thread_base {
|
||||||
public:
|
public:
|
||||||
typedef rak::priority_queue_default priority_queue;
|
typedef rak::priority_queue_default priority_queue;
|
||||||
typedef void (*thread_base_func)(ThreadBase*);
|
typedef void (*thread_base_func)(ThreadBase*);
|
||||||
typedef void* (*pthread_func)(void*);
|
typedef void* (*pthread_func)(void*);
|
||||||
|
|
||||||
enum state_type {
|
|
||||||
STATE_UNKNOWN,
|
|
||||||
STATE_INITIALIZED,
|
|
||||||
STATE_ACTIVE,
|
|
||||||
STATE_INACTIVE
|
|
||||||
};
|
|
||||||
|
|
||||||
ThreadBase();
|
ThreadBase();
|
||||||
virtual ~ThreadBase();
|
virtual ~ThreadBase();
|
||||||
|
|
||||||
bool is_active() const { return m_state == STATE_ACTIVE; }
|
|
||||||
|
|
||||||
torrent::Poll* poll() { return m_pollManager->get_torrent_poll(); }
|
|
||||||
core::PollManager* poll_manager() { return m_pollManager; }
|
|
||||||
priority_queue& task_scheduler() { return m_taskScheduler; }
|
priority_queue& task_scheduler() { return m_taskScheduler; }
|
||||||
|
|
||||||
virtual void init_thread() = 0;
|
virtual void init_thread() = 0;
|
||||||
@@ -82,7 +71,7 @@ public:
|
|||||||
|
|
||||||
void queue_item(thread_base_func newFunc);
|
void queue_item(thread_base_func newFunc);
|
||||||
|
|
||||||
static void* event_loop(ThreadBase* threadBase);
|
static void* event_loop(ThreadBase* thread);
|
||||||
|
|
||||||
// Only call this when global lock has been acquired, as it checks
|
// Only call this when global lock has been acquired, as it checks
|
||||||
// ThreadBase::is_main_polling() which is only guaranteed to remain
|
// ThreadBase::is_main_polling() which is only guaranteed to remain
|
||||||
@@ -99,12 +88,8 @@ protected:
|
|||||||
|
|
||||||
// TODO: Add thread name.
|
// TODO: Add thread name.
|
||||||
|
|
||||||
pthread_t m_thread;
|
|
||||||
state_type m_state;
|
|
||||||
|
|
||||||
// The timer needs to be sync'ed when updated...
|
// The timer needs to be sync'ed when updated...
|
||||||
|
|
||||||
core::PollManager* m_pollManager;
|
|
||||||
rak::priority_queue_default m_taskScheduler;
|
rak::priority_queue_default m_taskScheduler;
|
||||||
|
|
||||||
rak::priority_item m_taskShutdown;
|
rak::priority_item m_taskShutdown;
|
||||||
|
|||||||
+2
-2
@@ -49,8 +49,8 @@ ThreadMain::init_thread() {
|
|||||||
// The main thread always holds the lock while running.
|
// The main thread always holds the lock while running.
|
||||||
acquire_global_lock();
|
acquire_global_lock();
|
||||||
|
|
||||||
m_pollManager = core::PollManager::create_poll_manager();
|
m_poll = core::create_poll();
|
||||||
m_pollManager->get_torrent_poll()->set_flags(torrent::Poll::flag_waive_global_lock);
|
m_poll->set_flags(torrent::Poll::flag_waive_global_lock);
|
||||||
|
|
||||||
m_state = STATE_INITIALIZED;
|
m_state = STATE_INITIALIZED;
|
||||||
m_thread = pthread_self();
|
m_thread = pthread_self();
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ ThreadWorker::~ThreadWorker() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
ThreadWorker::init_thread() {
|
ThreadWorker::init_thread() {
|
||||||
m_pollManager = core::PollManager::create_poll_manager();
|
m_poll = core::create_poll();
|
||||||
|
|
||||||
m_state = STATE_INITIALIZED;
|
m_state = STATE_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user