File indexing completed on 2026-05-10 08:42:58
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_UTILITY_TIMEOUT_H
0010 #define LLDB_UTILITY_TIMEOUT_H
0011
0012 #include "llvm/Support/Chrono.h"
0013 #include "llvm/Support/FormatProviders.h"
0014 #include <optional>
0015
0016 namespace lldb_private {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 template <typename Ratio>
0028 class Timeout : public std::optional<std::chrono::duration<int64_t, Ratio>> {
0029 private:
0030 template <typename Ratio2> using Dur = std::chrono::duration<int64_t, Ratio2>;
0031 template <typename Rep2, typename Ratio2>
0032 using EnableIf = std::enable_if<
0033 std::is_convertible<std::chrono::duration<Rep2, Ratio2>,
0034 std::chrono::duration<int64_t, Ratio>>::value>;
0035
0036 using Base = std::optional<Dur<Ratio>>;
0037
0038 public:
0039 Timeout(std::nullopt_t none) : Base(none) {}
0040
0041 template <typename Ratio2,
0042 typename = typename EnableIf<int64_t, Ratio2>::type>
0043 Timeout(const Timeout<Ratio2> &other)
0044 : Base(other ? Base(Dur<Ratio>(*other)) : std::nullopt) {}
0045
0046 template <typename Rep2, typename Ratio2,
0047 typename = typename EnableIf<Rep2, Ratio2>::type>
0048 Timeout(const std::chrono::duration<Rep2, Ratio2> &other)
0049 : Base(Dur<Ratio>(other)) {}
0050 };
0051
0052 }
0053
0054 namespace llvm {
0055 template<typename Ratio>
0056 struct format_provider<lldb_private::Timeout<Ratio>, void> {
0057 static void format(const lldb_private::Timeout<Ratio> &timeout,
0058 raw_ostream &OS, StringRef Options) {
0059 typedef typename lldb_private::Timeout<Ratio>::value_type Dur;
0060
0061 if (!timeout)
0062 OS << "<infinite>";
0063 else
0064 format_provider<Dur>::format(*timeout, OS, Options);
0065 }
0066 };
0067 }
0068
0069 #endif