1.1 --- a/libfsserver/lib/pipes/pipe_paging.cc Sun Jul 11 23:11:39 2021 +0200
1.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc Sun Jul 11 23:21:08 2021 +0200
1.3 @@ -19,7 +19,6 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <ipc/cap_alloc.h>
1.8 #include <mem/memory_preallocated.h>
1.9
1.10 #include "page_queue_partitioned.h"
1.11 @@ -30,7 +29,7 @@
1.12
1.13
1.14 PipePaging::PipePaging(Memory *memory, offset_t size)
1.15 -: _memory(NULL), _size(size)
1.16 +: NotificationSupport(2), _memory(NULL), _size(size)
1.17 {
1.18 /* Reserve space for two pipe regions. */
1.19
1.20 @@ -42,49 +41,20 @@
1.21
1.22 for (unsigned int i = 0; i < 2; i++)
1.23 _regions[i] = NULL;
1.24 -
1.25 - /* Initialise endpoints and flags for notifications. */
1.26 -
1.27 - for (unsigned int i = 0; i < 2; i++)
1.28 - {
1.29 - _flags[i] = 0;
1.30 - _deferred[i] = 0;
1.31 - }
1.32 }
1.33
1.34 -/* Subscribe to an endpoint's notifications using a notification endpoint. */
1.35 +/* Subscribe to an endpoint's notifications using a notifier object. */
1.36
1.37 void PipePaging::subscribe(bool writing, l4_cap_idx_t notifier, notify_flags_t flags)
1.38 {
1.39 - int i = writing ? 1 : 0;
1.40 -
1.41 - _notifiers[i].insert(notifier);
1.42 - _flags[i] = flags;
1.43 -
1.44 - /* Send deferred conditions on behalf of the other endpoint held before
1.45 - subscription occurred. */
1.46 -
1.47 - if (_deferred[i])
1.48 - {
1.49 - notify(!writing, _deferred[i]);
1.50 - _deferred[i] = 0;
1.51 - }
1.52 + NotificationSupport::subscribe(writing ? 1 : 0, notifier, flags);
1.53 }
1.54
1.55 /* Unsubscribe from an endpoint's notifications. */
1.56
1.57 void PipePaging::unsubscribe(bool writing, l4_cap_idx_t notifier)
1.58 {
1.59 - int i = writing ? 1 : 0;
1.60 - std::set<l4_cap_idx_t>::iterator it = _notifiers[i].find(notifier);
1.61 -
1.62 - if (it != _notifiers[i].end())
1.63 - {
1.64 - _notifiers[i].erase(it);
1.65 - _flags[i] = 0;
1.66 - _deferred[i] = 0;
1.67 - ipc_cap_free_um(notifier);
1.68 - }
1.69 + NotificationSupport::unsubscribe(writing ? 1 : 0, notifier);
1.70 }
1.71
1.72 /* Notify the other endpoint. */
1.73 @@ -93,27 +63,7 @@
1.74 {
1.75 /* Let the writer notify the reader, and the other way round. */
1.76
1.77 - int i = writing ? 0 : 1;
1.78 -
1.79 - /* Notify the other endpoint or hold any notification for potential future
1.80 - subscription. */
1.81 -
1.82 - if (!_notifiers[i].empty())
1.83 - {
1.84 - if (flags & _flags[i])
1.85 - {
1.86 - std::set<l4_cap_idx_t>::iterator it;
1.87 -
1.88 - for (it = _notifiers[i].begin(); it != _notifiers[i].end(); it++)
1.89 - {
1.90 - client_Notifier notifier(*it);
1.91 -
1.92 - notifier.notify(flags & _flags[i]);
1.93 - }
1.94 - }
1.95 - }
1.96 - else
1.97 - _deferred[i] = flags;
1.98 + NotificationSupport::notify(writing ? 0 : 1, flags);
1.99 }
1.100
1.101 /* Return whether one or more endpoints have detached. */
1.102 @@ -156,15 +106,7 @@
1.103
1.104 /* Release notifiers. */
1.105
1.106 - for (unsigned int i = 0; i < 2; i++)
1.107 - {
1.108 - std::set<l4_cap_idx_t>::iterator it;
1.109 -
1.110 - for (it = _notifiers[i].begin(); it != _notifiers[i].end(); it++)
1.111 - ipc_cap_free_um(*it);
1.112 -
1.113 - _notifiers[i].clear();
1.114 - }
1.115 + release_notifiers();
1.116
1.117 /* Delete the page collection and related objects. */
1.118