aboutsummaryrefslogtreecommitdiff
path: root/libports
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-08-05 16:47:08 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-10 22:12:09 +0200
commitcbe5af61970052429388737de19dbc7ad03ffa96 (patch)
tree6593266852426d9aa6306414044d902e16b8a230 /libports
parent8db6b70ab6a64ea9b0ac313f2816131a046fbd76 (diff)
downloadhurd-cbe5af61970052429388737de19dbc7ad03ffa96.tar.gz
hurd-cbe5af61970052429388737de19dbc7ad03ffa96.tar.bz2
hurd-cbe5af61970052429388737de19dbc7ad03ffa96.zip
libports: Create a notify_port in each bucket
This notify port will be used to request & receive Mach notifications. While it is present in the bucket much like any other port, it is not counted in ports_count_bucket () and is not exposed to the user callback in ports_bucket_iterate ().
Diffstat (limited to 'libports')
-rw-r--r--libports/bucket-iterate.c5
-rw-r--r--libports/count-bucket.c11
-rw-r--r--libports/create-bucket.c23
-rw-r--r--libports/ports.h13
4 files changed, 45 insertions, 7 deletions
diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c
index b021b99e..9103c297 100644
--- a/libports/bucket-iterate.c
+++ b/libports/bucket-iterate.c
@@ -1,5 +1,5 @@
/* Iterate a function over the ports in a bucket.
- Copyright (C) 1995, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1999, 2021 Free Software Foundation, Inc.
Written by Michael I. Bushnell.
This file is part of the GNU Hurd.
@@ -76,7 +76,8 @@ _ports_bucket_class_iterate (struct hurd_ihash *ht,
err = 0;
for (i = 0; i < n; i++)
{
- if (!err)
+ /* Never expose the notify port to the user function. */
+ if (!err && !ports_port_is_notify (p[i]))
err = (*fun)(p[i]);
ports_port_deref (p[i]);
}
diff --git a/libports/count-bucket.c b/libports/count-bucket.c
index 63feb6be..45fc7bfa 100644
--- a/libports/count-bucket.c
+++ b/libports/count-bucket.c
@@ -1,5 +1,5 @@
-/*
- Copyright (C) 1995 Free Software Foundation, Inc.
+/*
+ Copyright (C) 1995, 2021 Free Software Foundation, Inc.
Written by Michael I. Bushnell.
This file is part of the GNU Hurd.
@@ -24,11 +24,12 @@ int
ports_count_bucket (struct port_bucket *bucket)
{
int ret;
-
+
pthread_mutex_lock (&_ports_lock);
- ret = bucket->count;
+ /* Account for the notify port. */
+ ret = bucket->count - 1;
bucket->flags |= PORT_BUCKET_NO_ALLOC;
pthread_mutex_unlock (&_ports_lock);
-
+
return ret;
}
diff --git a/libports/create-bucket.c b/libports/create-bucket.c
index 82c00a4b..81fe044c 100644
--- a/libports/create-bucket.c
+++ b/libports/create-bucket.c
@@ -24,6 +24,15 @@
#include <stdlib.h>
#include <hurd/ihash.h>
+static struct port_class *notify_port_class;
+static pthread_once_t init_notify_port_class_once = PTHREAD_ONCE_INIT;
+
+static void
+init_notify_port_class ()
+{
+ notify_port_class = ports_create_class (NULL, NULL);
+}
+
struct port_bucket *
ports_create_bucket ()
{
@@ -49,5 +58,19 @@ ports_create_bucket ()
hurd_ihash_init (&ret->htable, offsetof (struct port_info, hentry));
ret->rpcs = ret->flags = ret->count = 0;
_ports_threadpool_init (&ret->threadpool);
+
+ /* Create the notify_port for this bucket. */
+ pthread_once (&init_notify_port_class_once, init_notify_port_class);
+ err = ports_create_port (notify_port_class, ret,
+ sizeof (struct port_info),
+ &ret->notify_port);
+ if (err)
+ {
+ hurd_ihash_destroy (&ret->htable);
+ free (ret);
+ errno = err;
+ return NULL;
+ }
+
return ret;
}
diff --git a/libports/ports.h b/libports/ports.h
index 7295093d..f8ce9b6c 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -80,6 +80,8 @@ struct port_bucket
int flags;
int count;
struct ports_threadpool threadpool;
+ /* A port in this bucket used to receive Mach notifications. */
+ struct port_info *notify_port;
};
/* FLAGS above are the following: */
#define PORT_BUCKET_INHIBITED PORTS_INHIBITED
@@ -309,6 +311,17 @@ void ports_port_deref (void *port);
/* Drop a weak reference to PORT. */
void ports_port_deref_weak (void *port);
+/* Use this port right to request notifications about PORT. */
+#define ports_port_notify_right(port) \
+ ((struct port_info *) (port))->bucket->notify_port->port_right
+
+/* Is PORT the notify port for its bucket? */
+#define ports_port_is_notify(port) \
+ ({ \
+ struct port_info *__pi = (port); \
+ __pi ? (__pi->bucket->notify_port == __pi) : 0; \
+ })
+
/* The user is responsible for listening for no senders notifications;
when one arrives, call this routine for the PORT the message was
sent to, providing the MSCOUNT from the notification. */