rippled
Loading...
Searching...
No Matches
Job.cpp
1#include <xrpld/core/Job.h>
2
3#include <xrpl/beast/core/CurrentThreadName.h>
4
5namespace ripple {
6
7Job::Job() : mType(jtINVALID), mJobIndex(0)
8{
9}
10
11Job::Job(JobType type, std::uint64_t index) : mType(type), mJobIndex(index)
12{
13}
14
16 JobType type,
17 std::string const& name,
18 std::uint64_t index,
19 LoadMonitor& lm,
20 std::function<void()> const& job)
21 : mType(type)
22 , mJobIndex(index)
23 , mJob(job)
24 , mName(name)
25 , m_queue_time(clock_type::now())
26{
28}
29
32{
33 return mType;
34}
35
36Job::clock_type::time_point const&
38{
39 return m_queue_time;
40}
41
42void
44{
46 m_loadEvent->start();
47 m_loadEvent->setName(mName);
48
49 mJob();
50
51 // Destroy the lambda, otherwise we won't include
52 // its duration in the time measurement
53 mJob = nullptr;
54}
55
56bool
57Job::operator>(Job const& j) const
58{
59 if (mType < j.mType)
60 return true;
61
62 if (mType > j.mType)
63 return false;
64
65 return mJobIndex > j.mJobIndex;
66}
67
68bool
69Job::operator>=(Job const& j) const
70{
71 if (mType < j.mType)
72 return true;
73
74 if (mType > j.mType)
75 return false;
76
77 return mJobIndex >= j.mJobIndex;
78}
79
80bool
81Job::operator<(Job const& j) const
82{
83 if (mType < j.mType)
84 return false;
85
86 if (mType > j.mType)
87 return true;
88
89 return mJobIndex < j.mJobIndex;
90}
91
92bool
93Job::operator<=(Job const& j) const
94{
95 if (mType < j.mType)
96 return false;
97
98 if (mType > j.mType)
99 return true;
100
101 return mJobIndex <= j.mJobIndex;
102}
103
104} // namespace ripple
std::string mName
Definition Job.h:129
std::shared_ptr< LoadEvent > m_loadEvent
Definition Job.h:128
std::function< void()> mJob
Definition Job.h:127
bool operator>=(Job const &j) const
Definition Job.cpp:69
bool operator>(Job const &j) const
Definition Job.cpp:57
bool operator<=(Job const &j) const
Definition Job.cpp:93
Job()
Default constructor.
Definition Job.cpp:7
std::uint64_t mJobIndex
Definition Job.h:126
void doJob()
Definition Job.cpp:43
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Definition Job.cpp:37
bool operator<(Job const &j) const
Definition Job.cpp:81
clock_type::time_point m_queue_time
Definition Job.h:130
JobType mType
Definition Job.h:125
JobType getType() const
Definition Job.cpp:31
T is_same_v
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:6
JobType
Definition Job.h:16
@ jtINVALID
Definition Job.h:18
T ref(T... args)