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#include <xrpl/beast/core/CurrentThreadName.h>
22
23namespace ripple {
24
25Job::Job() : mType(jtINVALID), mJobIndex(0)
26{
27}
28
29Job::Job(JobType type, std::uint64_t index) : mType(type), mJobIndex(index)
30{
31}
32
34 JobType type,
35 std::string const& name,
36 std::uint64_t index,
37 LoadMonitor& lm,
38 std::function<void()> const& job)
39 : mType(type)
40 , mJobIndex(index)
41 , mJob(job)
42 , mName(name)
43 , m_queue_time(clock_type::now())
44{
45 m_loadEvent = std::make_shared<LoadEvent>(std::ref(lm), name, false);
46}
47
50{
51 return mType;
52}
53
54Job::clock_type::time_point const&
56{
57 return m_queue_time;
58}
59
60void
62{
64 m_loadEvent->start();
65 m_loadEvent->setName(mName);
66
67 mJob();
68
69 // Destroy the lambda, otherwise we won't include
70 // its duration in the time measurement
71 mJob = nullptr;
72}
73
74bool
75Job::operator>(const Job& j) const
76{
77 if (mType < j.mType)
78 return true;
79
80 if (mType > j.mType)
81 return false;
82
83 return mJobIndex > j.mJobIndex;
84}
85
86bool
87Job::operator>=(const Job& j) const
88{
89 if (mType < j.mType)
90 return true;
91
92 if (mType > j.mType)
93 return false;
94
95 return mJobIndex >= j.mJobIndex;
96}
97
98bool
99Job::operator<(const Job& j) const
100{
101 if (mType < j.mType)
102 return false;
103
104 if (mType > j.mType)
105 return true;
106
107 return mJobIndex < j.mJobIndex;
108}
109
110bool
111Job::operator<=(const Job& j) const
112{
113 if (mType < j.mType)
114 return false;
115
116 if (mType > j.mType)
117 return true;
118
119 return mJobIndex <= j.mJobIndex;
120}
121
122} // namespace ripple
std::string mName
Definition: Job.h:147
bool operator>(const Job &j) const
Definition: Job.cpp:75
std::shared_ptr< LoadEvent > m_loadEvent
Definition: Job.h:146
std::function< void()> mJob
Definition: Job.h:145
bool operator<=(const Job &j) const
Definition: Job.cpp:111
Job()
Default constructor.
Definition: Job.cpp:25
std::uint64_t mJobIndex
Definition: Job.h:144
void doJob()
Definition: Job.cpp:61
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Definition: Job.cpp:55
clock_type::time_point m_queue_time
Definition: Job.h:148
bool operator<(const Job &j) const
Definition: Job.cpp:99
JobType mType
Definition: Job.h:143
bool operator>=(const Job &j) const
Definition: Job.cpp:87
JobType getType() const
Definition: Job.cpp:49
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:34
@ jtINVALID
Definition: Job.h:36
T ref(T... args)