MCPcopy Create free account
hub / github.com/VCVRack/Rack / getThreadTime

Function getThreadTime

src/system.cpp:792–818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

790
791
792double getThreadTime() {
793#if defined ARCH_LIN
794 struct timespec ts;
795 clockid_t cid;
796 pthread_getcpuclockid(pthread_self(), &cid);
797 clock_gettime(cid, &ts);
798 return ts.tv_sec + ts.tv_nsec * 1e-9;
799#elif defined ARCH_MAC
800 mach_port_t thread = mach_thread_self();
801 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
802 thread_basic_info_data_t info;
803 kern_return_t kr = thread_info(thread, THREAD_BASIC_INFO, (thread_info_t) &info, &count);
804 if (kr != KERN_SUCCESS || (info.flags & TH_FLAGS_IDLE) != 0)
805 return 0.0;
806 return info.user_time.seconds + info.user_time.microseconds * 1e-6;
807#elif defined ARCH_WIN
808 FILETIME creationTime;
809 FILETIME exitTime;
810 FILETIME kernelTime;
811 FILETIME userTime;
812 if (GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime) == 0)
813 return 0.0;
814 return ((uint64_t(userTime.dwHighDateTime) << 32) + userTime.dwLowDateTime) * 1e-7;
815#else
816 return 0.0;
817#endif
818}
819
820
821void sleep(double time) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected