1.1 --- a/libfsclient/lib/src/file.cc Fri Jul 02 23:53:13 2021 +0200
1.2 +++ b/libfsclient/lib/src/file.cc Tue Jul 06 00:45:25 2021 +0200
1.3 @@ -21,19 +21,12 @@
1.4
1.5 #include <ipc/cap_alloc.h>
1.6 #include <ipc/mem_ipc.h>
1.7 -#include <ipc/irq.h>
1.8 -
1.9 -#include <l4/sys/irq.h>
1.10 -
1.11 -#include <pthread.h>
1.12 -#include <pthread-l4.h>
1.13
1.14 #include <string.h>
1.15
1.16 #include "dataspace_client.h"
1.17 #include "file_client.h"
1.18 #include "flush_client.h"
1.19 -#include "notification_client.h"
1.20 #include "opener_client.h"
1.21 #include "opener_context_client.h"
1.22 #include "pipe_client.h"
1.23 @@ -41,6 +34,7 @@
1.24 #include "mapped_file_client.h"
1.25
1.26 #include "file.h"
1.27 +#include "notifier.h"
1.28
1.29
1.30
1.31 @@ -73,7 +67,7 @@
1.32 {
1.33 file->memory = NULL;
1.34 file->ref = L4_INVALID_CAP;
1.35 - file->irq = L4_INVALID_CAP;
1.36 + file->notifier = L4_INVALID_CAP;
1.37 file->start_pos = 0;
1.38 file->end_pos = 0;
1.39 file->data_end = 0;
1.40 @@ -81,6 +75,7 @@
1.41 file->can_mmap = 1;
1.42 file->has_size = 1;
1.43 file->can_block = 0;
1.44 + file->notifications = 0;
1.45 }
1.46
1.47
1.48 @@ -92,8 +87,8 @@
1.49 if (l4_is_valid_cap(file->ref))
1.50 ipc_cap_free_um(file->ref);
1.51
1.52 - if (l4_is_valid_cap(file->irq))
1.53 - ipc_cap_free_um(file->irq);
1.54 + if (l4_is_valid_cap(file->notifier))
1.55 + ipc_cap_free_um(file->notifier);
1.56
1.57 if (file->memory != NULL)
1.58 ipc_detach_dataspace(file->memory);
1.59 @@ -378,64 +373,48 @@
1.60
1.61 long file_notify_subscribe(file_t *file, notify_flags_t flags)
1.62 {
1.63 - client_Notification notify(file->ref);
1.64 + FileNotifier *notifier = get_notifier();
1.65
1.66 - return notify.subscribe(flags, &file->irq);
1.67 + return notifier->subscribe(file, flags);
1.68 }
1.69
1.70 /* Unsubscribe from notification events on a file. */
1.71
1.72 long file_notify_unsubscribe(file_t *file)
1.73 {
1.74 - if (l4_is_invalid_cap(file->irq))
1.75 + if (l4_is_invalid_cap(file->notifier))
1.76 return -L4_EINVAL;
1.77
1.78 - l4_irq_detach(file->irq);
1.79 -
1.80 - client_Notification notify(file->ref);
1.81 -
1.82 - return notify.unsubscribe();
1.83 -}
1.84 + FileNotifier *notifier = get_notifier();
1.85
1.86 -/* Bind a file IRQ to the current thread. */
1.87 -
1.88 -long file_notify_bind_file(file_t *file)
1.89 -{
1.90 - if (l4_is_invalid_cap(file->irq))
1.91 - return -L4_EINVAL;
1.92 -
1.93 - return ipc_bind_irq(file->irq, (l4_umword_t) file, pthread_l4_cap(pthread_self()));
1.94 + return notifier->unsubscribe(file);
1.95 }
1.96
1.97 /* Wait for a notification event on a file. */
1.98
1.99 long file_notify_wait_file(file_t *file)
1.100 {
1.101 - long err = file_notify_bind_file(file);
1.102 + file_t *affected;
1.103 +
1.104 + do
1.105 + {
1.106 + long err = file_notify_wait_files(&affected);
1.107
1.108 - if (err)
1.109 - return err;
1.110 + if (err)
1.111 + return err;
1.112 + }
1.113 + while (affected != file);
1.114
1.115 - return l4_error(l4_irq_receive(file->irq, L4_IPC_NEVER));
1.116 + return L4_EOK;
1.117 }
1.118
1.119 /* Wait for notification events on files. */
1.120
1.121 long file_notify_wait_files(file_t **file)
1.122 {
1.123 - l4_umword_t label;
1.124 - l4_msgtag_t tag = l4_ipc_wait(l4_utcb(), &label, L4_IPC_NEVER);
1.125 - long err = l4_error(tag);
1.126 + FileNotifier *notifier = get_notifier();
1.127
1.128 - if (err)
1.129 - *file = NULL;
1.130 - else
1.131 - {
1.132 - label = label & ~3UL;
1.133 - *file = reinterpret_cast<file_t *>(label);
1.134 - }
1.135 -
1.136 - return err;
1.137 + return notifier->wait(file);
1.138 }
1.139
1.140