Debian Codegraph @

src/proclist.h

raw symbols SCIP
1 #pragma once
2
3 #include <map>
4 #include <mutex>
5
6 #include "procinfo.h"
7
8 class ProcList
9 {
10 // TODO: use a set instead
11 // sorted by pid. The map has a nice property : it is sorted
12 // by pid so this helps a lot when looking for the parent node
13 // as ppid is nearly always < pid.
14 typedef std::map<pid_t, ProcInfo> List;
15 List data;
16 std::mutex data_lock;
17 public:
18 std::map<pid_t, unsigned long> cpu_times;
19 typedef List::iterator Iterator;
20 Iterator
21 begin ()
22 {
23 return std::begin (data);
24 }
25 Iterator
26 end ()
27 {
28 return std::end (data);
29 }
30 Iterator
31 erase (Iterator it)
32 {
33 std::lock_guard<std::mutex> lg (data_lock);
34
35 return data.erase (it);
36 }
37 ProcInfo*
38 add (pid_t pid)
39 {
40 return &data.try_emplace (pid, pid).first->second;
41 }
42 void
43 clear ()
44 {
45 return data.clear ();
46 }
47
48 ProcInfo * find (pid_t pid);
49 };