xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
core
detail
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
12
namespace
xrpl
{
13
14
Job::Job
() :
type_
(
JtInvalid
),
jobIndex_
(0)
15
{
16
}
17
18
Job::Job
(
JobType
type,
std::uint64_t
index) :
type_
(type),
jobIndex_
(index)
19
{
20
}
21
22
Job::Job
(
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_
(
ClockType
::now())
29
{
30
loadEvent_
=
std::make_shared<LoadEvent>
(
std::ref
(lm), name,
false
);
31
}
32
33
JobType
34
Job::getType
()
const
35
{
36
return
type_
;
37
}
38
39
Job::ClockType::time_point
const
&
40
Job::queueTime
()
const
41
{
42
return
queueTime_
;
43
}
44
45
void
46
Job::doJob
()
47
{
48
beast::setCurrentThreadName
(
"j:"
+
name_
);
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
59
bool
60
Job::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
71
bool
72
Job::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
83
bool
84
Job::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
95
bool
96
Job::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
std::string
xrpl::Job::getType
JobType getType() const
Definition
Job.cpp:34
xrpl::Job::job_
std::function< void()> job_
Definition
Job.h:135
xrpl::Job::ClockType
std::chrono::steady_clock ClockType
Definition
Job.h:84
xrpl::Job::doJob
void doJob()
Definition
Job.cpp:46
xrpl::Job::loadEvent_
std::shared_ptr< LoadEvent > loadEvent_
Definition
Job.h:136
xrpl::Job::operator>=
bool operator>=(Job const &j) const
Definition
Job.cpp:72
xrpl::Job::queueTime
ClockType::time_point const & queueTime() const
Returns the time when the job was queued.
Definition
Job.cpp:40
xrpl::Job::operator<
bool operator<(Job const &j) const
Definition
Job.cpp:84
xrpl::Job::Job
Job()
Default constructor.
Definition
Job.cpp:14
xrpl::Job::name_
std::string name_
Definition
Job.h:137
xrpl::Job::operator<=
bool operator<=(Job const &j) const
Definition
Job.cpp:96
xrpl::Job::type_
JobType type_
Definition
Job.h:133
xrpl::Job::queueTime_
ClockType::time_point queueTime_
Definition
Job.h:138
xrpl::Job::jobIndex_
std::uint64_t jobIndex_
Definition
Job.h:134
xrpl::Job::operator>
bool operator>(Job const &j) const
Definition
Job.cpp:60
xrpl::LoadMonitor
Definition
LoadMonitor.h:19
cstdint
std::function
functional
std::uint64_t
std::make_shared
T make_shared(T... args)
memory
beast::setCurrentThreadName
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
Definition
CurrentThreadName.cpp:115
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::JobType
JobType
Definition
Job.h:21
xrpl::JtInvalid
@ JtInvalid
Definition
Job.h:23
std::ref
T ref(T... args)
string
Generated by
1.17.0