mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 14:42:24 +01:00
Stop misusing volatile keyword
This commit is contained in:
parent
4c9be808a7
commit
27cb54c1db
@ -253,7 +253,7 @@ const std::string Logger::getThreadName()
|
||||
|
||||
void Logger::log(LogLevel lev, const std::string &text)
|
||||
{
|
||||
if (m_silenced_levels[lev])
|
||||
if (isLevelSilenced(lev))
|
||||
return;
|
||||
|
||||
const std::string thread_name = getThreadName();
|
||||
@ -267,7 +267,7 @@ void Logger::log(LogLevel lev, const std::string &text)
|
||||
|
||||
void Logger::logRaw(LogLevel lev, const std::string &text)
|
||||
{
|
||||
if (m_silenced_levels[lev])
|
||||
if (isLevelSilenced(lev))
|
||||
return;
|
||||
|
||||
logToOutputsRaw(lev, text);
|
||||
|
10
src/log.h
10
src/log.h
@ -79,6 +79,10 @@ public:
|
||||
return m_has_outputs[level].load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
bool isLevelSilenced(LogLevel level) {
|
||||
return m_silenced_levels[level].load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
static LogColor color_mode;
|
||||
|
||||
private:
|
||||
@ -91,11 +95,7 @@ private:
|
||||
|
||||
std::vector<ILogOutput *> m_outputs[LL_MAX];
|
||||
std::atomic<bool> m_has_outputs[LL_MAX];
|
||||
|
||||
// Should implement atomic loads and stores (even though it's only
|
||||
// written to when one thread has access currently).
|
||||
// Works on all known architectures (x86, ARM, MIPS).
|
||||
volatile bool m_silenced_levels[LL_MAX];
|
||||
std::atomic<bool> m_silenced_levels[LL_MAX];
|
||||
std::map<std::thread::id, std::string> m_thread_names;
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
|
@ -1078,7 +1078,7 @@ bool UDPPeer::processReliableSendCommand(
|
||||
bool have_sequence_number = false;
|
||||
bool have_initial_sequence_number = false;
|
||||
std::queue<BufferedPacketPtr> toadd;
|
||||
volatile u16 initial_sequence_number = 0;
|
||||
u16 initial_sequence_number = 0;
|
||||
|
||||
for (SharedBuffer<u8> &original : originals) {
|
||||
u16 seqnum = chan.getOutgoingSequenceNumber(have_sequence_number);
|
||||
@ -1118,7 +1118,7 @@ bool UDPPeer::processReliableSendCommand(
|
||||
return true;
|
||||
}
|
||||
|
||||
volatile u16 packets_available = toadd.size();
|
||||
u16 packets_available = toadd.size();
|
||||
/* we didn't get a single sequence number no need to fill queue */
|
||||
if (!have_initial_sequence_number) {
|
||||
LOG(derr_con << m_connection->getDesc() << "Ran out of sequence numbers!" << std::endl);
|
||||
|
@ -161,7 +161,7 @@ void TestThreading::testAtomicSemaphoreThread()
|
||||
|
||||
|
||||
|
||||
static volatile bool g_tls_broken;
|
||||
static std::atomic<bool> g_tls_broken;
|
||||
|
||||
class TLSTestThread : public Thread {
|
||||
public:
|
||||
@ -226,7 +226,7 @@ private:
|
||||
*/
|
||||
void TestThreading::testTLS()
|
||||
{
|
||||
static const int num_threads = 10;
|
||||
constexpr int num_threads = 10;
|
||||
|
||||
for (int j = 0; j < num_threads; j++) {
|
||||
g_tls_broken = false;
|
||||
|
Loading…
Reference in New Issue
Block a user