aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-11-14 03:07:21 -0500
committerkwolekr <kwolekr@minetest.net>2016-01-19 04:18:06 -0500
commit9f988e3b962389e10a7cf010fd4bf0f81d70e31a (patch)
tree16d87f8aceea1f90c5a69b785a614b78a3f29fb9 /src
parentb67eab3b0050a1f08d9c56138969d1a659ee7eac (diff)
downloadminetest-9f988e3b962389e10a7cf010fd4bf0f81d70e31a.tar.gz
minetest-9f988e3b962389e10a7cf010fd4bf0f81d70e31a.tar.bz2
minetest-9f988e3b962389e10a7cf010fd4bf0f81d70e31a.zip
EmergeManager: Do not queue duplicate block requests
Diffstat (limited to 'src')
-rw-r--r--src/emerge.cpp13
-rw-r--r--src/emerge.h11
2 files changed, 18 insertions, 6 deletions
diff --git a/src/emerge.cpp b/src/emerge.cpp
index b188a7f41..ccb4c1703 100644
--- a/src/emerge.cpp
+++ b/src/emerge.cpp
@@ -292,14 +292,18 @@ bool EmergeManager::enqueueBlockEmergeEx(
void *callback_param)
{
EmergeThread *thread = NULL;
+ bool entry_already_exists = false;
{
MutexAutoLock queuelock(m_queue_mutex);
if (!pushBlockEmergeData(blockpos, peer_id, flags,
- callback, callback_param))
+ callback, callback_param, &entry_already_exists))
return false;
+ if (entry_already_exists)
+ return true;
+
thread = getOptimalThread();
thread->pushBlock(blockpos);
}
@@ -382,7 +386,8 @@ bool EmergeManager::pushBlockEmergeData(
u16 peer_requested,
u16 flags,
EmergeCompletionCallback callback,
- void *callback_param)
+ void *callback_param,
+ bool *entry_already_exists)
{
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()));
BlockEmergeData &bedata = findres.first->second;
- bool update_existing = !findres.second;
+ *entry_already_exists = !findres.second;
if (callback)
bedata.callbacks.push_back(std::make_pair(callback, callback_param));
- if (update_existing) {
+ if (*entry_already_exists) {
bedata.flags |= flags;
} else {
bedata.flags = flags;
diff --git a/src/emerge.h b/src/emerge.h
index a143b660f..02bdf7e67 100644
--- a/src/emerge.h
+++ b/src/emerge.h
@@ -159,8 +159,15 @@ private:
// Requires m_queue_mutex held
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);
friend class EmergeThread;