* Finished the foundation of threading.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1114 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2009-12-15 21:39:35 +00:00
parent 6a94909647
commit 2304983f4f
6 changed files with 15 additions and 53 deletions
+2 -40
View File
@@ -39,6 +39,7 @@
#include <pthread.h>
#include <sys/types.h>
#include <torrent/thread_base.h>
#include "rak/priority_queue_default.h"
#include "core/poll_manager.h"
@@ -49,7 +50,7 @@ struct thread_queue_hack;
struct thread_queue_hack;
class ThreadBase {
class ThreadBase : public torrent::ThreadBase {
public:
typedef rak::priority_queue_default priority_queue;
typedef void (*thread_base_func)(ThreadBase*);
@@ -80,12 +81,6 @@ public:
static void* event_loop(ThreadBase* threadBase);
static inline int global_queue_size() { return m_global.waiting; }
static inline void acquire_global_lock();
static inline void release_global_lock();
static inline void waive_global_lock();
protected:
inline rak::timer client_next_timeout();
@@ -102,39 +97,6 @@ protected:
// Temporary hack to pass messages to a thread. This really needs to
// be cleaned up and/or integrated into the priority queue itself.
thread_queue_hack* m_threadQueue;
struct __cacheline_aligned global_lock_type {
int waiting;
pthread_mutex_t lock;
};
static global_lock_type m_global;
};
inline void
ThreadBase::acquire_global_lock() {
__sync_add_and_fetch(&ThreadBase::m_global.waiting, 1);
pthread_mutex_lock(&ThreadBase::m_global.lock);
// if (pthread_mutex_lock(&ThreadBase::m_global.lock))
// throw internal_error("Mutex failed.");
__sync_fetch_and_sub(&ThreadBase::m_global.waiting, 1);
}
inline void
ThreadBase::release_global_lock() {
pthread_mutex_unlock(&ThreadBase::m_global.lock);
}
inline void
ThreadBase::waive_global_lock() {
__sync_synchronize();
pthread_mutex_unlock(&ThreadBase::m_global.lock);
// Do we need to sleep here? Make a CppUnit test for this.
acquire_global_lock();
}
#endif