aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'zencore')
-rw-r--r--zencore/compactbinary.cpp45
-rw-r--r--zencore/except.cpp17
-rw-r--r--zencore/filesystem.cpp20
-rw-r--r--zencore/include/zencore/compactbinarybuilder.h9
-rw-r--r--zencore/include/zencore/except.h7
-rw-r--r--zencore/include/zencore/trace.h4
-rw-r--r--zencore/include/zencore/zencore.h2
-rw-r--r--zencore/iobuffer.cpp6
-rw-r--r--zencore/thread.cpp169
-rw-r--r--zencore/trace.cpp11
10 files changed, 194 insertions, 96 deletions
diff --git a/zencore/compactbinary.cpp b/zencore/compactbinary.cpp
index 494b45581..cded378a1 100644
--- a/zencore/compactbinary.cpp
+++ b/zencore/compactbinary.cpp
@@ -197,8 +197,6 @@ DateTime::GetDate(int& Year, int& Month, int& Day) const
std::string
DateTime::ToString(const char* Format) const
{
- using namespace fmt::literals;
-
ExtendableStringBuilder<32> Result;
int Year, Month, Day;
@@ -215,32 +213,32 @@ DateTime::ToString(const char* Format) const
// case 'a': Result.Append(IsMorning() ? TEXT("am") : TEXT("pm")); break;
// case 'A': Result.Append(IsMorning() ? TEXT("AM") : TEXT("PM")); break;
case 'd':
- Result.Append("{:02}"_format(Day));
+ Result.Append(fmt::format("{:02}", Day));
break;
// case 'D': Result.Appendf(TEXT("%03i"), GetDayOfYear()); break;
case 'm':
- Result.Append("{:02}"_format(Month));
+ Result.Append(fmt::format("{:02}", Month));
break;
case 'y':
- Result.Append("{:02}"_format(Year % 100));
+ Result.Append(fmt::format("{:02}", Year % 100));
break;
case 'Y':
- Result.Append("{:04}"_format(Year));
+ Result.Append(fmt::format("{:04}", Year));
break;
case 'h':
- Result.Append("{:02}"_format(GetHour12()));
+ Result.Append(fmt::format("{:02}", GetHour12()));
break;
case 'H':
- Result.Append("{:02}"_format(GetHour()));
+ Result.Append(fmt::format("{:02}", GetHour()));
break;
case 'M':
- Result.Append("{:02}"_format(GetMinute()));
+ Result.Append(fmt::format("{:02}", GetMinute()));
break;
case 'S':
- Result.Append("{:02}"_format(GetSecond()));
+ Result.Append(fmt::format("{:02}", GetSecond()));
break;
case 's':
- Result.Append("{:03}"_format(GetMillisecond()));
+ Result.Append(fmt::format("{:03}", GetMillisecond()));
break;
default:
Result.Append(*Format);
@@ -282,8 +280,6 @@ TimeSpan::Set(int Days, int Hours, int Minutes, int Seconds, int FractionNano)
std::string
TimeSpan::ToString(const char* Format) const
{
- using namespace fmt::literals;
-
StringBuilder<128> Result;
Result.Append((int64_t(Ticks) < 0) ? '-' : '+');
@@ -295,31 +291,31 @@ TimeSpan::ToString(const char* Format) const
switch (*Format)
{
case 'd':
- Result.Append("{}"_format(GetDays()));
+ Result.Append(fmt::format("{}", GetDays()));
break;
case 'D':
- Result.Append("{:08}"_format(GetDays()));
+ Result.Append(fmt::format("{:08}", GetDays()));
break;
case 'h':
- Result.Append("{:02}"_format(GetHours()));
+ Result.Append(fmt::format("{:02}", GetHours()));
break;
case 'm':
- Result.Append("{:02}"_format(GetMinutes()));
+ Result.Append(fmt::format("{:02}", GetMinutes()));
break;
case 's':
- Result.Append("{:02}"_format(GetSeconds()));
+ Result.Append(fmt::format("{:02}", GetSeconds()));
break;
case 'f':
- Result.Append("{:03}"_format(GetFractionMilli()));
+ Result.Append(fmt::format("{:03}", GetFractionMilli()));
break;
case 'u':
- Result.Append("{:06}"_format(GetFractionMicro()));
+ Result.Append(fmt::format("{:06}", GetFractionMicro()));
break;
case 't':
- Result.Append("{:07}"_format(GetFractionTicks()));
+ Result.Append(fmt::format("{:07}", GetFractionTicks()));
break;
case 'n':
- Result.Append("{:09}"_format(GetFractionNano()));
+ Result.Append(fmt::format("{:09}", GetFractionNano()));
break;
default:
Result.Append(*Format);
@@ -1442,7 +1438,6 @@ public:
void WriteField(CbFieldView Field)
{
- using namespace fmt::literals;
using namespace std::literals;
WriteOptionalComma();
@@ -1512,7 +1507,7 @@ public:
const float Value = Accessor.AsFloat32();
if (std::isfinite(Value))
{
- Builder.Append("{:.9g}"_format(Value));
+ Builder.Append(fmt::format("{:.9g}", Value));
}
else
{
@@ -1525,7 +1520,7 @@ public:
const double Value = Accessor.AsFloat64();
if (std::isfinite(Value))
{
- Builder.Append("{:.17g}"_format(Value));
+ Builder.Append(fmt::format("{:.17g}", Value));
}
else
{
diff --git a/zencore/except.cpp b/zencore/except.cpp
index fae629286..2749d1984 100644
--- a/zencore/except.cpp
+++ b/zencore/except.cpp
@@ -58,12 +58,6 @@ ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string
#endif // ZEN_PLATFORM_WINDOWS
void
-ThrowLastError(std::string_view Message)
-{
- throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), std::string(Message));
-}
-
-void
ThrowSystemError(uint32_t ErrorCode, std::string_view Message)
{
throw std::system_error(std::error_code(ErrorCode, std::system_category()), std::string(Message));
@@ -83,11 +77,16 @@ GetSystemErrorAsString(uint32_t ErrorCode)
#if defined(__cpp_lib_source_location)
void
-ThrowLastError(std::string_view Message, const std::source_location& Location)
+ThrowLastErrorImpl(std::string_view Message, const std::source_location& Location)
{
- using namespace fmt::literals;
throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()),
- "{}({}): {}"_format(Location.file_name(), Location.line(), Message));
+ fmt::format("{}({}): {}", Location.file_name(), Location.line(), Message));
+}
+#else
+void
+ThrowLastError(std::string_view Message)
+{
+ throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), std::string(Message));
}
#endif
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 2507037ea..bed08b3f5 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -487,8 +487,6 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
&CancelFlag,
/* dwCopyFlags */ 0);
#else
- using namespace fmt::literals;
-
struct ScopedFd
{
~ScopedFd() { close(Fd); }
@@ -499,7 +497,7 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
int FromFd = open(FromPath.c_str(), O_RDONLY | O_CLOEXEC);
if (FromFd < 0)
{
- ThrowLastError("failed to open file {}"_format(FromPath));
+ ThrowLastError(fmt::format("failed to open file {}", FromPath));
}
ScopedFd $From = {FromFd};
@@ -507,7 +505,7 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
int ToFd = open(ToPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
if (ToFd < 0)
{
- ThrowLastError("failed to create file {}"_format(ToPath));
+ ThrowLastError(fmt::format("failed to create file {}", ToPath));
}
ScopedFd $To = {ToFd};
@@ -543,8 +541,6 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
void
WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t BufferCount)
{
- using namespace fmt::literals;
-
#if ZEN_PLATFORM_WINDOWS
CAtlFile Outfile;
HRESULT hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
@@ -557,7 +553,7 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
if (FAILED(hRes))
{
- ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str());
+ ThrowSystemException(hRes, fmt::format("File open failed for '{}'", Path).c_str());
}
#else
@@ -571,7 +567,7 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
if (Fd < 0)
{
- ThrowLastError("File open failed for '{}'"_format(Path));
+ ThrowLastError(fmt::format("File open failed for '{}'", Path));
}
#endif
@@ -590,12 +586,12 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
hRes = Outfile.Write(DataPtr, gsl::narrow_cast<uint32_t>(WriteSize));
if (FAILED(hRes))
{
- ThrowSystemException(hRes, "File write failed for '{}'"_format(Path).c_str());
+ ThrowSystemException(hRes, fmt::format("File write failed for '{}'", Path).c_str());
}
#else
if (write(Fd, DataPtr, WriteSize) != int64_t(WriteSize))
{
- ThrowLastError("File write failed for '{}'"_format(Path));
+ ThrowLastError(fmt::format("File write failed for '{}'", Path));
}
#endif // ZEN_PLATFORM_WINDOWS
@@ -867,14 +863,12 @@ FileSystemTraversal::TraverseFileSystem(const std::filesystem::path& RootDir, Tr
}
}
#else
- using namespace fmt::literals;
-
/* Could also implement this using Linux's getdents() syscall */
DIR* Dir = opendir(RootDir.c_str());
if (Dir == nullptr)
{
- ThrowLastError("Failed to open directory for traversal: {}"_format(RootDir.c_str()));
+ ThrowLastError(fmt::format("Failed to open directory for traversal: {}", RootDir.c_str()));
}
for (struct dirent* Entry; (Entry = readdir(Dir));)
diff --git a/zencore/include/zencore/compactbinarybuilder.h b/zencore/include/zencore/compactbinarybuilder.h
index 5f6d9fd0c..aee95ea5b 100644
--- a/zencore/include/zencore/compactbinarybuilder.h
+++ b/zencore/include/zencore/compactbinarybuilder.h
@@ -539,6 +539,15 @@ operator<<(CbWriter& Writer, std::nullptr_t)
return Writer;
}
+#if defined(__clang__)
+inline CbWriter&
+operator<<(CbWriter& Writer, std::size_t Value)
+{
+ Writer.AddInteger(uint64_t(Value));
+ return Writer;
+}
+#endif
+
inline CbWriter&
operator<<(CbWriter& Writer, std::wstring_view Value)
{
diff --git a/zencore/include/zencore/except.h b/zencore/include/zencore/except.h
index 6719c1319..d714b6ade 100644
--- a/zencore/include/zencore/except.h
+++ b/zencore/include/zencore/except.h
@@ -20,10 +20,11 @@ namespace zen {
ZENCORE_API void ThrowSystemException [[noreturn]] (HRESULT hRes, std::string_view Message);
#endif // ZEN_PLATFORM_WINDOWS
-ZENCORE_API void ThrowLastError [[noreturn]] (std::string_view Message);
-
#if defined(__cpp_lib_source_location)
-ZENCORE_API void ThrowLastError [[noreturn]] (std::string_view Message, const std::source_location& Location);
+ZENCORE_API void ThrowLastErrorImpl [[noreturn]] (std::string_view Message, const std::source_location& Location);
+#define ThrowLastError(Message) ThrowLastErrorImpl(Message, std::source_location::current())
+#else
+ZENCORE_API void ThrowLastError [[noreturn]] (std::string_view Message);
#endif
ZENCORE_API void ThrowSystemError [[noreturn]] (uint32_t ErrorCode, std::string_view Message);
diff --git a/zencore/include/zencore/trace.h b/zencore/include/zencore/trace.h
index 8d8cebb51..f28fdeeaf 100644
--- a/zencore/include/zencore/trace.h
+++ b/zencore/include/zencore/trace.h
@@ -2,6 +2,8 @@
#pragma once
+/* clang-format off */
+
#include <zencore/zencore.h>
#if ZEN_WITH_TRACE
@@ -29,3 +31,5 @@ void TraceInit(const char* HostOrPath, TraceType Type);
#define ZEN_TRACE_CPU(x)
#endif // ZEN_WITH_TRACE
+
+/* clang-format on */
diff --git a/zencore/include/zencore/zencore.h b/zencore/include/zencore/zencore.h
index 8688ddc13..12eacfb00 100644
--- a/zencore/include/zencore/zencore.h
+++ b/zencore/include/zencore/zencore.h
@@ -132,7 +132,7 @@
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 = true;
+ 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
diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp
index 30865068a..b6bbedc40 100644
--- a/zencore/iobuffer.cpp
+++ b/zencore/iobuffer.cpp
@@ -231,8 +231,6 @@ static RwLock g_MappingLock;
void
IoBufferExtendedCore::Materialize() const
{
- using namespace fmt::literals;
-
// The synchronization scheme here is very primitive, if we end up with
// a lot of contention we can make it more fine-grained
@@ -264,7 +262,7 @@ IoBufferExtendedCore::Materialize() const
if (NewMmapHandle == nullptr)
{
throw std::system_error(std::error_code(::GetLastError(), std::system_category()),
- "CreateFileMapping failed on file '{}'"_format(zen::PathFromHandle(m_FileHandle)));
+ fmt::format("CreateFileMapping failed on file '{}'", zen::PathFromHandle(m_FileHandle)));
}
NewFlags |= kOwnsMmap;
@@ -291,7 +289,7 @@ IoBufferExtendedCore::Materialize() const
{
throw std::system_error(
std::error_code(zen::GetLastError(), std::system_category()),
- "MapViewOfFile failed (offset {:#x}, size {:#x}) file: '{}'"_format(MapOffset, MapSize, zen::PathFromHandle(m_FileHandle)));
+ fmt::format("MapViewOfFile failed (offset {:#x}, size {:#x}) file: '{}'", MapOffset, MapSize, zen::PathFromHandle(m_FileHandle)));
}
m_MappedPointer = MappedBase;
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 596549bb5..97d44e733 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -8,17 +8,22 @@
#include <zencore/string.h>
#include <zencore/testing.h>
+#if ZEN_PLATFORM_LINUX
+# if !defined(_GNU_SOURCE)
+# define _GNU_SOURCE // for semtimedop()
+# endif
+#endif
+
#if ZEN_PLATFORM_WINDOWS
# include <shellapi.h>
# include <Shlobj.h>
# include <zencore/windows.h>
-#elif ZEN_PLATFORM_LINUX
+#else
# include <chrono>
# include <condition_variable>
# include <mutex>
# include <fcntl.h>
-# include <mqueue.h>
# include <pthread.h>
# include <signal.h>
# include <sys/file.h>
@@ -27,6 +32,14 @@
# include <unistd.h>
#endif
+#if ZEN_PLATFORM_LINUX
+# include <mqueue.h>
+#endif
+
+#if ZEN_PLATFORM_MAC
+# include <sys/sem.h>
+#endif
+
#include <thread>
ZEN_THIRD_PARTY_INCLUDES_START
@@ -278,9 +291,9 @@ NamedEvent::NamedEvent(std::string_view EventName)
int LockResult = flock(Inner, LOCK_EX | LOCK_NB);
if (LockResult == 0)
{
- // This is really thread safe as the message queue could be set between
- // getting the exclusive lock and checking the queue. But for the our
- // simple synchronising of process, this should be okay.
+ // This isn't really thread safe as the message queue could be set
+ // between getting the exclusive lock and checking the queue. But for
+ // the our simple synchronising of process, this should be okay.
while (!IsMessageQueueEmpty(Inner))
{
char Sink;
@@ -289,8 +302,51 @@ NamedEvent::NamedEvent(std::string_view EventName)
}
m_EventHandle = (void*)intptr_t(Inner);
-#else
-# error Implement NamedEvent for this platform
+#elif ZEN_PLATFORM_MAC
+ // Create a file to back the semaphore
+ ExtendableStringBuilder<64> EventPath;
+ EventPath << "/tmp/" << EventName;
+
+ int Fd = open(EventPath.c_str(), O_RDWR|O_CREAT, 0644);
+ if (Fd < 0)
+ {
+ ThrowLastError(fmt::format("Failed to create '{}' for named event", EventPath));
+ }
+
+ // Use the file path to generate an IPC key
+ key_t IpcKey = ftok(EventPath.c_str(), 1);
+ if (IpcKey < 0)
+ {
+ close(Fd);
+ ThrowLastError("Failed to create an SysV IPC key");
+ }
+
+ // Use the key to create/open the semaphore
+ int Sem = semget(IpcKey, 1, 0600 | IPC_CREAT);
+ if (Sem < 0)
+ {
+ close(Fd);
+ ThrowLastError("Failed creating an SysV semaphore");
+ }
+
+ // Atomically claim ownership of the semaphore's key. The owner initialises
+ // the semaphore to 1 so we can use the wait-for-zero op as that does not
+ // modify the semaphore's value on a successful wait.
+ int LockResult = flock(Fd, LOCK_EX | LOCK_NB);
+ if (LockResult == 0)
+ {
+ // This isn't thread safe really. Another thread could open the same
+ // semaphore and successfully wait on it in the period of time where
+ // this comment is but before the semaphore's initialised.
+ semctl(Sem, 0, SETVAL, 1);
+ }
+
+ // 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;
+ m_EventHandle = (void*)Packed;
#endif
}
@@ -310,7 +366,7 @@ NamedEvent::Close()
#if ZEN_PLATFORM_WINDOWS
CloseHandle(m_EventHandle);
#elif ZEN_PLATFORM_LINUX
- int Inner = int(intptr_t(m_EventHandle));
+ int Inner = int(intptr_t(m_EventHandle));
if (flock(Inner, LOCK_EX | LOCK_NB) == 0)
{
@@ -320,6 +376,20 @@ NamedEvent::Close()
}
close(Inner);
+#elif ZEN_PLATFORM_MAC
+ int Fd = int(intptr_t(m_EventHandle) & 0xffff'ffff);
+
+ if (flock(Fd, LOCK_EX | LOCK_NB) == 0)
+ {
+ std::filesystem::path Name = PathFromHandle((void*)(intptr_t(Fd)));
+ unlink(Name.c_str());
+
+ flock(Fd, LOCK_UN | LOCK_NB);
+ close(Fd);
+
+ int Sem = int(intptr_t(m_EventHandle) >> 32);
+ semctl(Sem, 0, IPC_RMID);
+ }
#endif
m_EventHandle = nullptr;
@@ -343,6 +413,9 @@ NamedEvent::Set()
{
ThrowLastError("Unable to send set message to queue");
}
+#elif ZEN_PLATFORM_MAC
+ int Sem = int(intptr_t(m_EventHandle) >> 32);
+ semctl(Sem, 0, SETVAL, 0);
#endif
}
@@ -370,8 +443,8 @@ NamedEvent::Wait(int TimeoutMs)
}
struct timeval TimeoutValue = {
- .tv_sec = 0,
- .tv_usec = TimeoutMs << 10,
+ .tv_sec = (TimeoutMs >> 10),
+ .tv_usec = (TimeoutMs & 0x3ff) << 10,
};
struct timeval* TimeoutPtr = (TimeoutMs < 0) ? nullptr : &TimeoutValue;
@@ -379,6 +452,43 @@ NamedEvent::Wait(int TimeoutMs)
FD_ZERO(&FdSet);
FD_SET(Inner, &FdSet);
return select(Inner + 1, &FdSet, nullptr, nullptr, TimeoutPtr) > 0;
+#elif ZEN_PLATFORM_MAC
+ int Sem = int(intptr_t(m_EventHandle) >> 32);
+
+ int Result;
+ struct sembuf SemOp = {};
+
+ if (TimeoutMs < 0)
+ {
+ Result = semop(Sem, &SemOp, 1);
+ return Result == 0;
+ }
+
+#if defined(_GNU_SOURCE)
+ struct timespec TimeoutValue = {
+ .tv_sec = TimeoutMs >> 10,
+ .tv_nsec = (TimeoutMs & 0x3ff) << 20,
+ };
+ int Result = semtimedop(Sem, &SemOp, 1, &TimeoutValue);
+ return Result == 0;
+#else
+ const int SleepTimeMs = 10;
+ SemOp.sem_flg = IPC_NOWAIT;
+ do
+ {
+ Result = semop(Sem, &SemOp, 1);
+ if (Result == 0 || errno != EAGAIN)
+ {
+ break;
+ }
+
+ Sleep(SleepTimeMs);
+ TimeoutMs -= SleepTimeMs;
+ }
+ while (TimeoutMs > 0);
+
+ return Result == 0;
+#endif // _GNU_SOURCE
#endif
}
@@ -511,19 +621,16 @@ ProcessHandle::Initialize(int Pid)
#if ZEN_PLATFORM_WINDOWS
m_ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, Pid);
-#elif ZEN_PLATFORM_LINUX
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
if (Pid > 0)
{
m_ProcessHandle = (void*)(intptr_t(Pid));
}
-#else
-# error Check process control on this platform
#endif
if (!m_ProcessHandle)
{
- using namespace fmt::literals;
- ThrowLastError("ProcessHandle::Initialize(pid: {}) failed"_format(Pid));
+ ThrowLastError(fmt::format("ProcessHandle::Initialize(pid: {}) failed", Pid));
}
m_Pid = Pid;
@@ -538,12 +645,8 @@ ProcessHandle::IsRunning() const
DWORD ExitCode = 0;
GetExitCodeProcess(m_ProcessHandle, &ExitCode);
bActive = (ExitCode == STILL_ACTIVE);
-#elif ZEN_PLATFORM_LINUX
- StringBuilder<64> ProcPath;
- ProcPath << "/proc/" << m_Pid;
- bActive = (access(ProcPath.c_str(), F_OK) != 0);
-#else
-# error Check process control on this platform
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+ bActive = (kill(pid_t(m_Pid), 0) == 0);
#endif
return bActive;
@@ -569,11 +672,9 @@ ProcessHandle::Terminate(int ExitCode)
TerminateProcess(m_ProcessHandle, ExitCode);
DWORD WaitResult = WaitForSingleObject(m_ProcessHandle, INFINITE);
bSuccess = (WaitResult != WAIT_OBJECT_0);
-#elif ZEN_PLATFORM_LINUX
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
ZEN_UNUSED(ExitCode);
- bSuccess = (kill(m_Pid, SIGKILL) == 0);
-#else
-# error Check kill() on this platform
+ bSuccess = (kill(m_Pid, SIGKILL) == 0);
#endif
if (!bSuccess)
@@ -616,7 +717,7 @@ ProcessHandle::Wait(int TimeoutMs)
case WAIT_FAILED:
break;
}
-#elif ZEN_PLATFORM_LINUX
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
const int SleepMs = 20;
timespec SleepTime = {0, SleepMs * 1000 * 1000};
for (int i = 0;; i += SleepMs)
@@ -640,8 +741,6 @@ ProcessHandle::Wait(int TimeoutMs)
nanosleep(&SleepTime, nullptr);
}
-#else
-# error Check kill() on this platform
#endif
// What might go wrong here, and what is meaningful to act on?
@@ -1012,20 +1111,14 @@ IsProcessRunning(int pid)
return false;
}
- using namespace fmt::literals;
- ThrowSystemError(Error, "failed to open process with pid {}"_format(pid));
+ ThrowSystemError(Error, fmt::format("failed to open process with pid {}", pid));
}
CloseHandle(hProc);
return true;
-#elif ZEN_PLATFORM_LINUX
- char Buffer[64];
- sprintf(Buffer, "/proc/%d", pid);
- return access(Buffer, F_OK) == 0;
-#elif ZEN_PLATFORM_MAC
- kill(pid_t(pid), 0);
- return errno != ESRCH;
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+ return (kill(pid_t(pid), 0) == 0);
#endif
}
@@ -1078,6 +1171,8 @@ TEST_CASE("Thread")
int Pid = GetCurrentProcessId();
CHECK(Pid > 0);
CHECK(IsProcessRunning(Pid));
+
+ CHECK_FALSE(GetCurrentThreadId() == 0);
}
TEST_CASE("BuildArgV")
diff --git a/zencore/trace.cpp b/zencore/trace.cpp
index f6a303960..6a35571e6 100644
--- a/zencore/trace.cpp
+++ b/zencore/trace.cpp
@@ -1,12 +1,13 @@
// Copyright Epic Games, Inc. All Rights Reserved.
+/* clang-format off */
+
#if ZEN_WITH_TRACE
-# include <zencore/zencore.h>
+#include <zencore/zencore.h>
-# define TRACE_IMPLEMENT 1
-# include <zencore/trace.h>
-//#undef TRACE_IMPLEMENT
+#define TRACE_IMPLEMENT 1
+#include <zencore/trace.h>
void
TraceInit(const char* HostOrPath, TraceType Type)
@@ -31,3 +32,5 @@ TraceInit(const char* HostOrPath, TraceType Type)
}
#endif // ZEN_WITH_TRACE
+
+/* clang-format on */