rippled
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/Stoppable.h>
24 #include <ripple/core/impl/Workers.h>
25 
26 #include <functional>
27 #include <queue>
28 
29 namespace ripple {
30 namespace NodeStore {
31 
32 class TaskQueue : public Stoppable, private Workers::Callback
33 {
34 public:
35  explicit TaskQueue(Stoppable& parent);
36 
37  void
38  onStop() override;
39 
44  void
45  addTask(std::function<void()> task);
46 
47 private:
51 
52  void
53  processTask(int instance) override;
54 };
55 
56 } // namespace NodeStore
57 } // namespace ripple
58 
59 #endif
functional
ripple::NodeStore::TaskQueue::workers_
Workers workers_
Definition: TaskQueue.h:49
ripple::NodeStore::TaskQueue::processTask
void processTask(int instance) override
Perform a task.
Definition: TaskQueue.cpp:50
std::function
ripple::NodeStore::TaskQueue::tasks_
std::queue< std::function< void()> > tasks_
Definition: TaskQueue.h:50
queue
ripple::Workers::Callback
Called to perform tasks as needed.
Definition: Workers.h:43
ripple::NodeStore::TaskQueue
Definition: TaskQueue.h:32
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::NodeStore::TaskQueue::addTask
void addTask(std::function< void()> task)
Adds a task to the queue.
Definition: TaskQueue.cpp:41
ripple::Workers
A group of threads that process tasks.
Definition: Workers.h:39
ripple::NodeStore::TaskQueue::TaskQueue
TaskQueue(Stoppable &parent)
Definition: TaskQueue.cpp:27
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::TaskQueue::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: TaskQueue.cpp:34
std::mutex
STL class.
ripple::NodeStore::TaskQueue::mutex_
std::mutex mutex_
Definition: TaskQueue.h:48