rippled
Loading...
Searching...
No Matches
Job.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/core/Job.h>
21
22#include <xrpl/beast/core/CurrentThreadName.h>
23
24namespace ripple {
25
26Job::Job() : mType(jtINVALID), mJobIndex(0)
27{
28}
29
30Job::Job(JobType type, std::uint64_t index) : mType(type), mJobIndex(index)
31{
32}
33
35 JobType type,
36 std::string const& name,
37 std::uint64_t index,
38 LoadMonitor& lm,
39 std::function<void()> const& job)
40 : mType(type)
41 , mJobIndex(index)
42 , mJob(job)
43 , mName(name)
44 , m_queue_time(clock_type::now())
45{
46 m_loadEvent = std::make_shared<LoadEvent>(std::ref(lm), name, false);
47}
48
51{
52 return mType;
53}
54
55Job::clock_type::time_point const&
57{
58 return m_queue_time;
59}
60
61void
63{
65 m_loadEvent->start();
66 m_loadEvent->setName(mName);
67
68 mJob();
69
70 // Destroy the lambda, otherwise we won't include
71 // its duration in the time measurement
72 mJob = nullptr;
73}
74
75bool
76Job::operator>(Job const& j) const
77{
78 if (mType < j.mType)
79 return true;
80
81 if (mType > j.mType)
82 return false;
83
84 return mJobIndex > j.mJobIndex;
85}
86
87bool
88Job::operator>=(Job const& j) const
89{
90 if (mType < j.mType)
91 return true;
92
93 if (mType > j.mType)
94 return false;
95
96 return mJobIndex >= j.mJobIndex;
97}
98
99bool
100Job::operator<(Job const& j) const
101{
102 if (mType < j.mType)
103 return false;
104
105 if (mType > j.mType)
106 return true;
107
108 return mJobIndex < j.mJobIndex;
109}
110
111bool
112Job::operator<=(Job const& j) const
113{
114 if (mType < j.mType)
115 return false;
116
117 if (mType > j.mType)
118 return true;
119
120 return mJobIndex <= j.mJobIndex;
121}
122
123} // namespace ripple
std::string mName
Definition: Job.h:148
std::shared_ptr< LoadEvent > m_loadEvent
Definition: Job.h:147
std::function< void()> mJob
Definition: Job.h:146
bool operator>=(Job const &j) const
Definition: Job.cpp:88
bool operator>(Job const &j) const
Definition: Job.cpp:76
bool operator<=(Job const &j) const
Definition: Job.cpp:112
Job()
Default constructor.
Definition: Job.cpp:26
std::uint64_t mJobIndex
Definition: Job.h:145
void doJob()
Definition: Job.cpp:62
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Definition: Job.cpp:56
bool operator<(Job const &j) const
Definition: Job.cpp:100
clock_type::time_point m_queue_time
Definition: Job.h:149
JobType mType
Definition: Job.h:144
JobType getType() const
Definition: Job.cpp:50
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:26
JobType
Definition: Job.h:35
@ jtINVALID
Definition: Job.h:37
T ref(T... args)