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,
#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. */
/* 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;
}