mirror of
https://github.com/gabime/spdlog.git
synced 2026-04-10 11:34:29 +08:00
Gabime/fwrite unlocked (#3276)
* Use locking fwrite_unlocked if possible * Added compile definitions to header_only
This commit is contained in:
@@ -106,14 +106,14 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_t &color_code) {
|
||||
fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_);
|
||||
details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_);
|
||||
}
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted,
|
||||
size_t start,
|
||||
size_t end) {
|
||||
fwrite(formatted.data() + start, sizeof(char), end - start, target_file_);
|
||||
details::os::fwrite_bytes(formatted.data() + start, end - start, target_file_);
|
||||
}
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
#include <spdlog/details/console_globals.h>
|
||||
#include <spdlog/pattern_formatter.h>
|
||||
#include <spdlog/details/os.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
// under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675)
|
||||
@@ -22,7 +23,7 @@
|
||||
|
||||
#include <io.h> // _get_osfhandle(..)
|
||||
#include <stdio.h> // _fileno(..)
|
||||
#endif // WIN32
|
||||
#endif // _WIN32
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
@@ -44,7 +45,7 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
if (handle_ == INVALID_HANDLE_VALUE && file != stdout && file != stderr) {
|
||||
throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno);
|
||||
}
|
||||
#endif // WIN32
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
@@ -67,8 +68,8 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
#endif // WIN32
|
||||
details::os::fwrite_bytes(formatted.data(), formatted.size(), file_);
|
||||
#endif // _WIN32
|
||||
::fflush(file_); // flush every line to terminal
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user