diff options
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
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) |