Skip to content

Commit

Permalink
Use wz::mutex instead of WZ_MUTEX.
Browse files Browse the repository at this point in the history
Can't use std::mutex when cross-compiling.

See f5c622e.
  • Loading branch information
Cyp committed Sep 8, 2016
1 parent 293ea01 commit 735347d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/console.cpp
Expand Up @@ -41,6 +41,7 @@
#include <string>
#include <istream>
#include <deque>
#include <mutex>

// FIXME: When we switch over to full JS, use class version of this file

Expand Down Expand Up @@ -70,7 +71,7 @@ struct CONSOLE_MESSAGE
bool team; // team message or not
CONSOLE_MESSAGE() : timeAdded(0), JustifyType(0), player(0), team(false) {}
};
WZ_MUTEX *mtx = wzMutexCreate(); // prevent adding messages when we are not expecting them
wz::mutex mtx; // prevent adding messages when we are not expecting them
std::deque<CONSOLE_MESSAGE> ActiveMessages; // we add all messages to this container
std::deque<CONSOLE_MESSAGE> TeamMessages; // history of team/private communications
std::deque<CONSOLE_MESSAGE> HistoryMessages; // history of all other communications
Expand Down Expand Up @@ -196,7 +197,7 @@ bool addConsoleMessage(const char *Text, CONSOLE_TEXT_JUSTIFICATION jusType, SDW

consoleStorage.text = messageText;
consoleStorage.timeAdded = realTime; // Store the time when it was added
wzMutexLock(mtx); // Don't add messages unless locked!
std::lock_guard<wz::mutex> lck(mtx); // Don't add messages unless locked!
if (player == INFO_MESSAGE)
{
InfoMessages.push_back(consoleStorage);
Expand All @@ -210,7 +211,6 @@ bool addConsoleMessage(const char *Text, CONSOLE_TEXT_JUSTIFICATION jusType, SDW
}
HistoryMessages.push_back(consoleStorage); // persistent messages (all types)
}
wzMutexUnlock(mtx);
}
return true;
}
Expand All @@ -231,7 +231,7 @@ void updateConsoleMessages(void)
{
return;
}
wzMutexLock(mtx); // don't remove messages unless locked
std::lock_guard<wz::mutex> lck(mtx); // Don't remove messages unless locked.
for (auto i = InfoMessages.begin(); i != InfoMessages.end();)
{
if (realTime - i->timeAdded > messageDuration)
Expand All @@ -255,7 +255,6 @@ void updateConsoleMessages(void)
++i;
}
}
wzMutexUnlock(mtx);
}

/**
Expand Down Expand Up @@ -422,7 +421,7 @@ void displayConsoleMessages(void)
displayOldMessages(HistoryMode);
}

wzMutexLock(mtx); // don't iterate without a lock
std::lock_guard<wz::mutex> lck(mtx); // Don't iterate without a lock.
if (InfoMessages.size())
{
auto i = InfoMessages.end() - 1; // we can only show the last one...
Expand All @@ -445,7 +444,6 @@ void displayConsoleMessages(void)
setConsoleTextColor(i->player);
TextYpos = iV_DrawFormattedText(i->text.c_str(), mainConsole.topX, TextYpos, mainConsole.width, i->JustifyType);
}
wzMutexUnlock(mtx);
}

/** Allows toggling of the box under the console text */
Expand Down

0 comments on commit 735347d

Please sign in to comment.