-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_context.cpp
67 lines (58 loc) · 1.76 KB
/
io_context.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "io_context.h"
#include "server_nodemonitor.h"
#include "server_vfs.h"
#include "system.h"
IoContext::IoContext(const IoContext& other)
{
_maxMonitors = other._maxMonitors;
// Monitors are not copied.
}
IoContext::~IoContext()
{
auto& vfsService = System::GetInstance().GetVfsService();
auto lock = vfsService.Lock();
for (auto& listener : _monitors)
{
if (listener && listener->monitor
&& listener->monitor->node != (haiku_ino_t)-1)
{
vfsService.RemoveMonitor(listener->monitor->device, listener->monitor->node);
}
}
}
IoContext& IoContext::operator=(const IoContext& other)
{
if (this == &other)
return *this;
_maxMonitors = other._maxMonitors;
return *this;
}
unsigned int IoContext::NumMonitors() const
{
return _monitors.size();
}
size_t IoContext::AddMonitor(const std::shared_ptr<monitor_listener>& listener)
{
_monitors.push_back(listener);
listener->context_link = --_monitors.end();
if (listener && listener->monitor
&& listener->monitor->node != (haiku_ino_t)-1)
{
auto& vfsService = System::GetInstance().GetVfsService();
auto lock = vfsService.Lock();
vfsService.AddMonitor(listener->monitor->device, listener->monitor->node);
}
return _monitors.size();
}
size_t IoContext::RemoveMonitor(const std::shared_ptr<monitor_listener>& listener)
{
_monitors.erase(listener->context_link);
if (listener && listener->monitor
&& listener->monitor->node != (haiku_ino_t)-1)
{
auto& vfsService = System::GetInstance().GetVfsService();
auto lock = vfsService.Lock();
vfsService.RemoveMonitor(listener->monitor->device, listener->monitor->node);
}
return _monitors.size();
}