MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_clock_gettime

Function sys_clock_gettime

components/lwp/lwp_syscall.c:8094–8132  ·  view source on GitHub ↗

* @brief Retrieves the current time of a specified clock. * * This function retrieves the current time of the specified clock (identified by `clk`) and stores it in the * `struct timespec` pointed to by `ts`. The time is expressed in seconds and nanoseconds. The clock can be * one of several types, such as real-time, monotonic, or process-specific clocks. * * @param[in] clk The clock ID for

Source from the content-addressed store, hash-verified

8092 * @see sys_clock_settime(), sys_clock_getres()
8093 */
8094sysret_t sys_clock_gettime(clockid_t clk, struct timespec *ts)
8095{
8096 int ret = 0;
8097#ifdef ARCH_MM_MMU
8098 size_t size = sizeof(struct timespec);
8099 struct timespec *kts = NULL;
8100
8101 if (!lwp_user_accessable((void *)ts, size))
8102 {
8103 return -EFAULT;
8104 }
8105
8106 kts = kmem_get(size);
8107 if (!kts)
8108 {
8109 return -ENOMEM;
8110 }
8111
8112 ret = clock_gettime(clk, kts);
8113 if (ret != -1)
8114 lwp_put_to_user(ts, kts, size);
8115
8116 if (ret < 0)
8117 {
8118 ret = GET_ERRNO();
8119 }
8120
8121 kmem_put(kts);
8122
8123 return ret;
8124#else
8125 if (!lwp_user_accessable((void *)ts, sizeof(struct timespec)))
8126 {
8127 return -EFAULT;
8128 }
8129 ret = clock_gettime(clk, ts);
8130 return (ret < 0 ? GET_ERRNO() : ret);
8131#endif
8132}
8133
8134/**
8135 * @brief Suspends the execution of the calling thread for the specified time duration.

Callers

nothing calls this directly

Calls 5

lwp_user_accessableFunction · 0.85
kmem_getFunction · 0.85
clock_gettimeFunction · 0.85
lwp_put_to_userFunction · 0.85
kmem_putFunction · 0.85

Tested by

no test coverage detected