diff options
| author | Per Larsson <[email protected]> | 2022-01-22 11:11:34 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-01-22 11:11:34 +0100 |
| commit | aef9c292beae2245da35f60fa8c8bd9c52fd248f (patch) | |
| tree | 798c254a0a3c867b5bc79c676684de7d47de6cc9 /zencore | |
| parent | Use ExtendablePathBuilders (diff) | |
| download | zen-aef9c292beae2245da35f60fa8c8bd9c52fd248f.tar.xz zen-aef9c292beae2245da35f60fa8c8bd9c52fd248f.zip | |
Format fix.
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/base64.cpp | 2 | ||||
| -rw-r--r-- | zencore/filesystem.cpp | 10 | ||||
| -rw-r--r-- | zencore/include/zencore/except.h | 2 | ||||
| -rw-r--r-- | zencore/include/zencore/memory.h | 6 | ||||
| -rw-r--r-- | zencore/include/zencore/string.h | 6 | ||||
| -rw-r--r-- | zencore/include/zencore/zencore.h | 53 | ||||
| -rw-r--r-- | zencore/iobuffer.cpp | 8 | ||||
| -rw-r--r-- | zencore/md5.cpp | 2 | ||||
| -rw-r--r-- | zencore/stats.cpp | 5 | ||||
| -rw-r--r-- | zencore/thread.cpp | 31 |
10 files changed, 71 insertions, 54 deletions
diff --git a/zencore/base64.cpp b/zencore/base64.cpp index 0448d7c2f..b97dfebbf 100644 --- a/zencore/base64.cpp +++ b/zencore/base64.cpp @@ -30,7 +30,7 @@ static const uint8_t DecodingAlphabet[256] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xe0-0xef 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 0xf0-0xff }; -#endif // 0 +#endif // 0 template<typename CharType> uint32_t diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index bed08b3f5..ee49aa474 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -765,7 +765,7 @@ DiskSpace DiskSpaceInfo(std::filesystem::path Directory, std::error_code& Error) { using namespace std::filesystem; - + space_info SpaceInfo = space(Directory, Error); if (Error) { @@ -940,7 +940,7 @@ PathFromHandle(void* NativeHandle) Link[BytesRead] = '\0'; return Link; #elif ZEN_PLATFORM_MAC - int Fd = int(uintptr_t(NativeHandle)); + int Fd = int(uintptr_t(NativeHandle)); char Path[MAXPATHLEN]; if (fcntl(Fd, F_GETPATH, Path) < 0) { @@ -968,10 +968,10 @@ GetRunningExecutablePath() Link[BytesRead] = '\0'; return Link; #elif ZEN_PLATFORM_MAC - char Buffer[PROC_PIDPATHINFO_MAXSIZE]; + char Buffer[PROC_PIDPATHINFO_MAXSIZE]; int SelfPid = GetCurrentProcessId(); - if (proc_pidpath(SelfPid, Buffer, sizeof(Buffer)) <= 0) + if (proc_pidpath(SelfPid, Buffer, sizeof(Buffer)) <= 0) return {}; return Buffer; @@ -1100,7 +1100,7 @@ TEST_CASE("DiskSpaceInfo") CHECK(Okay); CHECK(int64_t(Space.Total) > 0); - CHECK(int64_t(Space.Free) > 0); // Hopefully there's at least one byte free + CHECK(int64_t(Space.Free) > 0); // Hopefully there's at least one byte free } TEST_CASE("PathBuilder") diff --git a/zencore/include/zencore/except.h b/zencore/include/zencore/except.h index d714b6ade..c61db5ba9 100644 --- a/zencore/include/zencore/except.h +++ b/zencore/include/zencore/except.h @@ -22,7 +22,7 @@ ZENCORE_API void ThrowSystemException [[noreturn]] (HRESULT hRes, std::string_vi #if defined(__cpp_lib_source_location) ZENCORE_API void ThrowLastErrorImpl [[noreturn]] (std::string_view Message, const std::source_location& Location); -#define ThrowLastError(Message) ThrowLastErrorImpl(Message, std::source_location::current()) +# define ThrowLastError(Message) ThrowLastErrorImpl(Message, std::source_location::current()) #else ZENCORE_API void ThrowLastError [[noreturn]] (std::string_view Message); #endif diff --git a/zencore/include/zencore/memory.h b/zencore/include/zencore/memory.h index 40a3be18c..560fa9ffc 100644 --- a/zencore/include/zencore/memory.h +++ b/zencore/include/zencore/memory.h @@ -15,9 +15,11 @@ namespace zen { #if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L - template <typename T> concept ContiguousRange = std::ranges::contiguous_range<T>; +template<typename T> +concept ContiguousRange = std::ranges::contiguous_range<T>; #else - template <typename T> concept ContiguousRange = true; +template<typename T> +concept ContiguousRange = true; #endif struct MemoryView; diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h index 1afacc089..1e8907906 100644 --- a/zencore/include/zencore/string.h +++ b/zencore/include/zencore/string.h @@ -664,9 +664,9 @@ template<typename Fn> uint32_t ForEachStrTok(const std::string_view& Str, char Delim, Fn&& Func) { - const char* It = Str.data(); - const char* End = It + Str.length(); - uint32_t Count = 0; + const char* It = Str.data(); + const char* End = It + Str.length(); + uint32_t Count = 0; while (It != End) { diff --git a/zencore/include/zencore/zencore.h b/zencore/include/zencore/zencore.h index 9f8af8c41..023b237cd 100644 --- a/zencore/include/zencore/zencore.h +++ b/zencore/include/zencore/zencore.h @@ -139,23 +139,38 @@ // of std::integral. Some platforms like Ubuntu and Mac OS are still on 12. #if defined(__cpp_lib_concepts) # include <concepts> - template <class T> concept Integral = std::integral<T>; - template <class T> concept SignedIntegral = std::signed_integral<T>; - template <class T> concept UnsignedIntegral = std::unsigned_integral<T>; - template <class F, class... A> concept Invocable = std::invocable<F, A...>; - template <class D, class B> concept DerivedFrom = std::derived_from<D, B>; +template<class T> +concept Integral = std::integral<T>; +template<class T> +concept SignedIntegral = std::signed_integral<T>; +template<class T> +concept UnsignedIntegral = std::unsigned_integral<T>; +template<class F, class... A> +concept Invocable = std::invocable<F, A...>; +template<class D, class B> +concept DerivedFrom = std::derived_from<D, B>; #else - template <class T> concept Integral = std::is_integral_v<T>; - template <class T> concept SignedIntegral = Integral<T> && std::is_signed_v<T>; - template <class T> concept UnsignedIntegral = Integral<T> && !std::is_signed_v<T>; - template <class F, class... A> concept Invocable = requires(F&& f, A&&... a) { std::invoke(std::forward<F>(f), std::forward<A>(a)...); }; - template <class D, class B> concept DerivedFrom = std::is_base_of_v<B, D> && std::is_convertible_v<const volatile D*, const volatile B*>; +template<class T> +concept Integral = std::is_integral_v<T>; +template<class T> +concept SignedIntegral = Integral<T> && std::is_signed_v<T>; +template<class T> +concept UnsignedIntegral = Integral<T> && !std::is_signed_v<T>; +template<class F, class... A> +concept Invocable = requires(F&& f, A&&... a) +{ + std::invoke(std::forward<F>(f), std::forward<A>(a)...); +}; +template<class D, class B> +concept DerivedFrom = std::is_base_of_v<B, D> && std::is_convertible_v<const volatile D*, const volatile B*>; #endif #if defined(__cpp_lib_ranges) - template <typename T> concept ContiguousRange = std::ranges::contiguous_range<T>; +template<typename T> +concept ContiguousRange = std::ranges::contiguous_range<T>; #else - template <typename T> concept ContiguousRange = true; +template<typename T> +concept ContiguousRange = true; #endif ////////////////////////////////////////////////////////////////////////// @@ -224,13 +239,13 @@ static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size # define ZEN_DEBUG_SECTION ZEN_CODE_SECTION(".zcold") #endif -namespace zen { - -class AssertException : public std::logic_error +namespace zen { -public: - AssertException(const char* Msg) : std::logic_error(Msg) {} -}; + class AssertException : public std::logic_error + { + public: + AssertException(const char* Msg) : std::logic_error(Msg) {} + }; } // namespace zen @@ -315,7 +330,7 @@ ZENCORE_API void zencore_forcelinktests(); #ifndef ZEN_USE_MIMALLOC # if ZEN_ARCH_ARM64 - // The vcpkg mimalloc port doesn't support Arm targets + // The vcpkg mimalloc port doesn't support Arm targets # define ZEN_USE_MIMALLOC 0 # else # define ZEN_USE_MIMALLOC 1 diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index e4c1ad75a..e2aaa3169 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -288,9 +288,11 @@ IoBufferExtendedCore::Materialize() const if (MappedBase == nullptr) { - throw std::system_error( - std::error_code(zen::GetLastError(), std::system_category()), - fmt::format("MapViewOfFile failed (offset {:#x}, size {:#x}) file: '{}'", MapOffset, MapSize, zen::PathFromHandle(m_FileHandle))); + throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), + fmt::format("MapViewOfFile failed (offset {:#x}, size {:#x}) file: '{}'", + MapOffset, + MapSize, + zen::PathFromHandle(m_FileHandle))); } m_MappedPointer = MappedBase; diff --git a/zencore/md5.cpp b/zencore/md5.cpp index a5a5ea41d..faece3862 100644 --- a/zencore/md5.cpp +++ b/zencore/md5.cpp @@ -441,7 +441,7 @@ TEST_CASE("MD5") { using namespace std::literals; - auto Input = "jumblesmcgee"sv; + auto Input = "jumblesmcgee"sv; auto Output = "28f2200a59c60b75947099d750c2cc50"sv; MD5Stream Stream; diff --git a/zencore/stats.cpp b/zencore/stats.cpp index 595c45c3f..f783ccd3d 100644 --- a/zencore/stats.cpp +++ b/zencore/stats.cpp @@ -56,8 +56,7 @@ RawEWMA::Tick(double Alpha, uint64_t Interval, uint64_t Count, bool IsInitialUpd do { Next = Value + Delta; - } - while (!m_Rate.compare_exchange_weak(Value, Next, std::memory_order_relaxed)); + } while (!m_Rate.compare_exchange_weak(Value, Next, std::memory_order_relaxed)); #endif } } @@ -706,4 +705,4 @@ stats_forcelink() #endif -} // namespace zen +} // namespace zen::metrics diff --git a/zencore/thread.cpp b/zencore/thread.cpp index fa149321f..2cc4d8a96 100644 --- a/zencore/thread.cpp +++ b/zencore/thread.cpp @@ -10,7 +10,7 @@ #if ZEN_PLATFORM_LINUX # if !defined(_GNU_SOURCE) -# define _GNU_SOURCE // for semtimedop() +# define _GNU_SOURCE // for semtimedop() # endif #endif @@ -94,11 +94,11 @@ SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName) SetNameInternal(GetCurrentThreadId(), ThreadNameZ.c_str()); #else std::string ThreadNameZ{ThreadName}; -#if ZEN_PLATFORM_MAC +# if ZEN_PLATFORM_MAC pthread_setname_np(ThreadNameZ.c_str()); -#else +# else pthread_setname_np(pthread_self(), ThreadNameZ.c_str()); -#endif +# endif #endif } // namespace zen @@ -257,7 +257,7 @@ NamedEvent::NamedEvent(std::string_view EventName) ExtendableStringBuilder<64> EventPath; EventPath << "/tmp/" << EventName; - int Fd = open(EventPath.c_str(), O_RDWR|O_CREAT, 0644); + int Fd = open(EventPath.c_str(), O_RDWR | O_CREAT, 0644); if (Fd < 0) { ThrowLastError(fmt::format("Failed to create '{}' for named event", EventPath)); @@ -294,8 +294,8 @@ NamedEvent::NamedEvent(std::string_view EventName) // Pack into the handle static_assert(sizeof(Sem) + sizeof(Fd) <= sizeof(void*), "Semaphore packing assumptions not met"); intptr_t Packed; - Packed = intptr_t(Sem) << 32; - Packed |= intptr_t(Fd) & 0xffff'ffff; + Packed = intptr_t(Sem) << 32; + Packed |= intptr_t(Fd) & 0xffff'ffff; m_EventHandle = (void*)Packed; #endif } @@ -316,7 +316,7 @@ NamedEvent::Close() #if ZEN_PLATFORM_WINDOWS CloseHandle(m_EventHandle); #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - int Fd = int(intptr_t(m_EventHandle) & 0xffff'ffff); + int Fd = int(intptr_t(m_EventHandle) & 0xffff'ffff); if (flock(Fd, LOCK_EX | LOCK_NB) == 0) { @@ -363,7 +363,7 @@ NamedEvent::Wait(int TimeoutMs) #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC int Sem = int(intptr_t(m_EventHandle) >> 32); - int Result; + int Result; struct sembuf SemOp = {}; if (TimeoutMs < 0) @@ -372,15 +372,15 @@ NamedEvent::Wait(int TimeoutMs) return Result == 0; } -#if defined(_GNU_SOURCE) +# if defined(_GNU_SOURCE) struct timespec TimeoutValue = { .tv_sec = TimeoutMs >> 10, .tv_nsec = (TimeoutMs & 0x3ff) << 20, }; Result = semtimedop(Sem, &SemOp, 1, &TimeoutValue); -#else +# else const int SleepTimeMs = 10; - SemOp.sem_flg = IPC_NOWAIT; + SemOp.sem_flg = IPC_NOWAIT; do { Result = semop(Sem, &SemOp, 1); @@ -391,9 +391,8 @@ NamedEvent::Wait(int TimeoutMs) Sleep(SleepTimeMs); TimeoutMs -= SleepTimeMs; - } - while (TimeoutMs > 0); -#endif // _GNU_SOURCE + } while (TimeoutMs > 0); +# endif // _GNU_SOURCE return Result == 0; #endif @@ -581,7 +580,7 @@ ProcessHandle::Terminate(int ExitCode) bSuccess = (WaitResult != WAIT_OBJECT_0); #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC ZEN_UNUSED(ExitCode); - bSuccess = (kill(m_Pid, SIGKILL) == 0); + bSuccess = (kill(m_Pid, SIGKILL) == 0); #endif if (!bSuccess) |