xrpld
Loading...
Searching...
No Matches
Job.cpp
1#include <xrpl/core/Job.h>
2
3#include <xrpl/beast/core/CurrentThreadName.h>
4#include <xrpl/core/LoadEvent.h>
5#include <xrpl/core/LoadMonitor.h>
6
7#include <cstdint>
8#include <functional>
9#include <memory>
10#include <string>
11
12namespace xrpl {
13
17
18Job::Job(JobType type, std::uint64_t index) : type_(type), jobIndex_(index)
19{
20}
21
23 JobType type,
24 std::string const& name,
25 std::uint64_t index,
26 LoadMonitor& lm,
27 std::function<void()> const& job)
28 : type_(type), jobIndex_(index), job_(job), name_(name), queueTime_(clock_type::now())
29{
31}
32
35{
36 return type_;
37}
38
39Job::clock_type::time_point const&
41{
42 return queueTime_;
43}
44
45void
47{
49 loadEvent_->start();
50 loadEvent_->setName(name_);
51
52 job_();
53
54 // Destroy the lambda, otherwise we won't include
55 // its duration in the time measurement
56 job_ = nullptr;
57}
58
59bool
60Job::operator>(Job const& j) const
61{
62 if (type_ < j.type_)
63 return true;
64
65 if (type_ > j.type_)
66 return false;
67
68 return jobIndex_ > j.jobIndex_;
69}
70
71bool
72Job::operator>=(Job const& j) const
73{
74 if (type_ < j.type_)
75 return true;
76
77 if (type_ > j.type_)
78 return false;
79
80 return jobIndex_ >= j.jobIndex_;
81}
82
83bool
84Job::operator<(Job const& j) const
85{
86 if (type_ < j.type_)
87 return false;
88
89 if (type_ > j.type_)
90 return true;
91
92 return jobIndex_ < j.jobIndex_;
93}
94
95bool
96Job::operator<=(Job const& j) const
97{
98 if (type_ < j.type_)
99 return false;
100
101 if (type_ > j.type_)
102 return true;
103
104 return jobIndex_ <= j.jobIndex_;
105}
106
107} // namespace xrpl
JobType getType() const
Definition Job.cpp:34
std::function< void()> job_
Definition Job.h:127
void doJob()
Definition Job.cpp:46
clock_type::time_point queueTime_
Definition Job.h:130
std::shared_ptr< LoadEvent > loadEvent_
Definition Job.h:128
bool operator>=(Job const &j) const
Definition Job.cpp:72
bool operator<(Job const &j) const
Definition Job.cpp:84
std::chrono::steady_clock clock_type
Definition Job.h:79
Job()
Default constructor.
Definition Job.cpp:14
clock_type::time_point const & queueTime() const
Returns the time when the job was queued.
Definition Job.cpp:40
std::string name_
Definition Job.h:129
bool operator<=(Job const &j) const
Definition Job.cpp:96
JobType type_
Definition Job.h:125
std::uint64_t jobIndex_
Definition Job.h:126
bool operator>(Job const &j) const
Definition Job.cpp:60
T make_shared(T... args)
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
JobType
Definition Job.h:16
@ JtInvalid
Definition Job.h:18
T ref(T... args)