1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Protects against concurrent access to in game console texts.

This commit is contained in:
Frank Zago 2009-06-09 03:53:29 +00:00
parent fcc4acc451
commit cbf2ed6b7a
2 changed files with 10 additions and 0 deletions

View File

@ -2967,6 +2967,8 @@ void CInGameConsole::show(SDL_Surface * to)
std::vector<std::list< std::pair< std::string, int > >::iterator> toDel;
texts_mx.lock();
for(std::list< std::pair< std::string, int > >::iterator it = texts.begin(); it != texts.end(); ++it, ++number)
{
SDL_Color green = {0,0xff,0,0};
@ -2986,16 +2988,22 @@ void CInGameConsole::show(SDL_Surface * to)
{
texts.erase(toDel[it]);
}
texts_mx.unlock();
}
void CInGameConsole::print(const std::string &txt)
{
texts_mx.lock();
texts.push_back(std::make_pair(txt, SDL_GetTicks()));
if(texts.size() > maxDisplayedTexts)
{
texts.pop_front();
}
texts_mx.unlock();
}
void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)

View File

@ -7,6 +7,7 @@
#include "FunctionList.h"
#include <set>
#include <list>
#include <boost/thread/shared_mutex.hpp>
#ifdef max
#undef max
@ -532,6 +533,7 @@ class CInGameConsole : public IShowActivable, public KeyInterested
{
private:
std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
boost::mutex texts_mx; // protects texts
std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
int defaultTimeout; //timeout for new texts (in ms)