mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 15:12:23 +01:00
EmergeManager: Do not queue duplicate block requests
This commit is contained in:
parent
b67eab3b00
commit
9f988e3b96
@ -292,14 +292,18 @@ bool EmergeManager::enqueueBlockEmergeEx(
|
|||||||
void *callback_param)
|
void *callback_param)
|
||||||
{
|
{
|
||||||
EmergeThread *thread = NULL;
|
EmergeThread *thread = NULL;
|
||||||
|
bool entry_already_exists = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexAutoLock queuelock(m_queue_mutex);
|
MutexAutoLock queuelock(m_queue_mutex);
|
||||||
|
|
||||||
if (!pushBlockEmergeData(blockpos, peer_id, flags,
|
if (!pushBlockEmergeData(blockpos, peer_id, flags,
|
||||||
callback, callback_param))
|
callback, callback_param, &entry_already_exists))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (entry_already_exists)
|
||||||
|
return true;
|
||||||
|
|
||||||
thread = getOptimalThread();
|
thread = getOptimalThread();
|
||||||
thread->pushBlock(blockpos);
|
thread->pushBlock(blockpos);
|
||||||
}
|
}
|
||||||
@ -382,7 +386,8 @@ bool EmergeManager::pushBlockEmergeData(
|
|||||||
u16 peer_requested,
|
u16 peer_requested,
|
||||||
u16 flags,
|
u16 flags,
|
||||||
EmergeCompletionCallback callback,
|
EmergeCompletionCallback callback,
|
||||||
void *callback_param)
|
void *callback_param,
|
||||||
|
bool *entry_already_exists)
|
||||||
{
|
{
|
||||||
u16 &count_peer = m_peer_queue_count[peer_requested];
|
u16 &count_peer = m_peer_queue_count[peer_requested];
|
||||||
|
|
||||||
@ -402,12 +407,12 @@ bool EmergeManager::pushBlockEmergeData(
|
|||||||
findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData()));
|
findres = m_blocks_enqueued.insert(std::make_pair(pos, BlockEmergeData()));
|
||||||
|
|
||||||
BlockEmergeData &bedata = findres.first->second;
|
BlockEmergeData &bedata = findres.first->second;
|
||||||
bool update_existing = !findres.second;
|
*entry_already_exists = !findres.second;
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
bedata.callbacks.push_back(std::make_pair(callback, callback_param));
|
bedata.callbacks.push_back(std::make_pair(callback, callback_param));
|
||||||
|
|
||||||
if (update_existing) {
|
if (*entry_already_exists) {
|
||||||
bedata.flags |= flags;
|
bedata.flags |= flags;
|
||||||
} else {
|
} else {
|
||||||
bedata.flags = flags;
|
bedata.flags = flags;
|
||||||
|
11
src/emerge.h
11
src/emerge.h
@ -159,8 +159,15 @@ private:
|
|||||||
|
|
||||||
// Requires m_queue_mutex held
|
// Requires m_queue_mutex held
|
||||||
EmergeThread *getOptimalThread();
|
EmergeThread *getOptimalThread();
|
||||||
bool pushBlockEmergeData(v3s16 pos, u16 peer_requested, u16 flags,
|
|
||||||
EmergeCompletionCallback callback, void *callback_param);
|
bool pushBlockEmergeData(
|
||||||
|
v3s16 pos,
|
||||||
|
u16 peer_requested,
|
||||||
|
u16 flags,
|
||||||
|
EmergeCompletionCallback callback,
|
||||||
|
void *callback_param,
|
||||||
|
bool *entry_already_exists);
|
||||||
|
|
||||||
bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
|
bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
|
||||||
|
|
||||||
friend class EmergeThread;
|
friend class EmergeThread;
|
||||||
|
Loading…
Reference in New Issue
Block a user