summaryrefslogtreecommitdiff
path: root/components/cplusplus/cpp11/gcc/__utils.h
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-28 10:36:54 +0800
committerGitHub <[email protected]>2021-09-28 10:36:54 +0800
commit55a302cd092758a44b589d65470a69d9e8ae4ced (patch)
treee60fc53994c426007e9eb4877e5bd123f124ef39 /components/cplusplus/cpp11/gcc/__utils.h
parent00727d6b6db92dc1cf98f028f26fd6168594b905 (diff)
parent00d42ef73cff61ecda7ff006b077a73e1a4ff669 (diff)
Merge branch 'master' into usbh_construct
Diffstat (limited to 'components/cplusplus/cpp11/gcc/__utils.h')
-rw-r--r--components/cplusplus/cpp11/gcc/__utils.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/components/cplusplus/cpp11/gcc/__utils.h b/components/cplusplus/cpp11/gcc/__utils.h
new file mode 100644
index 0000000000..f9a3c93796
--- /dev/null
+++ b/components/cplusplus/cpp11/gcc/__utils.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-27 flybreak the first version.
+ */
+
+#pragma once
+
+#include <cstdlib>
+#include <system_error>
+#include <chrono>
+#include <ratio>
+
+#include <rtthread.h>
+
+#define RT_USING_CPP_EXCEPTION
+
+inline void throw_system_error(int err, const char *what_msg)
+{
+#ifdef RT_USING_CPP_EXCEPTION
+ throw std::system_error(std::error_code(err, std::system_category()), what_msg);
+#else
+ (void)err;
+ (void)what_msg;
+ ::abort();
+#endif
+}
+
+class tick_clock
+{
+public:
+ typedef clock_t rep;
+ typedef std::ratio<1, RT_TICK_PER_SECOND> period;
+
+ typedef std::chrono::duration<tick_clock::rep, tick_clock::period> duration;
+ typedef std::chrono::time_point<tick_clock> time_point;
+
+ constexpr static bool is_ready = true;
+
+ static time_point now();
+};
+
+class real_time_clock
+{
+public:
+ typedef std::chrono::nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<real_time_clock, duration> time_point;
+
+ static constexpr bool is_steady = true;
+
+ static time_point
+ now() noexcept;
+};