-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_list.h
48 lines (41 loc) · 1.15 KB
/
report_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <atomic>
#include <map>
#include <queue>
#include <mutex>
#include "reports.h"
#include "pinba.pb-c.h"
#include "report_producer.h"
class ReportList {
std::map<std::string, Report *> reports;
public:
unsigned req_count;
unsigned version;
ReportList() : req_count(0) {};
virtual int add_report(Report *report, std::string report_type);
virtual void del_report(std::string report_type);
virtual void merge_reports(ReportList *main_reports);
virtual Report *get_report(std::string report_type);
int add_request_to_reports(Pinba__Request *request);
int del_request_from_reports(Pinba__Request *request);
};
class SharedReportList : public ReportList {
std::mutex lock;
public:
SharedReportList() : ReportList() {};
virtual int add_report(Report *report, std::string type) {
std::lock_guard<std::mutex> lck(lock);
return ReportList::add_report(report, type);
};
virtual void del_report(std::string type) {
std::lock_guard<std::mutex> lck(lock);
ReportList::del_report(type);
}
virtual Report *get_report(std::string type) {
lock.lock();
return ReportList::get_report(type);
}
void return_report() {
lock.unlock();
}
};