2006-07-12 Marcus Brinkmann <marcus@g10code.de>
authorMarcus Brinkmann <mb@g10code.com>
Wed, 12 Jul 2006 19:36:27 +0000 (19:36 +0000)
committerMarcus Brinkmann <mb@g10code.com>
Wed, 12 Jul 2006 19:36:27 +0000 (19:36 +0000)
* ath.c (ath_mutex_destroy): Microoptimize destruction of unused
statitically initialized mutexes.  Suggested by Victor Stinner
<haypo@inl.fr>.

src/ChangeLog
src/ath.c

index 602df29..d4f225a 100644 (file)
@@ -1,5 +1,9 @@
 2006-07-12  Marcus Brinkmann  <marcus@g10code.de>
 
+       * ath.c (ath_mutex_destroy): Microoptimize destruction of unused
+       statitically initialized mutexes.  Suggested by Victor Stinner
+       <haypo@inl.fr>.
+
        * gcrypt.h (GCRY_THREAD_OPTION_PTHREAD_IMPL,
        (GCRY_THREAD_OPTION_PTH_IMPL): Add missing initializers to
        suppress gcc warning.
index 628a6bb..2768d8e 100644 (file)
--- a/src/ath.c
+++ b/src/ath.c
@@ -149,15 +149,17 @@ ath_mutex_destroy (ath_mutex_t *lock)
 {
   if (ops_set)
     {
-      int err = mutex_init (lock, 1);
-
-      if (err)
-       return err;
-
-      if (ops.mutex_destroy)
-       return (*ops.mutex_destroy) (lock);
-      else
+      if (!ops.mutex_destroy)
        return 0;
+
+      (*ops.mutex_lock) (&check_init_lock);
+      if (*lock == ATH_MUTEX_INITIALIZER)
+       {
+         (*ops.mutex_unlock) (&check_init_lock);
+         return 0;
+       }
+      (*ops.mutex_unlock) (&check_init_lock);
+      return (*ops.mutex_destroy) (lock);
     }
 
 #ifndef NDEBUG