mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02:00
Fix concurrency in texture source (#13150)
This commit is contained in:
parent
e21d5613a6
commit
ca13c51024
@ -405,7 +405,7 @@ private:
|
|||||||
std::mutex m_textureinfo_cache_mutex;
|
std::mutex m_textureinfo_cache_mutex;
|
||||||
|
|
||||||
// Queued texture fetches (to be processed by the main thread)
|
// Queued texture fetches (to be processed by the main thread)
|
||||||
RequestQueue<std::string, u32, u8, u8> m_get_texture_queue;
|
RequestQueue<std::string, u32, std::thread::id, u8> m_get_texture_queue;
|
||||||
|
|
||||||
// Textures that have been overwritten with other ones
|
// Textures that have been overwritten with other ones
|
||||||
// but can't be deleted because the ITexture* might still be used
|
// but can't be deleted because the ITexture* might still be used
|
||||||
@ -491,16 +491,16 @@ u32 TextureSource::getTextureId(const std::string &name)
|
|||||||
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;
|
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;
|
||||||
|
|
||||||
// We're gonna ask the result to be put into here
|
// We're gonna ask the result to be put into here
|
||||||
static thread_local ResultQueue<std::string, u32, u8, u8> result_queue;
|
static thread_local ResultQueue<std::string, u32, std::thread::id, u8> result_queue;
|
||||||
|
|
||||||
// Throw a request in
|
// Throw a request in
|
||||||
m_get_texture_queue.add(name, 0, 0, &result_queue);
|
m_get_texture_queue.add(name, std::this_thread::get_id(), 0, &result_queue);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while(true) {
|
while(true) {
|
||||||
// Wait for result for up to 4 seconds (empirical value)
|
// Wait for result for up to 1 seconds (empirical value)
|
||||||
GetResult<std::string, u32, u8, u8>
|
GetResult<std::string, u32, std::thread::id, u8>
|
||||||
result = result_queue.pop_front(4000);
|
result = result_queue.pop_front(1000);
|
||||||
|
|
||||||
if (result.key == name) {
|
if (result.key == name) {
|
||||||
return result.item;
|
return result.item;
|
||||||
@ -726,10 +726,10 @@ void TextureSource::processQueue()
|
|||||||
/*
|
/*
|
||||||
Fetch textures
|
Fetch textures
|
||||||
*/
|
*/
|
||||||
//NOTE this is only thread safe for ONE consumer thread!
|
// NOTE: process outstanding requests from all mesh generation threads
|
||||||
if (!m_get_texture_queue.empty())
|
while (!m_get_texture_queue.empty())
|
||||||
{
|
{
|
||||||
GetRequest<std::string, u32, u8, u8>
|
GetRequest<std::string, u32, std::thread::id, u8>
|
||||||
request = m_get_texture_queue.pop();
|
request = m_get_texture_queue.pop();
|
||||||
|
|
||||||
/*infostream<<"TextureSource::processQueue(): "
|
/*infostream<<"TextureSource::processQueue(): "
|
||||||
|
Loading…
Reference in New Issue
Block a user