summaryrefslogtreecommitdiff
path: root/debian/patches/translators-list0003-libfshelp-improve-translator-list.patch
blob: a3f021d8f3732a9238dcdd6e805add7d9db93a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From 34499d5045ba39674b9801f09c6c5b468fe46f49 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Tue, 24 Nov 2015 01:20:57 +0100
Subject: [PATCH hurd 3/4] 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 8f0bfae..173da7f 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 <4winter@informatik.uni-hamburg.de>
 
@@ -39,18 +39,12 @@ 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)
 {
   error_t err;
-  struct translator *translator = element;
+  struct translator *translator = value;
 
   if (translator->pi)
     ports_port_deref (translator->pi);
@@ -62,6 +56,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
@@ -70,20 +84,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;
@@ -100,7 +110,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;
 
@@ -171,7 +182,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;
-- 
2.1.4