Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtorrent: Implement two hash queue threads #28

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading