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