mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 13:42:30 +00:00
Moving thread code to libtorrent.
This commit is contained in:
+7
-18
@@ -108,13 +108,7 @@ public:
|
||||
void throw_shutdown_exception() { throw torrent::shutdown_exception(); }
|
||||
|
||||
ThreadBase::ThreadBase() :
|
||||
m_state(STATE_UNKNOWN),
|
||||
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(rak::ptr_fn(&throw_shutdown_exception));
|
||||
|
||||
m_threadQueue = new thread_queue_hack;
|
||||
@@ -149,24 +143,19 @@ ThreadBase::client_next_timeout() {
|
||||
}
|
||||
|
||||
void*
|
||||
ThreadBase::event_loop(ThreadBase* threadBase) {
|
||||
// Setup stuff...
|
||||
threadBase->m_state = STATE_ACTIVE;
|
||||
|
||||
// Set local poll and priority queue.
|
||||
ThreadBase::event_loop(ThreadBase* thread) {
|
||||
thread->m_state = STATE_ACTIVE;
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
// Check for new queued items set by other threads.
|
||||
if (!threadBase->m_threadQueue->empty())
|
||||
threadBase->call_queued_items();
|
||||
if (!thread->m_threadQueue->empty())
|
||||
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);
|
||||
|
||||
threadBase->m_pollManager->poll_simple(threadBase->client_next_timeout());
|
||||
thread->m_pollManager->poll_simple(thread->client_next_timeout());
|
||||
}
|
||||
|
||||
} catch (torrent::shutdown_exception& e) {
|
||||
@@ -175,7 +164,7 @@ ThreadBase::event_loop(ThreadBase* threadBase) {
|
||||
release_global_lock();
|
||||
}
|
||||
|
||||
threadBase->m_state = STATE_INACTIVE;
|
||||
thread->m_state = STATE_INACTIVE;
|
||||
__sync_synchronize();
|
||||
|
||||
return NULL;
|
||||
|
||||
+3
-16
@@ -39,7 +39,7 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <torrent/thread_base.h>
|
||||
#include <torrent/utils/thread_base.h>
|
||||
|
||||
#include "rak/priority_queue_default.h"
|
||||
#include "core/poll_manager.h"
|
||||
@@ -50,25 +50,15 @@ struct thread_queue_hack;
|
||||
|
||||
struct thread_queue_hack;
|
||||
|
||||
class ThreadBase : public torrent::ThreadBase {
|
||||
class ThreadBase : public torrent::thread_base {
|
||||
public:
|
||||
typedef rak::priority_queue_default priority_queue;
|
||||
typedef void (*thread_base_func)(ThreadBase*);
|
||||
typedef void* (*pthread_func)(void*);
|
||||
|
||||
enum state_type {
|
||||
STATE_UNKNOWN,
|
||||
STATE_INITIALIZED,
|
||||
STATE_ACTIVE,
|
||||
STATE_INACTIVE
|
||||
};
|
||||
|
||||
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; }
|
||||
|
||||
@@ -82,7 +72,7 @@ public:
|
||||
|
||||
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
|
||||
// ThreadBase::is_main_polling() which is only guaranteed to remain
|
||||
@@ -99,9 +89,6 @@ protected:
|
||||
|
||||
// TODO: Add thread name.
|
||||
|
||||
pthread_t m_thread;
|
||||
state_type m_state;
|
||||
|
||||
// The timer needs to be sync'ed when updated...
|
||||
|
||||
core::PollManager* m_pollManager;
|
||||
|
||||
@@ -51,6 +51,7 @@ ThreadMain::init_thread() {
|
||||
|
||||
m_pollManager = core::PollManager::create_poll_manager();
|
||||
m_pollManager->get_torrent_poll()->set_flags(torrent::Poll::flag_waive_global_lock);
|
||||
m_poll = m_pollManager->get_torrent_poll();
|
||||
|
||||
m_state = STATE_INITIALIZED;
|
||||
m_thread = pthread_self();
|
||||
|
||||
@@ -63,6 +63,7 @@ ThreadWorker::~ThreadWorker() {
|
||||
void
|
||||
ThreadWorker::init_thread() {
|
||||
m_pollManager = core::PollManager::create_poll_manager();
|
||||
m_poll = m_pollManager->get_torrent_poll();
|
||||
|
||||
m_state = STATE_INITIALIZED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user