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/impl/Workers.h>
24 #include <ripple/core/Stoppable.h>
25 
26 #include <functional>
27 #include <queue>
28 
29 namespace ripple {
30 namespace NodeStore {
31 
32 class TaskQueue
33  : public Stoppable
34  , private Workers::Callback
35 {
36 public:
37  explicit
38  TaskQueue(Stoppable& parent);
39 
40  void
41  onStop() override;
42 
47  void
48  addTask(std::function<void()> task);
49 
50 private:
54 
55  void
56  processTask(int instance) override;
57 };
58 
59 } // NodeStore
60 } // ripple
61 
62 #endif
functional
ripple::NodeStore::TaskQueue::workers_
Workers workers_
Definition: TaskQueue.h:52
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:53
queue
ripple::Workers::Callback
Called to perform tasks as needed.
Definition: Workers.h:44
ripple::NodeStore::TaskQueue
Definition: TaskQueue.h:32
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
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:40
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:51