diff --git a/code/common/clock.cc b/code/common/clock.cc index 069cbb0..557baaa 100644 --- a/code/common/clock.cc +++ b/code/common/clock.cc @@ -1,9 +1,7 @@ #if defined(_WIN32) #include -#elif defined(__linux__) - #include #else - static_assert(false, "clock.cc is not implemented for this operating system"); + #include #endif #include @@ -27,13 +25,11 @@ namespace common::time QueryPerformanceCounter(&count); return count.QuadPart; - #elif defined(__linux__) + #else timespec ts; if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) debug::panic("Failed to get time!"); return (u64)ts.tv_nsec + (u64)1E9 * (u64)ts.tv_sec; - #else - static_assert(false, "Not implemented"); #endif } @@ -49,10 +45,8 @@ namespace common::time QueryPerformanceFrequency(&freq); s_cached_cycles_per_second = freq.QuadPart; - #elif defined(__linux__) - return (u64)1E9; #else - static_assert(false, "Not implemented"); + return (u64)1E9; #endif } diff --git a/code/common/dynamic_library.cc b/code/common/dynamic_library.cc index cbdba30..442e3e3 100644 --- a/code/common/dynamic_library.cc +++ b/code/common/dynamic_library.cc @@ -1,9 +1,7 @@ #if defined(_WIN32) #include -#elif defined(__linux__) -#include #else -#error Not Implemented +#include #endif #include "common/strings.h" @@ -15,10 +13,8 @@ namespace common { #if defined(_WIN32) using handle_type = wil::unique_hmodule; - #elif defined(__linux__) - using handle_type = void*; #else - #error Not Implemented + using handle_type = void*; #endif class dynamic_library::impl @@ -68,7 +64,7 @@ namespace common return reinterpret_cast(addr); } - #elif defined(__linux__) + #else bool dynamic_library::impl::open(std::string_view name) { const auto name_string = std::string{ name }; @@ -90,8 +86,6 @@ namespace common return dlsym(m_handle, name_string.c_str()); } - #else - #error Not Implemented #endif dynamic_library::dynamic_library() diff --git a/code/common/synchro.cc b/code/common/synchro.cc index f7de141..9d16313 100644 --- a/code/common/synchro.cc +++ b/code/common/synchro.cc @@ -1,10 +1,14 @@ #if defined(_WIN32) #include -#elif defined(__linux__) +#endif + +#if defined(__linux__) || defined(__APPLE__) #include #include -#else - static_assert(false, "synchro.cc not defined for this operating system"); +#endif + +#if defined(__APPLE__) + #include #endif #include "common/debug.h" @@ -24,6 +28,8 @@ namespace common::synchro return GetCurrentThreadId(); #elif defined(__linux__) return static_cast(pthread_self()); // Return type might need to be OS-dependent + #elif defined(__APPLE__) + return mach_thread_self(); #else static_assert(false, "Not implemented"); #endif @@ -43,6 +49,8 @@ namespace common::synchro p_set_thread_description(GetCurrentThread(), wname.c_str()); #elif defined(__linux__) pthread_setname_np(pthread_self(), name.data()); + #elif defined(__APPLE__) + pthread_setname_np(name.data()); #else static_assert(false, "Not implemented"); #endif @@ -52,7 +60,7 @@ namespace common::synchro { #if defined(_WIN32) Sleep(ms); - #elif defined(__linux__) + #elif defined(__linux__) || defined(__APPLE__) timespec ts; ts.tv_sec = ms / 1000; ts.tv_nsec = (ms % 1000) * 1000000;