[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 02/15: libfshelp: improve translator list
From: |
Samuel Thibault |
Subject: |
[hurd] 02/15: libfshelp: improve translator list |
Date: |
Sun, 19 Nov 2017 15:27:05 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch dde
in repository hurd.
commit 1a75f7795e8d5e2b7cbc27e39eade1ee04668c19
Author: Justus Winter <address@hidden>
Date: Tue Nov 24 01:20:57 2015 +0100
libfshelp: improve translator list
Use the path names of active translators as keys in the hash table.
* libfshelp/translator-list.c (hash, compare): New functions.
(translator_ihash): Use generalized key interface.
(fshelp_set_active_translator): Update accordingly.
(fshelp_remove_active_translator): Likewise.
---
libfshelp/translator-list.c | 59 +++++++++++++++++++++++++++------------------
1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c
index e043a67..c730ecd 100644
--- a/libfshelp/translator-list.c
+++ b/libfshelp/translator-list.c
@@ -1,6 +1,6 @@
/* A list of active translators.
- Copyright (C) 2013,14 Free Software Foundation, Inc.
+ Copyright (C) 2013,14,15 Free Software Foundation, Inc.
Written by Justus Winter <address@hidden>
@@ -39,17 +39,11 @@ struct translator
mach_port_t active;
};
-/* The list of active translators. */
-static struct hurd_ihash translator_ihash
- = HURD_IHASH_INITIALIZER (HURD_IHASH_NO_LOCP);
-
-/* The lock protecting the translator_ihash. */
-static pthread_mutex_t translator_ihash_lock = PTHREAD_MUTEX_INITIALIZER;
-
+/* The hash table requires some callback functions. */
static void
-translator_ihash_cleanup (void *element, void *arg)
+cleanup (void *value, void *arg)
{
- struct translator *translator = element;
+ struct translator *translator = value;
if (translator->pi)
ports_port_deref (translator->pi);
@@ -58,6 +52,26 @@ translator_ihash_cleanup (void *element, void *arg)
free (translator);
}
+static hurd_ihash_key_t
+hash (const void *key)
+{
+ return (hurd_ihash_key_t) hurd_ihash_hash32 (key, strlen (key), 0);
+}
+
+static int
+compare (const void *a, const void *b)
+{
+ return strcmp ((const char *) a, (const char *) b) == 0;
+}
+
+/* The list of active translators. */
+static struct hurd_ihash translator_ihash
+ = HURD_IHASH_INITIALIZER_GKI (HURD_IHASH_NO_LOCP, cleanup, NULL,
+ hash, compare);
+
+/* The lock protecting the translator_ihash. */
+static pthread_mutex_t translator_ihash_lock = PTHREAD_MUTEX_INITIALIZER;
+
/* Record an active translator being bound to the given file name
NAME. ACTIVE is the control port of the translator. */
error_t
@@ -66,20 +80,16 @@ fshelp_set_active_translator (struct port_info *pi,
mach_port_t active)
{
error_t err = 0;
- pthread_mutex_lock (&translator_ihash_lock);
-
- if (! translator_ihash.cleanup)
- hurd_ihash_set_cleanup (&translator_ihash, translator_ihash_cleanup, NULL);
+ struct translator *t;
+ hurd_ihash_locp_t slot;
- struct translator *t = NULL;
- HURD_IHASH_ITERATE (&translator_ihash, value)
- {
- t = value;
- if (strcmp (name, t->name) == 0)
- goto update; /* Entry exists. */
- }
+ pthread_mutex_lock (&translator_ihash_lock);
+ t = hurd_ihash_locp_find (&translator_ihash, (hurd_ihash_key_t) name,
+ &slot);
+ if (t)
+ goto update; /* Entry exists. */
- t = malloc (sizeof (struct translator));
+ t = malloc (sizeof *t);
if (! t)
{
err = errno;
@@ -96,7 +106,8 @@ fshelp_set_active_translator (struct port_info *pi,
goto out;
}
- err = hurd_ihash_add (&translator_ihash, (hurd_ihash_key_t) t, t);
+ err = hurd_ihash_locp_add (&translator_ihash, slot,
+ (hurd_ihash_key_t) t->name, t);
if (err)
goto out;
@@ -158,7 +169,7 @@ fshelp_remove_active_translator (mach_port_t active)
}
if (t)
- hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t);
+ hurd_ihash_remove (&translator_ihash, (hurd_ihash_key_t) t->name);
pthread_mutex_unlock (&translator_ihash_lock);
return err;
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] branch dde updated (4d4175c -> e3c726d), Samuel Thibault, 2017/11/19
- [hurd] 04/15: libfshelp: Avoid useless allocations., Samuel Thibault, 2017/11/19
- [hurd] 05/15: libfshelp: Always register dead-name notifications., Samuel Thibault, 2017/11/19
- [hurd] 07/15: Normalize path of translators., Samuel Thibault, 2017/11/19
- [hurd] 09/15: libfshelp: Avoid some right diddling., Samuel Thibault, 2017/11/19
- [hurd] 08/15: libfshelp: Improve error handling., Samuel Thibault, 2017/11/19
- [hurd] 12/15: libdiskfs: Shutdown pagers on startup_dosync., Samuel Thibault, 2017/11/19
- [hurd] 10/15: libfshelp: Use node instead of name as key., Samuel Thibault, 2017/11/19
- [hurd] 06/15: libfshelp: Add function to map over all active translators., Samuel Thibault, 2017/11/19
- [hurd] 02/15: libfshelp: improve translator list,
Samuel Thibault <=
- [hurd] 01/15: pflocal: Use default stub implementations., Samuel Thibault, 2017/11/19
- [hurd] 15/15: Merge branch 'dde-upstream' into dde, Samuel Thibault, 2017/11/19
- [hurd] 03/15: Fix active translator registration., Samuel Thibault, 2017/11/19
- [hurd] 13/15: Merge remote-tracking branch 'mainline/master' into dde, Samuel Thibault, 2017/11/19
- [hurd] 14/15: Merge branch 'dde' of git.savannah.gnu.org:/srv/git/hurd/incubator into dde-upstream, Samuel Thibault, 2017/11/19
- [hurd] 11/15: Traverse translator hierarchies using the fsys protocol., Samuel Thibault, 2017/11/19