# HG changeset patch # User Paul Boddie # Date 1677446371 -3600 # Node ID d9de8ecdaf6038c8d2d6a31d021a520ac588e143 # Parent 4f4174ed0b1f99a81e6a0367e7426626e2a46431 Changed the unsubscribe operation in the notification interface to involve an explicit notifier, thus relieving the external pager from having to retain a single notifier when many notifiers could potentially be used. For file and pipe pagers, the use of a single notifier per pager is preserved but managed slightly differently. diff -r 4f4174ed0b1f -r d9de8ecdaf60 libexec/include/exec/external_pager.h --- a/libexec/include/exec/external_pager.h Sun Feb 26 18:43:52 2023 +0100 +++ b/libexec/include/exec/external_pager.h Sun Feb 26 22:19:31 2023 +0100 @@ -34,9 +34,6 @@ class ExternalPager : public ExecPager, public ParentPagerObject, public NotificationSupport { -protected: - l4_cap_idx_t _notifier; - public: explicit ExternalPager(address_t start = 0, address_t end = 0); @@ -61,7 +58,7 @@ virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); - virtual long unsubscribe(); + virtual long unsubscribe(l4_cap_idx_t notifier); }; /* vim: tabstop=2 expandtab shiftwidth=2 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libexec/lib/src/external_pager.cc Sun Feb 26 22:19:31 2023 +0100 @@ -172,16 +172,14 @@ long ExternalPager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags) { - _notifier = notifier; return NotificationSupport::subscribe(notifier, flags); } /* Unsubscribe from notifications. */ -long ExternalPager::unsubscribe() +long ExternalPager::unsubscribe(l4_cap_idx_t notifier) { - NotificationSupport::unsubscribe(_notifier); - return L4_EOK; + return NotificationSupport::unsubscribe(notifier); } /* vim: tabstop=2 expandtab shiftwidth=2 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsclient/lib/src/notifier.cc --- a/libfsclient/lib/src/notifier.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsclient/lib/src/notifier.cc Sun Feb 26 22:19:31 2023 +0100 @@ -216,7 +216,7 @@ client_Notification notify(object->base->ref); - notify.unsubscribe(); + notify.unsubscribe(endpoint); return remove_endpoint(object, endpoint); } diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/include/fsserver/directory_resource.h --- a/libfsserver/include/fsserver/directory_resource.h Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/include/fsserver/directory_resource.h Sun Feb 26 22:19:31 2023 +0100 @@ -63,7 +63,7 @@ virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); - virtual long unsubscribe(); + virtual long unsubscribe(l4_cap_idx_t notifier); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/include/fsserver/file_pager.h --- a/libfsserver/include/fsserver/file_pager.h Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/include/fsserver/file_pager.h Sun Feb 26 22:19:31 2023 +0100 @@ -83,7 +83,7 @@ virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); - virtual long unsubscribe(); + virtual long unsubscribe(l4_cap_idx_t notifier); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/include/fsserver/notification.h --- a/libfsserver/include/fsserver/notification.h Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/include/fsserver/notification.h Sun Feb 26 22:19:31 2023 +0100 @@ -121,7 +121,7 @@ virtual long subscribe(unsigned int endpoint, l4_cap_idx_t notifier, notify_flags_t flags); - virtual void unsubscribe(l4_cap_idx_t notifier); + virtual long unsubscribe(l4_cap_idx_t notifier); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/include/fsserver/pipe_pager.h --- a/libfsserver/include/fsserver/pipe_pager.h Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/include/fsserver/pipe_pager.h Sun Feb 26 22:19:31 2023 +0100 @@ -77,7 +77,7 @@ virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); - virtual long unsubscribe(); + virtual long unsubscribe(l4_cap_idx_t notifier); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/lib/directories/directory_resource.cc --- a/libfsserver/lib/directories/directory_resource.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/lib/directories/directory_resource.cc Sun Feb 26 22:19:31 2023 +0100 @@ -131,10 +131,9 @@ /* Unsubscribe from notifications. */ -long DirectoryResource::unsubscribe() +long DirectoryResource::unsubscribe(l4_cap_idx_t notifier) { - _provider->unsubscribe(_notifier); - return L4_EOK; + return _provider->unsubscribe(notifier); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/lib/files/file_pager.cc --- a/libfsserver/lib/files/file_pager.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/lib/files/file_pager.cc Sun Feb 26 22:19:31 2023 +0100 @@ -53,7 +53,7 @@ /* Notify other users of the file and unsubscribe. */ _provider->notify_others(_notifier, NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL); - unsubscribe(); + unsubscribe(_notifier); /* Detach the pager, potentially removing the file provider. */ @@ -146,24 +146,27 @@ -/* Subscribe to notifications. */ +/* Subscribe to notifications. + Readers can subscribe to new data (flush) and file closed events. + Writers can subscribe to file closed events. */ long FilePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags) { - /* Readers can subscribe to new data (flush) and file closed events. - Writers can subscribe to file closed events. */ + /* A single notifier is recorded so that it may be unsubscribed when the + file is closed. */ + + if ((notifier != _notifier) && l4_is_valid_cap(_notifier)) + unsubscribe(_notifier); _notifier = notifier; - return _provider->subscribe(notifier, flags); } /* Unsubscribe from notifications. */ -long FilePager::unsubscribe() +long FilePager::unsubscribe(l4_cap_idx_t notifier) { - _provider->unsubscribe(_notifier); - return L4_EOK; + return _provider->unsubscribe(notifier); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/lib/generic/notification.cc --- a/libfsserver/lib/generic/notification.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/lib/generic/notification.cc Sun Feb 26 22:19:31 2023 +0100 @@ -103,11 +103,12 @@ /* Unsubscribe from an endpoint's notifications. */ -void NotificationSupport::unsubscribe(l4_cap_idx_t notifier) +long NotificationSupport::unsubscribe(l4_cap_idx_t notifier) { std::lock_guard guard(_lock); _unsubscribe(notifier); + return L4_EOK; } /* Common subscription functionality. */ diff -r 4f4174ed0b1f -r d9de8ecdaf60 libfsserver/lib/pipes/pipe_pager.cc --- a/libfsserver/lib/pipes/pipe_pager.cc Sun Feb 26 18:43:52 2023 +0100 +++ b/libfsserver/lib/pipes/pipe_pager.cc Sun Feb 26 22:19:31 2023 +0100 @@ -64,7 +64,7 @@ _paging->notify_others(_writing ? PipePaging::WRITER : PipePaging::READER, NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL); - unsubscribe(); + unsubscribe(_notifier); /* Deallocate the paging coordinator if no other endpoints are active. */ @@ -178,12 +178,17 @@ -/* Subscribe to notifications. */ +/* Subscribe to notifications. + Readers can subscribe to new data (at end), and pipe closed events. + Writers can subscribe to new space and pipe closed events. */ long PipePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags) { - /* Readers can subscribe to new data (at end), and pipe closed events. - Writers can subscribe to new space and pipe closed events. */ + /* A single notifier is recorded so that it may be unsubscribed when the + file is closed. */ + + if ((notifier != _notifier) && l4_is_valid_cap(_notifier)) + unsubscribe(_notifier); _notifier = notifier; @@ -193,10 +198,9 @@ /* Unsubscribe from notifications. */ -long PipePager::unsubscribe() +long PipePager::unsubscribe(l4_cap_idx_t notifier) { - _paging->unsubscribe(_notifier); - return L4_EOK; + return _paging->unsubscribe(notifier); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 4f4174ed0b1f -r d9de8ecdaf60 libsystypes/idl/notification.idl --- a/libsystypes/idl/notification.idl Sun Feb 26 18:43:52 2023 +0100 +++ b/libsystypes/idl/notification.idl Sun Feb 26 22:19:31 2023 +0100 @@ -9,5 +9,5 @@ /* Unsubscribe from events. */ - [opcode(24)] void unsubscribe(); + [opcode(24)] void unsubscribe(in cap notifier); };