mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-12 20:40:49 +00:00
Cut down on locking in DEBUG_LOG.
Reduces GenericLog() from 13.8% to 1.5% in Where Is My Heart?, will probably help other games to a lesser extent.
This commit is contained in:
parent
f300f46b9c
commit
ca938bf353
@ -172,13 +172,11 @@ void LogManager::LoadConfig(IniFile::Section *section) {
|
||||
}
|
||||
|
||||
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *file, int line, const char *format, va_list args) {
|
||||
std::lock_guard<std::mutex> lk(log_lock_);
|
||||
|
||||
char msg[MAX_MSGLEN * 2];
|
||||
LogChannel *log = log_[type];
|
||||
if (!log || !log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
|
||||
if (level > log->GetLevel() || !log->IsEnabled() || !log->HasListeners())
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lk(log_lock_);
|
||||
static const char level_to_char[8] = "-NEWIDV";
|
||||
char formattedTime[13];
|
||||
Common::Timer::GetTimeFormatted(formattedTime);
|
||||
@ -196,7 +194,8 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
|
||||
if (fileshort != file)
|
||||
file = fileshort + 1;
|
||||
}
|
||||
|
||||
|
||||
char msg[MAX_MSGLEN * 2];
|
||||
char *msgPos = msg;
|
||||
if (hleCurrentThreadName != NULL) {
|
||||
msgPos += sprintf(msgPos, "%s %-12.12s %c[%s]: %s:%d ",
|
||||
@ -228,7 +227,7 @@ void LogManager::Shutdown() {
|
||||
}
|
||||
|
||||
LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)
|
||||
: enable_(enable) {
|
||||
: enable_(enable), m_hasListeners(false) {
|
||||
strncpy(m_fullName, fullName, 128);
|
||||
strncpy(m_shortName, shortName, 32);
|
||||
#if defined(_DEBUG)
|
||||
@ -242,11 +241,13 @@ LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)
|
||||
void LogChannel::AddListener(LogListener *listener) {
|
||||
std::lock_guard<std::mutex> lk(m_listeners_lock);
|
||||
m_listeners.insert(listener);
|
||||
m_hasListeners = true;
|
||||
}
|
||||
|
||||
void LogChannel::RemoveListener(LogListener *listener) {
|
||||
std::lock_guard<std::mutex> lk(m_listeners_lock);
|
||||
m_listeners.erase(listener);
|
||||
m_hasListeners = !m_listeners.empty();
|
||||
}
|
||||
|
||||
void LogChannel::Trigger(LogTypes::LOG_LEVELS level, const char *msg) {
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
LogTypes::LOG_LEVELS GetLevel() const { return (LogTypes::LOG_LEVELS)level_; }
|
||||
|
||||
void SetLevel(LogTypes::LOG_LEVELS level) { level_ = level; }
|
||||
bool HasListeners() const { return !m_listeners.empty(); }
|
||||
bool HasListeners() const { return m_hasListeners; }
|
||||
|
||||
// Although not elegant, easy to set with a PopupMultiChoice...
|
||||
int level_;
|
||||
@ -94,6 +94,7 @@ private:
|
||||
char m_shortName[32];
|
||||
std::mutex m_listeners_lock;
|
||||
std::set<LogListener*> m_listeners;
|
||||
bool m_hasListeners;
|
||||
};
|
||||
|
||||
class ConsoleListener;
|
||||
|
Loading…
x
Reference in New Issue
Block a user