]> Savannah Git Hosting - gnulib.git/commitdiff
localename: Use module 'thread-optim'.
authorBruno Haible <bruno@clisp.org>
Sat, 8 Aug 2020 20:11:50 +0000 (22:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 8 Aug 2020 20:11:50 +0000 (22:11 +0200)
* lib/localename.c: Include thread-optim.h.
(struniq): Use IF_MT macro.
* modules/localename (Depends-on): Add thread-optim.

ChangeLog
lib/localename.c
modules/localename

index 1ee85d6f1d1239b31b06400ebd4874de9053be07..d9a78c4fc86dabb324148bd0035699b25711bcf9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2020-08-08  Bruno Haible  <bruno@clisp.org>
 
+       localename: Use module 'thread-optim'.
+       * lib/localename.c: Include thread-optim.h.
+       (struniq): Use IF_MT macro.
+       * modules/localename (Depends-on): Add thread-optim.
+
        clean-temp: Use module 'thread-optim'.
        * lib/clean-temp.c: Include thread-optim.h.
        (register_temporary_file, unregister_temporary_file, create_temp_dir,
index dc60b07c565696dfdd6478ef2a0f0887ae145bcd..2e76c1161938681054cecd4d09173b7d98ab56d0 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "flexmember.h"
 #include "setlocale_null.h"
+#include "thread-optim.h"
 
 /* We cannot support uselocale() on platforms where the locale_t type is fake.
    See intl-thread-locale.m4 for details.  */
@@ -2697,24 +2698,27 @@ struniq (const char *string)
     /* Out of memory.  Return a statically allocated string.  */
     return "C";
   memcpy (new_node->contents, string, size);
-  /* Lock while inserting new_node.  */
-  gl_lock_lock (struniq_lock);
-  /* Check whether another thread already added the string while we were
-     waiting on the lock.  */
-  for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
-    if (strcmp (p->contents, string) == 0)
-      {
-        free (new_node);
-        new_node = p;
-        goto done;
-      }
-  /* Really insert new_node into the hash table.  Fill new_node entirely first,
-     because other threads may be iterating over the linked list.  */
-  new_node->next = struniq_hash_table[slot];
-  struniq_hash_table[slot] = new_node;
- done:
-  /* Unlock after new_node is inserted.  */
-  gl_lock_unlock (struniq_lock);
+  {
+    IF_MT_DECL;
+    /* Lock while inserting new_node.  */
+    IF_MT gl_lock_lock (struniq_lock);
+    /* Check whether another thread already added the string while we were
+       waiting on the lock.  */
+    for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
+      if (strcmp (p->contents, string) == 0)
+        {
+          free (new_node);
+          new_node = p;
+          goto done;
+        }
+    /* Really insert new_node into the hash table.  Fill new_node entirely
+       first, because other threads may be iterating over the linked list.  */
+    new_node->next = struniq_hash_table[slot];
+    struniq_hash_table[slot] = new_node;
+   done:
+    /* Unlock after new_node is inserted.  */
+    IF_MT gl_lock_unlock (struniq_lock);
+  }
   return new_node->contents;
 }
 
index c528acb51a6225140ea928bb8df49cb5033f220f..28710d0bf75b1868c3b8bd22d2129575b674da5e 100644 (file)
@@ -19,6 +19,7 @@ strdup
 lock
 langinfo
 setlocale-null
+thread-optim
 
 configure.ac:
 gl_LOCALENAME