mirror of
https://github.com/minetest/minetest.git
synced 2025-01-11 07:47:31 +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)
|
void Logger::log(LogLevel lev, const std::string &text)
|
||||||
{
|
{
|
||||||
if (m_silenced_levels[lev])
|
if (isLevelSilenced(lev))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const std::string thread_name = getThreadName();
|
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)
|
void Logger::logRaw(LogLevel lev, const std::string &text)
|
||||||
{
|
{
|
||||||
if (m_silenced_levels[lev])
|
if (isLevelSilenced(lev))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logToOutputsRaw(lev, text);
|
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);
|
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;
|
static LogColor color_mode;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -91,11 +95,7 @@ private:
|
|||||||
|
|
||||||
std::vector<ILogOutput *> m_outputs[LL_MAX];
|
std::vector<ILogOutput *> m_outputs[LL_MAX];
|
||||||
std::atomic<bool> m_has_outputs[LL_MAX];
|
std::atomic<bool> m_has_outputs[LL_MAX];
|
||||||
|
std::atomic<bool> m_silenced_levels[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::map<std::thread::id, std::string> m_thread_names;
|
std::map<std::thread::id, std::string> m_thread_names;
|
||||||
mutable std::mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
@ -1078,7 +1078,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||||||
bool have_sequence_number = false;
|
bool have_sequence_number = false;
|
||||||
bool have_initial_sequence_number = false;
|
bool have_initial_sequence_number = false;
|
||||||
std::queue<BufferedPacketPtr> toadd;
|
std::queue<BufferedPacketPtr> toadd;
|
||||||
volatile u16 initial_sequence_number = 0;
|
u16 initial_sequence_number = 0;
|
||||||
|
|
||||||
for (SharedBuffer<u8> &original : originals) {
|
for (SharedBuffer<u8> &original : originals) {
|
||||||
u16 seqnum = chan.getOutgoingSequenceNumber(have_sequence_number);
|
u16 seqnum = chan.getOutgoingSequenceNumber(have_sequence_number);
|
||||||
@ -1118,7 +1118,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||||||
return true;
|
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 */
|
/* we didn't get a single sequence number no need to fill queue */
|
||||||
if (!have_initial_sequence_number) {
|
if (!have_initial_sequence_number) {
|
||||||
LOG(derr_con << m_connection->getDesc() << "Ran out of sequence numbers!" << std::endl);
|
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 {
|
class TLSTestThread : public Thread {
|
||||||
public:
|
public:
|
||||||
@ -226,7 +226,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
void TestThreading::testTLS()
|
void TestThreading::testTLS()
|
||||||
{
|
{
|
||||||
static const int num_threads = 10;
|
constexpr int num_threads = 10;
|
||||||
|
|
||||||
for (int j = 0; j < num_threads; j++) {
|
for (int j = 0; j < num_threads; j++) {
|
||||||
g_tls_broken = false;
|
g_tls_broken = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user