#include "time.hpp" #include <time.h> #include <type_traits> #include <mach/mach_time.h> #include <mach/mach.h> #include <mach/clock.h> namespace sprawl { namespace time { static double GetTimeBase() { mach_timebase_info_data_t info; mach_timebase_info(&info); return double(info.numer) / double(info.denom); } static double s_timeBase = GetTimeBase(); static struct ClockPort { ClockPort() { mach_port_t hostPort = mach_host_self(); host_get_clock_service(hostPort, CALENDAR_CLOCK, &port); mach_port_deallocate(mach_task_self(), hostPort); } ~ClockPort() { mach_port_deallocate(mach_task_self(), port); } mach_port_t port; } s_clockPort; int64_t Now(Resolution resolution) { mach_timespec_t ts; clock_get_time(s_clockPort.port, &ts); uint64_t nanosecondResult = ts.tv_sec; nanosecondResult *= 1000000000; nanosecondResult += ts.tv_nsec; return nanosecondResult / std::underlying_type<Resolution>::type(resolution); } int64_t SteadyNow(Resolution resolution) { uint64_t absTime = mach_absolute_time(); uint64_t nanosecondResult = absTime * s_timeBase; return nanosecondResult / std::underlying_type<Resolution>::type(resolution); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 14216 | ShadauxCat |
-Moved some global sprawl::Strings into local scope in json serialization test because of initialization order issues in the memory allocator on mac. This is a temporary fix, and a real fix will come by making the pool allocator work in explicitly-sized pieces and putting all the code for those pieces into a cpp file. -Fixed a large number of warnings on mac/linux that were exposed by fixes to csbuild -Fixed compile errors on mac due to malloc and alloca not being defined, fixed by #include <stdlib.h> in appropriate places -Fixed mac os x trying to link against pthread erroneously -Provided os x implementation of time library -Fixed compile errors on os x due to std::unordered_map whining about the difference between an allocator that allocates std::pair<key, value> and one that allocates std::pair<key const, value>, which, of course, is that the allocator will be no different at all. -Fixed an actual issue where one unordered_map was allocating only key_type instead of std::pair<key_type, value_type> -Fixed a memory leak where coroutine objects would never be cleaned up because either Yield() or reactivate_() will never return (and thus never clean up their stack memory and thus never release any dynamic memory held in stack objects) depending on the situation - if the function runs to completion, reactivate_() never returns after calling swapcontext(); meanwhile, if the function does not run to completion, Yield() never returns after calling Pause(). This behavior will need to be well-documented because it will affect client-side code as well. Stack memory within a coroutine should not rely on RAII behavior. -Fixed compile failure when creating a StlWrapper with a const value_type #review-14217 |