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