Added priorities for messages

This commit is contained in:
r.kuznetsov 2015-03-12 16:52:18 +03:00
parent 2ebcafc4fc
commit bb5b8d39a3
15 changed files with 97 additions and 30 deletions

View file

@ -64,7 +64,7 @@ void BackendRenderer::AcceptMessage(dp::RefPointer<Message> message)
df::Viewport const & v = msg->GetViewport();
m_guiCacher.Resize(v.GetWidth(), v.GetHeight());
GuiLayerRecachedMessage * outputMsg = new GuiLayerRecachedMessage(m_guiCacher.Recache(m_texturesManager));
m_commutator->PostMessage(ThreadsCommutator::RenderThread, dp::MovePointer<df::Message>(outputMsg));
m_commutator->PostMessage(ThreadsCommutator::RenderThread, dp::MovePointer<df::Message>(outputMsg), MessagePriority::High);
break;
}
case Message::InvalidateReadManagerRect:
@ -161,7 +161,7 @@ void BackendRenderer::InitGLDependentResource()
void BackendRenderer::FlushGeometry(dp::TransferPointer<Message> message)
{
GLFunctions::glFlush();
m_commutator->PostMessage(ThreadsCommutator::RenderThread, message);
m_commutator->PostMessage(ThreadsCommutator::RenderThread, message, MessagePriority::Normal);
}
} // namespace df

View file

@ -60,31 +60,42 @@ void DrapeEngine::Resize(int w, int h)
m_viewport.SetViewport(0, 0, w, h);
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
dp::MovePointer<Message>(new ResizeMessage(m_viewport)));
dp::MovePointer<Message>(new ResizeMessage(m_viewport)),
MessagePriority::High);
}
void DrapeEngine::UpdateCoverage(ScreenBase const & screen)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
dp::MovePointer<Message>(new UpdateModelViewMessage(screen)));
dp::MovePointer<Message>(new UpdateModelViewMessage(screen)),
MessagePriority::Normal);
}
void DrapeEngine::ClearUserMarksLayer(df::TileKey const & tileKey)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
dp::MovePointer<Message>(new ClearUserMarkLayerMessage(tileKey)));
dp::MovePointer<Message>(new ClearUserMarkLayerMessage(tileKey)),
MessagePriority::Normal);
}
void DrapeEngine::ChangeVisibilityUserMarksLayer(TileKey const & tileKey, bool isVisible)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
dp::MovePointer<Message>(new ChangeUserMarkLayerVisibilityMessage(tileKey, isVisible)));
dp::MovePointer<Message>(new ChangeUserMarkLayerVisibilityMessage(tileKey, isVisible)),
MessagePriority::Normal);
}
void DrapeEngine::UpdateUserMarksLayer(TileKey const & tileKey, UserMarksProvider * provider)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
dp::MovePointer<Message>(new UpdateUserMarkLayerMessage(tileKey, provider)));
dp::MovePointer<Message>(new UpdateUserMarkLayerMessage(tileKey, provider)),
MessagePriority::Normal);
}
void DrapeEngine::SetRenderingEnabled(bool const isEnabled)
{
m_threadCommutator->PostMessageBroadcast(dp::MovePointer<Message>(new RenderingEnabledMessage(isEnabled)),
MessagePriority::High);
}
} // namespace df

View file

@ -34,6 +34,8 @@ public:
void ChangeVisibilityUserMarksLayer(TileKey const & tileKey, bool isVisible);
void UpdateUserMarksLayer(TileKey const & tileKey, UserMarksProvider * provider);
void SetRenderingEnabled(bool const isEnabled);
private:
dp::MasterPointer<FrontendRenderer> m_frontend;
dp::MasterPointer<BackendRenderer> m_backend;

View file

@ -21,12 +21,12 @@ EngineContext::EngineContext(dp::RefPointer<ThreadsCommutator> commutator)
void EngineContext::BeginReadTile(TileKey const & key)
{
PostMessage(new TileReadStartMessage(key));
PostMessage(new TileReadStartMessage(key), MessagePriority::Normal);
}
void EngineContext::InsertShape(TileKey const & key, dp::TransferPointer<MapShape> shape)
{
PostMessage(new MapShapeReadedMessage(key, shape));
PostMessage(new MapShapeReadedMessage(key, shape), MessagePriority::Normal);
}
void EngineContext::EndReadTile(TileKey const & key)
@ -63,12 +63,12 @@ void EngineContext::EndReadTile(TileKey const & key)
InsertShape(key, dp::MovePointer<df::MapShape>(new TextShape(r.Center(), tp)));
#endif
PostMessage(new TileReadEndMessage(key));
PostMessage(new TileReadEndMessage(key), MessagePriority::Normal);
}
void EngineContext::PostMessage(Message * message)
void EngineContext::PostMessage(Message * message, MessagePriority priority)
{
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, dp::MovePointer(message));
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, dp::MovePointer(message), priority);
}
} // namespace df

View file

@ -8,6 +8,7 @@ namespace df
{
class Message;
enum class MessagePriority;
class MapShape;
struct TileKey;
@ -23,7 +24,7 @@ public:
void EndReadTile(TileKey const & key);
private:
void PostMessage(Message * message);
void PostMessage(Message * message, MessagePriority priority);
private:
dp::RefPointer<ThreadsCommutator> m_commutator;

View file

@ -41,6 +41,7 @@ FrontendRenderer::FrontendRenderer(dp::RefPointer<ThreadsCommutator> commutator,
, m_textureManager(textureManager)
, m_gpuProgramManager(new dp::GpuProgramManager())
, m_viewport(viewport)
, m_isEnabled(true)
{
#ifdef DRAW_INFO
m_tpf = 0,0;
@ -153,9 +154,11 @@ void FrontendRenderer::AcceptMessage(dp::RefPointer<Message> message)
RefreshModelView();
ResolveTileKeys();
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
dp::MovePointer<Message>(new ResizeMessage(m_viewport)));
dp::MovePointer<Message>(new ResizeMessage(m_viewport)),
MessagePriority::Normal);
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
dp::MovePointer<Message>(new UpdateReadManagerMessage(m_view, m_tiles)));
dp::MovePointer<Message>(new UpdateReadManagerMessage(m_view, m_tiles)),
MessagePriority::Normal);
break;
}
@ -166,7 +169,8 @@ void FrontendRenderer::AcceptMessage(dp::RefPointer<Message> message)
RefreshModelView();
ResolveTileKeys();
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
dp::MovePointer<Message>(new UpdateReadManagerMessage(m_view, m_tiles)));
dp::MovePointer<Message>(new UpdateReadManagerMessage(m_view, m_tiles)),
MessagePriority::Normal);
break;
}
@ -179,7 +183,9 @@ void FrontendRenderer::AcceptMessage(dp::RefPointer<Message> message)
InvalidateRenderGroups(keyStorage);
Message * msgToBackend = new InvalidateReadManagerRectMessage(keyStorage);
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, dp::MovePointer(msgToBackend));
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
dp::MovePointer(msgToBackend),
MessagePriority::Normal);
break;
}

View file

@ -112,6 +112,8 @@ private:
set<TileKey> m_tiles;
dp::OverlayTree m_overlayTree;
bool m_isEnabled;
};
} // namespace df

View file

@ -21,11 +21,18 @@ public:
ClearUserMarkLayer,
ChangeUserMarkLayerVisibility,
UpdateUserMarkLayer,
GuiLayerRecached
GuiLayerRecached,
RenderingEnabled
};
virtual ~Message() {}
virtual Type GetType() const { return Unknown; }
};
enum class MessagePriority
{
Normal,
High
};
} // namespace df

View file

@ -16,9 +16,9 @@ void MessageAcceptor::ProcessSingleMessage(unsigned maxTimeWait)
message.Destroy();
}
void MessageAcceptor::PostMessage(dp::TransferPointer<Message> message)
void MessageAcceptor::PostMessage(dp::TransferPointer<Message> message, MessagePriority priority)
{
m_messageQueue.PushMessage(message);
m_messageQueue.PushMessage(message, priority);
}
void MessageAcceptor::CloseQueue()

View file

@ -24,7 +24,7 @@ protected:
private:
friend class ThreadsCommutator;
void PostMessage(dp::TransferPointer<Message> message);
void PostMessage(dp::TransferPointer<Message> message, MessagePriority priority);
private:
MessageQueue m_messageQueue;

View file

@ -28,12 +28,26 @@ dp::TransferPointer<Message> MessageQueue::PopMessage(unsigned maxTimeWait)
return msg.Move();
}
void MessageQueue::PushMessage(dp::TransferPointer<Message> message)
void MessageQueue::PushMessage(dp::TransferPointer<Message> message, MessagePriority priority)
{
threads::ConditionGuard guard(m_condition);
bool wasEmpty = m_messages.empty();
m_messages.push_back(dp::MasterPointer<Message>(message));
switch (priority)
{
case MessagePriority::Normal:
{
m_messages.push_back(dp::MasterPointer<Message>(message));
break;
}
case MessagePriority::High:
{
m_messages.insert(m_messages.begin(), dp::MasterPointer<Message>(message));
break;
}
default:
ASSERT(false, ("Unknown message priority type"));
}
if (wasEmpty)
guard.Signal();

View file

@ -6,7 +6,7 @@
#include "base/condition.hpp"
#include "std/list.hpp"
#include "std/deque.hpp"
namespace df
{
@ -18,7 +18,7 @@ public:
/// if queue is empty than return NULL
dp::TransferPointer<Message> PopMessage(unsigned maxTimeWait);
void PushMessage(dp::TransferPointer<Message> message);
void PushMessage(dp::TransferPointer<Message> message, MessagePriority priority);
void CancelWait();
void ClearQuery();
@ -27,7 +27,7 @@ private:
private:
threads::Condition m_condition;
list<dp::MasterPointer<Message> > m_messages;
deque<dp::MasterPointer<Message> > m_messages;
};
} // namespace df

View file

@ -237,4 +237,18 @@ private:
dp::TransferPointer<gui::LayerRenderer> m_renderer;
};
class RenderingEnabledMessage : public Message
{
public:
RenderingEnabledMessage(bool const isEnabled)
: m_isEnabled(isEnabled) {}
Type GetType() const override { return Message::RenderingEnabled; }
bool isSuspended() const { return m_isEnabled; }
private:
bool m_isEnabled;
};
} // namespace df

View file

@ -12,12 +12,20 @@ void ThreadsCommutator::RegisterThread(ThreadName name, MessageAcceptor * accept
VERIFY(m_acceptors.insert(make_pair(name, acceptor)).second, ());
}
void ThreadsCommutator::PostMessage(ThreadName name, dp::TransferPointer<Message> message)
void ThreadsCommutator::PostMessage(ThreadName name, dp::TransferPointer<Message> message, MessagePriority priority)
{
acceptors_map_t::iterator it = m_acceptors.find(name);
ASSERT(it != m_acceptors.end(), ());
if (it != m_acceptors.end())
it->second->PostMessage(message);
it->second->PostMessage(message, priority);
}
void ThreadsCommutator::PostMessageBroadcast(dp::TransferPointer<Message> message, MessagePriority priority)
{
for (auto it = m_acceptors.cbegin(); it != m_acceptors.cend(); ++it)
{
it->second->PostMessage(message, priority);
}
}
} // namespace df

View file

@ -7,6 +7,7 @@ namespace df
{
class Message;
enum class MessagePriority;
class MessageAcceptor;
class ThreadsCommutator
@ -19,11 +20,12 @@ public:
};
void RegisterThread(ThreadName name, MessageAcceptor *acceptor);
void PostMessage(ThreadName name, dp::TransferPointer<Message> message);
void PostMessage(ThreadName name, dp::TransferPointer<Message> message, MessagePriority priority);
void PostMessageBroadcast(dp::TransferPointer<Message> message, MessagePriority priority);
private:
typedef map<ThreadName, MessageAcceptor *> acceptors_map_t;
acceptors_map_t m_acceptors;
acceptors_map_t m_acceptors;
};
} // namespace df