2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_SERVER_MEMORY_PROTECTOR_H_
18 #define incl_HPHP_SERVER_MEMORY_PROTECTOR_H_
20 #include <condition_variable>
24 #include <boost/container/flat_set.hpp>
26 #include "hphp/runtime/base/config.h"
27 #include "hphp/util/async-func.h"
28 #include "hphp/util/health-monitor-types.h"
32 // This class must be used as a singleton.
33 struct HostHealthMonitor
{
34 void subscribe(IHostHealthObserver
* observer
) {
35 assert(observer
!= nullptr);
36 std::lock_guard
<std::mutex
> g(m_lock
);
37 m_observers
.insert(observer
);
39 bool unsubscribe(IHostHealthObserver
* observer
) {
40 std::lock_guard
<std::mutex
> g(m_lock
);
41 return !!m_observers
.erase(observer
);
43 void addMetric(IHealthMonitorMetric
* metric
);
50 HealthLevel
evaluate();
51 void notifyObservers(HealthLevel newStatus
);
54 std::vector
<IHealthMonitorMetric
*> m_metrics
;
55 boost::container::flat_set
<IHostHealthObserver
*> m_observers
;
56 std::mutex m_lock
; // protects metrics/observers
57 HealthLevel m_status
{HealthLevel::Bold
};
58 std::mutex m_stopped_lock
;
59 std::condition_variable m_condition
;
61 std::unique_ptr
<AsyncFunc
<HostHealthMonitor
>> m_monitor_func
;