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