rippled
LoadManager.h
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 #ifndef RIPPLE_APP_MAIN_LOADMANAGER_H_INCLUDED
21 #define RIPPLE_APP_MAIN_LOADMANAGER_H_INCLUDED
22 
23 #include <ripple/beast/utility/Journal.h>
24 #include <atomic>
25 #include <condition_variable>
26 #include <memory>
27 #include <mutex>
28 #include <thread>
29 
30 namespace ripple {
31 
32 class Application;
33 
46 {
47  LoadManager(Application& app, beast::Journal journal);
48 
49 public:
50  LoadManager() = delete;
51  LoadManager(LoadManager const&) = delete;
53  operator=(LoadManager const&) = delete;
54 
59  ~LoadManager();
60 
69  // VFALCO NOTE it seems that the deadlock detector has an "armed" state
70  // to prevent it from going off during program startup if
71  // there's a lengthy initialization operation taking place?
72  //
73  void
75 
81  void
83 
84  //--------------------------------------------------------------------------
85 
86  void
87  start();
88 
89  void
90  stop();
91 
92 private:
93  void
94  run();
95 
96 private:
99 
101  std::mutex mutex_; // Guards deadLock_, armed_, cv_
103  bool stop_ = false;
104 
105  std::chrono::steady_clock::time_point
106  deadLock_; // Detect server deadlocks.
107  bool armed_;
108 
111 };
112 
115 
116 } // namespace ripple
117 
118 #endif
ripple::Application
Definition: Application.h:115
ripple::LoadManager::activateDeadlockDetector
void activateDeadlockDetector()
Turn on deadlock detection.
Definition: LoadManager.cpp:55
ripple::LoadManager
Manages load sources.
Definition: LoadManager.h:45
ripple::LoadManager::start
void start()
Definition: LoadManager.cpp:73
ripple::make_LoadManager
std::unique_ptr< LoadManager > make_LoadManager(Application &app, beast::Journal journal)
Definition: LoadManager.cpp:197
ripple::LoadManager::journal_
const beast::Journal journal_
Definition: LoadManager.h:98
ripple::LoadManager::app_
Application & app_
Definition: LoadManager.h:97
thread
ripple::LoadManager::mutex_
std::mutex mutex_
Definition: LoadManager.h:101
ripple::LoadManager::stop
void stop()
Definition: LoadManager.cpp:82
ripple::LoadManager::~LoadManager
~LoadManager()
Destroy the manager.
Definition: LoadManager.cpp:38
ripple::LoadManager::thread_
std::thread thread_
Definition: LoadManager.h:100
ripple::LoadManager::cv_
std::condition_variable cv_
Definition: LoadManager.h:102
ripple::LoadManager::armed_
bool armed_
Definition: LoadManager.h:107
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::LoadManager::make_LoadManager
friend std::unique_ptr< LoadManager > make_LoadManager(Application &app, beast::Journal journal)
Definition: LoadManager.cpp:197
atomic
memory
ripple::LoadManager::operator=
LoadManager & operator=(LoadManager const &)=delete
ripple::LoadManager::resetDeadlockDetector
void resetDeadlockDetector()
Reset the deadlock detection timer.
Definition: LoadManager.cpp:63
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
condition_variable
ripple::LoadManager::LoadManager
LoadManager()=delete
ripple::LoadManager::run
void run()
Definition: LoadManager.cpp:100
mutex
ripple::LoadManager::stop_
bool stop_
Definition: LoadManager.h:103
std::unique_ptr
STL class.
ripple::LoadManager::deadLock_
std::chrono::steady_clock::time_point deadLock_
Definition: LoadManager.h:106