mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	Merge pull request #4681 from FearlessTobi/port-2188-2190
Port yuzu-emu/yuzu#2188 and yuzu-emu/yuzu#2190: various minor code refactoring changes
This commit is contained in:
		
						commit
						e9c2b27c68
					
				
					 11 changed files with 51 additions and 56 deletions
				
			
		|  | @ -39,8 +39,10 @@ public: | |||
|     Impl(Impl const&) = delete; | ||||
|     const Impl& operator=(Impl const&) = delete; | ||||
| 
 | ||||
|     void PushEntry(Entry e) { | ||||
|         message_queue.Push(std::move(e)); | ||||
|     void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, | ||||
|                    const char* function, std::string message) { | ||||
|         message_queue.Push( | ||||
|             CreateEntry(log_class, log_level, filename, line_num, function, std::move(message))); | ||||
|     } | ||||
| 
 | ||||
|     void AddBackend(std::unique_ptr<Backend> backend) { | ||||
|  | @ -108,11 +110,33 @@ private: | |||
|         backend_thread.join(); | ||||
|     } | ||||
| 
 | ||||
|     Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | ||||
|                       const char* function, std::string message) const { | ||||
|         using std::chrono::duration_cast; | ||||
|         using std::chrono::steady_clock; | ||||
| 
 | ||||
|         // matches from the beginning up to the last '../' or 'src/'
 | ||||
|         static const std::regex trim_source_path(R"(.*([\/\\]|^)((\.\.)|(src))[\/\\])"); | ||||
| 
 | ||||
|         Entry entry; | ||||
|         entry.timestamp = | ||||
|             duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); | ||||
|         entry.log_class = log_class; | ||||
|         entry.log_level = log_level; | ||||
|         entry.filename = std::regex_replace(filename, trim_source_path, ""); | ||||
|         entry.line_num = line_nr; | ||||
|         entry.function = function; | ||||
|         entry.message = std::move(message); | ||||
| 
 | ||||
|         return entry; | ||||
|     } | ||||
| 
 | ||||
|     std::mutex writing_mutex; | ||||
|     std::thread backend_thread; | ||||
|     std::vector<std::unique_ptr<Backend>> backends; | ||||
|     Common::MPSCQueue<Log::Entry> message_queue; | ||||
|     Filter filter; | ||||
|     std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; | ||||
| }; | ||||
| 
 | ||||
| void ConsoleBackend::Write(const Entry& entry) { | ||||
|  | @ -249,27 +273,6 @@ const char* GetLevelName(Level log_level) { | |||
| #undef LVL | ||||
| } | ||||
| 
 | ||||
| Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | ||||
|                   const char* function, std::string message) { | ||||
|     using std::chrono::duration_cast; | ||||
|     using std::chrono::steady_clock; | ||||
| 
 | ||||
|     // matches from the beginning up to the last '../' or 'src/'
 | ||||
|     static const std::regex trim_source_path(R"(.*([\/\\]|^)((\.\.)|(src))[\/\\])"); | ||||
|     static steady_clock::time_point time_origin = steady_clock::now(); | ||||
| 
 | ||||
|     Entry entry; | ||||
|     entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); | ||||
|     entry.log_class = log_class; | ||||
|     entry.log_level = log_level; | ||||
|     entry.filename = std::regex_replace(filename, trim_source_path, ""); | ||||
|     entry.line_num = line_nr; | ||||
|     entry.function = function; | ||||
|     entry.message = std::move(message); | ||||
| 
 | ||||
|     return entry; | ||||
| } | ||||
| 
 | ||||
| void SetGlobalFilter(const Filter& filter) { | ||||
|     Impl::Instance().SetGlobalFilter(filter); | ||||
| } | ||||
|  | @ -294,9 +297,7 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, | |||
|     if (!filter.CheckMessage(log_class, log_level)) | ||||
|         return; | ||||
| 
 | ||||
|     Entry entry = | ||||
|         CreateEntry(log_class, log_level, filename, line_num, function, fmt::vformat(format, args)); | ||||
| 
 | ||||
|     instance.PushEntry(std::move(entry)); | ||||
|     instance.PushEntry(log_class, log_level, filename, line_num, function, | ||||
|                        fmt::vformat(format, args)); | ||||
| } | ||||
| } // namespace Log
 | ||||
|  |  | |||
|  | @ -136,10 +136,6 @@ const char* GetLogClassName(Class log_class); | |||
|  */ | ||||
| const char* GetLevelName(Level log_level); | ||||
| 
 | ||||
| /// Creates a log entry by formatting the given source location, and message.
 | ||||
| Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | ||||
|                   const char* function, std::string message); | ||||
| 
 | ||||
| /**
 | ||||
|  * The global filter will prevent any messages from even being processed if they are filtered. Each | ||||
|  * backend can have a filter, but if the level is lower than the global filter, the backend will | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue