[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 63/98: libfshelp: use a hash table in get-identity.c
From: |
Samuel Thibault |
Subject: |
[hurd] 63/98: libfshelp: use a hash table in get-identity.c |
Date: |
Tue, 14 Jan 2014 02:00:02 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit a0a49e530b269679695daa6014bfade0b36970e1
Author: Justus Winter <address@hidden>
Date: Wed Dec 4 17:14:49 2013 +0100
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.
---
libfshelp/get-identity.c | 66 +++++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 31 deletions(-)
diff --git a/libfshelp/get-identity.c b/libfshelp/get-identity.c
index 946b7e8..2dbd254 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;
}
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 92/98: trans/mtab: properly lock mtab objects, (continued)
- [hurd] 92/98: trans/mtab: properly lock mtab objects, Samuel Thibault, 2014/01/13
- [hurd] 03/98: libports: fix the thread counts in case the thread creation fails, Samuel Thibault, 2014/01/13
- [hurd] 76/98: utils/settrans: fix the teardown of chrooted environments, Samuel Thibault, 2014/01/13
- [hurd] 16/98: libshouldbeinlibc: fix reference counting in port_name_xlator_create, Samuel Thibault, 2014/01/13
- [hurd] 95/98: libfshelp: fix the api of fshelp_set_active_translator, Samuel Thibault, 2014/01/13
- [hurd] 98/98: Merge remote-tracking branch 'upstream/master' into upstream, Samuel Thibault, 2014/01/13
- [hurd] 17/98: utils: implement portinfo --search, Samuel Thibault, 2014/01/13
- [hurd] 10/98: auth: fix use of uninitialized variable err, Samuel Thibault, 2014/01/13
- [hurd] 61/98: trans: fix transparent reauthentication in fakeroot, Samuel Thibault, 2014/01/13
- [hurd] 01/98: pfinet: fix emission on the loopback device, Samuel Thibault, 2014/01/13
- [hurd] 63/98: libfshelp: use a hash table in get-identity.c,
Samuel Thibault <=
- [hurd] 90/98: trans/mtab: populate mtab objects on demand, Samuel Thibault, 2014/01/13
- [hurd] 09/98: init: fix memory leak, Samuel Thibault, 2014/01/13
- [hurd] 88/98: libports: remove the threadvars stack size hack, Samuel Thibault, 2014/01/13
- [hurd] 02/98: Normalize whitespace at the end of each file to '\n', Samuel Thibault, 2014/01/13
- [hurd] 84/98: utils/rpctrace: handle MACH_MSG_TYPE_PORT_SEND rights in trace_and_forward, Samuel Thibault, 2014/01/13
- [hurd] 82/98: utils/rpctrace: generalize code in rewrite_right, Samuel Thibault, 2014/01/13
- [hurd] 86/98: utils/rpctrace: fix output so that replies can be attributed to requests, Samuel Thibault, 2014/01/13
- [hurd] 81/98: utils/mount: fix autodetection of fat file systems, Samuel Thibault, 2014/01/13
- [hurd] 79/98: trans/fakeroot: remove dead code, Samuel Thibault, 2014/01/13
- [hurd] 85/98: utils/rpctrace: escape non-printable characters in strings, Samuel Thibault, 2014/01/13