1.1 --- a/libfsserver/lib/files/file_paging.cc Sat Sep 04 23:23:32 2021 +0200
1.2 +++ b/libfsserver/lib/files/file_paging.cc Wed Sep 08 01:18:00 2021 +0200
1.3 @@ -27,7 +27,7 @@
1.4
1.5
1.6 FilePaging::FilePaging(Pages *pages)
1.7 -: NotificationSupport(), _pages(pages)
1.8 +: _pages(pages)
1.9 {
1.10 }
1.11
1.12 @@ -49,6 +49,14 @@
1.13 return mapper;
1.14 }
1.15
1.16 +/* Remove a notification manager for the given 'fileid'. */
1.17 +
1.18 +void FilePaging::remove(fileid_t fileid, FileNotification *notifier)
1.19 +{
1.20 + _notifiers.erase(fileid);
1.21 + delete notifier;
1.22 +}
1.23 +
1.24 /* Remove a page mapper and its resources for the given 'fileid'. */
1.25
1.26 void FilePaging::remove(fileid_t fileid, PageMapper *mapper)
1.27 @@ -58,14 +66,17 @@
1.28 delete mapper;
1.29 }
1.30
1.31 -/* Register a page 'mapper' for the given 'fileid'. */
1.32 +/* Register a page 'mapper' and a notification manager for the given 'fileid'. */
1.33
1.34 void FilePaging::set(fileid_t fileid, PageMapper *mapper)
1.35 {
1.36 FileMapping::iterator entry = _mappers.find(fileid);
1.37
1.38 - if (entry == _mappers.end())
1.39 - _mappers[fileid] = mapper;
1.40 + if (entry != _mappers.end())
1.41 + return;
1.42 +
1.43 + _mappers[fileid] = mapper;
1.44 + _notifiers[fileid] = new FileNotification;
1.45 }
1.46
1.47
1.48 @@ -106,6 +117,18 @@
1.49 return L4_EOK;
1.50 }
1.51
1.52 +/* Obtain a file-specific notification manager. */
1.53 +
1.54 +FileNotification *FilePaging::get_notifier(fileid_t file)
1.55 +{
1.56 + FileNotifiers::iterator entry = _notifiers.find(file);
1.57 +
1.58 + if (entry != _notifiers.end())
1.59 + return _notifiers[file];
1.60 + else
1.61 + return NULL;
1.62 +}
1.63 +
1.64
1.65
1.66 /* Return a pager initialised with a page mapper. */
1.67 @@ -138,6 +161,20 @@
1.68
1.69 if (!mapper->detach())
1.70 remove(fileid, mapper);
1.71 +
1.72 + FileNotification *notifier = get_notifier(fileid);
1.73 +
1.74 + if ((notifier != NULL) && (!notifier->detach()))
1.75 + remove(fileid, notifier);
1.76 +}
1.77 +
1.78 +/* Obtain a file-specific notification manager. */
1.79 +
1.80 +FileNotification *FilePaging::notifier(fileid_t file)
1.81 +{
1.82 + std::lock_guard<std::mutex> guard(_lock);
1.83 +
1.84 + return get_notifier(file);
1.85 }
1.86
1.87 // vim: tabstop=4 expandtab shiftwidth=4