summaryrefslogtreecommitdiff
path: root/libfshelp
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-12-04 17:14:49 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2013-12-09 15:07:59 +0100
commita0a49e530b269679695daa6014bfade0b36970e1 (patch)
tree30595221c468f55a41964b14ee71858c3e2dee9b /libfshelp
parent6204a717fc63891839faefda75e95a364ec0434e (diff)
libfshelp: use a hash table in get-identity.c
Currently fshelp_get_identity uses ports_class_iterate to de-duplicate the identity ports. Use a hash table instead. * libfshelp/get-identity.c (struct idspec): Remove field fileno. (struct idspec): Add field id_hashloc. (id_clean): New function. (id_initialize): Use id_clean as cleanup function for idclass. (fshelp_get_identity): Use a hash table to de-duplicate the identity ports.
Diffstat (limited to 'libfshelp')
-rw-r--r--libfshelp/get-identity.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/libfshelp/get-identity.c b/libfshelp/get-identity.c
index 946b7e8e..2dbd254c 100644
--- a/libfshelp/get-identity.c
+++ b/libfshelp/get-identity.c
@@ -21,6 +21,8 @@
#include <fshelp.h>
#include <hurd/ports.h>
+#include <hurd/ihash.h>
+#include <stddef.h>
#include <assert.h>
static struct port_class *idclass = 0;
@@ -29,14 +31,26 @@ static pthread_mutex_t idlock = PTHREAD_MUTEX_INITIALIZER;
struct idspec
{
struct port_info pi;
- ino_t fileno;
+ hurd_ihash_locp_t id_hashloc;
};
+static struct hurd_ihash idhash
+ = HURD_IHASH_INITIALIZER (offsetof (struct idspec, id_hashloc));
+
+static void
+id_clean (void *cookie)
+{
+ struct idspec *i = cookie;
+ pthread_mutex_lock (&idlock);
+ hurd_ihash_locp_remove (&idhash, i->id_hashloc);
+ pthread_mutex_unlock (&idlock);
+}
+
static void
id_initialize ()
{
assert (!idclass);
- idclass = ports_create_class (0, 0);
+ idclass = ports_create_class (id_clean, NULL);
}
error_t
@@ -47,42 +61,32 @@ fshelp_get_identity (struct port_bucket *bucket,
struct idspec *i;
error_t err = 0;
- error_t check_port (void *arg)
- {
- struct idspec *i = arg;
- if (i->fileno == fileno)
- {
- *pt = ports_get_right (i);
- return 1;
- }
- else
- return 0;
- }
-
pthread_mutex_lock (&idlock);
if (!idclass)
id_initialize ();
- *pt = MACH_PORT_NULL;
-
- ports_class_iterate (idclass, check_port);
-
- if (*pt != MACH_PORT_NULL)
+ i = hurd_ihash_find (&idhash, (hurd_ihash_key_t) fileno);
+ if (i == NULL)
{
- pthread_mutex_unlock (&idlock);
- return 0;
+ err = ports_create_port (idclass, bucket, sizeof (struct idspec), &i);
+ if (err)
+ goto lose;
+ err = hurd_ihash_add (&idhash, (hurd_ihash_key_t) fileno, i);
+ if (err)
+ goto lose_port;
+
+ *pt = ports_get_right (i);
+ ports_port_deref (i);
}
+ else
+ *pt = ports_get_right (i);
- err = ports_create_port (idclass, bucket, sizeof (struct idspec), &i);
- if (err)
- {
- pthread_mutex_unlock (&idlock);
- return err;
- }
- i->fileno = fileno;
+ /* Success! */
+ goto lose;
- *pt = ports_get_right (i);
- ports_port_deref (i);
+ lose_port:
+ ports_destroy_right (i);
+ lose:
pthread_mutex_unlock (&idlock);
- return 0;
+ return err;
}