* More work on the threading stuff.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1113 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2009-12-14 21:18:51 +00:00
parent b635f8c852
commit 6a94909647
7 changed files with 101 additions and 8 deletions
+20 -3
View File
@@ -38,11 +38,18 @@
#include "thread_base.h"
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <torrent/exceptions.h>
#include "globals.h"
// A preliminary implementation of a global lock, to be moved
// somewhere more appropriate when it's put to use.
ThreadBase::global_lock_type ThreadBase::m_global = { 0, PTHREAD_MUTEX_INITIALIZER };
// Temporarly injected into config.h.
/* temp hack */
//#define __cacheline_aligned __attribute__((__aligned__(128)))
@@ -108,7 +115,7 @@ ThreadBase::ThreadBase() :
}
ThreadBase::~ThreadBase() {
// Cleanup...
pthread_mutex_destroy(&ThreadBase::m_global.lock);
}
void
@@ -122,6 +129,16 @@ void
ThreadBase::stop_thread() {
}
inline rak::timer
ThreadBase::client_next_timeout() {
if (m_taskScheduler.empty())
return rak::timer::from_seconds(10);
else if (m_taskScheduler.top()->time() <= cachedTime)
return 0;
else
return m_taskScheduler.top()->time() - cachedTime;
}
void*
ThreadBase::event_loop(ThreadBase* threadBase) {
// Setup stuff...
@@ -134,11 +151,11 @@ ThreadBase::event_loop(ThreadBase* threadBase) {
if (!threadBase->m_threadQueue->empty())
threadBase->call_queued_items();
// // Remember to add global lock thing to the main poll loop ++.
// // Remember to add global lock thing to the main poll loop ++.
rak::priority_queue_perform(&threadBase->m_taskScheduler, cachedTime);
threadBase->m_pollManager->poll_simple(rak::timer::from_seconds(10));
threadBase->m_pollManager->poll_simple(threadBase->client_next_timeout());
}
return NULL;