Skip to content

Commit

Permalink
Reapply "libtorrent: Implement two hash queue threads (#28)"
Browse files Browse the repository at this point in the history
This reverts commit e5922cc.
  • Loading branch information
stickz committed Sep 15, 2024
1 parent e5922cc commit 62ffcc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions libtorrent/src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ Manager::Manager() :
m_main_thread_main.signal_bitfield()->add_signal(std::bind(&HashQueue::work, m_hashQueue)),
std::placeholders::_1);

m_hashQueueTwo = new HashQueue(&m_sub_thread_disk);
m_hashQueueTwo->slot_has_work() =
std::bind(&thread_base::send_event_signal,
&m_main_thread_main,
m_main_thread_main.signal_bitfield()->add_signal(std::bind(&HashQueue::work, m_hashQueueTwo)),
std::placeholders::_1);

m_taskTick.slot() = std::bind(&Manager::receive_tick, this);

priority_queue_insert(&taskScheduler, &m_taskTick, cachedTime.round_seconds());
Expand Down
7 changes: 6 additions & 1 deletion libtorrent/src/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Manager {
DownloadManager* download_manager() { return m_downloadManager; }
FileManager* file_manager() { return m_fileManager; }
HandshakeManager* handshake_manager() { return m_handshakeManager; }
HashQueue* hash_queue() { return m_hashQueue; }
HashQueue* hash_queue() { return ++m_hashQueueCount % 2 == 0 ? m_hashQueue : m_hashQueueTwo; }
ResourceManager* resource_manager() { return m_resourceManager; }

ChunkManager* chunk_manager() { return m_chunkManager; }
Expand All @@ -84,6 +84,7 @@ class Manager {

thread_main* main_thread_main() { return &m_main_thread_main; }
thread_disk* main_thread_disk() { return &m_main_thread_disk; }
thread_disk* sub_thread_disk() { return &m_sub_thread_disk; }

EncodingList* encoding_list() { return &m_encodingList; }

Expand All @@ -100,6 +101,7 @@ class Manager {
FileManager* m_fileManager;
HandshakeManager* m_handshakeManager;
HashQueue* m_hashQueue;
HashQueue* m_hashQueueTwo;
ResourceManager* m_resourceManager;

ChunkManager* m_chunkManager;
Expand All @@ -109,12 +111,15 @@ class Manager {

thread_main m_main_thread_main;
thread_disk m_main_thread_disk;
thread_disk m_sub_thread_disk;

EncodingList m_encodingList;

Throttle* m_uploadThrottle;
Throttle* m_downloadThrottle;

uint64_t m_hashQueueCount;

unsigned int m_ticks;
rak::priority_item m_taskTick;
};
Expand Down
3 changes: 3 additions & 0 deletions libtorrent/src/torrent/torrent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ initialize() {

manager->main_thread_disk()->init_thread();
manager->main_thread_disk()->start_thread();
manager->sub_thread_disk()->init_thread();
manager->sub_thread_disk()->start_thread();
}

// Clean up and close stuff. Stopping all torrents and waiting for
Expand All @@ -120,6 +122,7 @@ cleanup() {
throw internal_error("torrent::cleanup() called but the library is not initialized.");

manager->main_thread_disk()->stop_thread_wait();
manager->sub_thread_disk()->stop_thread_wait();

delete manager;
manager = NULL;
Expand Down

0 comments on commit 62ffcc1

Please sign in to comment.