rippled
ripple
nodestore
impl
TaskQueue.h
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012, 2019 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
#ifndef RIPPLE_NODESTORE_TASKQUEUE_H_INCLUDED
21
#define RIPPLE_NODESTORE_TASKQUEUE_H_INCLUDED
22
23
#include <ripple/core/impl/Workers.h>
24
25
#include <
functional
>
26
#include <
queue
>
27
28
namespace
ripple
{
29
namespace
NodeStore {
30
31
class
TaskQueue
:
private
Workers::Callback
32
{
33
public
:
34
TaskQueue
();
35
36
void
37
stop
();
38
43
void
44
addTask
(
std::function
<
void
()> task);
45
48
[[nodiscard]]
size_t
49
size
()
const
;
50
51
private
:
52
mutable
std::mutex
mutex_
;
53
Workers
workers_
;
54
std::queue
<
std::function
<void()>>
tasks_
;
55
std::uint64_t
processing_
{0};
56
57
void
58
processTask
(
int
instance)
override
;
59
};
60
61
}
// namespace NodeStore
62
}
// namespace ripple
63
64
#endif
functional
ripple::NodeStore::TaskQueue::size
size_t size() const
Return the queue size.
Definition:
TaskQueue.cpp:48
ripple::NodeStore::TaskQueue::workers_
Workers workers_
Definition:
TaskQueue.h:53
ripple::NodeStore::TaskQueue::processTask
void processTask(int instance) override
Perform a task.
Definition:
TaskQueue.cpp:55
ripple::NodeStore::TaskQueue::TaskQueue
TaskQueue()
Definition:
TaskQueue.cpp:27
std::function
ripple::NodeStore::TaskQueue::tasks_
std::queue< std::function< void()> > tasks_
Definition:
TaskQueue.h:54
queue
ripple::Workers::Callback
Called to perform tasks as needed.
Definition:
Workers.h:83
ripple::NodeStore::TaskQueue
Definition:
TaskQueue.h:31
ripple::NodeStore::TaskQueue::addTask
void addTask(std::function< void()> task)
Adds a task to the queue.
Definition:
TaskQueue.cpp:38
ripple::NodeStore::TaskQueue::stop
void stop()
Definition:
TaskQueue.cpp:32
std::uint64_t
ripple::Workers
Workers is effectively a thread pool.
Definition:
Workers.h:79
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
std::mutex
STL class.
ripple::NodeStore::TaskQueue::mutex_
std::mutex mutex_
Definition:
TaskQueue.h:52
ripple::NodeStore::TaskQueue::processing_
std::uint64_t processing_
Definition:
TaskQueue.h:55
Generated by
1.8.17