Commit f8761542 authored by Ben's avatar Ben

After 35d69c72, std::map<pid_t, ProcInfo> requires ProcInfo to be

CopyConstructible for older compiler like gcc 5.4.
Make it a std::map<pid_t, std::shared_ptr<ProcInfo>> and implement a
wrapper to minimize code change.

https://bugzilla.gnome.org/show_bug.cgi?id=783993
parent 90f0100c
......@@ -152,19 +152,33 @@ class ProcList {
// sorted by pid. The map has a nice property : it is sorted
// by pid so this helps a lot when looking for the parent node
// as ppid is nearly always < pid.
typedef std::map<pid_t, ProcInfo> List;
typedef std::map<pid_t, std::shared_ptr<ProcInfo>> List;
List data;
std::mutex data_lock;
public:
std::map<pid_t, unsigned long> cpu_times;
typedef List::iterator Iterator;
struct Iterator
{
typedef List::iterator It;
typedef std::pair<pid_t, ProcInfo&> value_type;
It it;
std::shared_ptr<value_type> value;
Iterator(const It& it) : it(it) {}
bool operator!=(const Iterator& other) const { return it != other.it; }
Iterator& operator++() { ++it; return *this; }
value_type* operator->() { value = std::make_shared<value_type>(it->first, *it->second); return value.get(); }
value_type& operator*() { value = std::make_shared<value_type>(it->first, *it->second); return *value.get(); }
};
Iterator begin() { return std::begin(data); }
Iterator end() { return std::end(data); }
Iterator erase(Iterator it) {
std::lock_guard<std::mutex> lg(data_lock);
return data.erase(it);
return data.erase(it.it);
}
ProcInfo* add(pid_t pid) { return &data.emplace(pid, pid).first->second; }
ProcInfo* add(pid_t pid) { return data.emplace(pid, std::make_shared<ProcInfo>(pid)).first->second.get(); }
void clear() { return data.clear(); }
ProcInfo* find(pid_t pid);
......
......@@ -66,7 +66,7 @@
ProcInfo* ProcList::find(pid_t pid)
{
auto it = data.find(pid);
return (it == data.end() ? nullptr : &it->second);
return (it == data.end() ? nullptr : it->second.get());
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment