[or-cvs] r15222: Set dynamic-locking callbacks in openssl. These can be more (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Fri Jun 13 16:35:13 UTC 2008


Author: nickm
Date: 2008-06-13 12:35:12 -0400 (Fri, 13 Jun 2008)
New Revision: 15222

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/common/crypto.c
Log:
Set dynamic-locking callbacks in openssl.  These can be more efficient when openssl uses them.

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-06-13 16:05:37 UTC (rev 15221)
+++ tor/trunk/ChangeLog	2008-06-13 16:35:12 UTC (rev 15222)
@@ -1,3 +1,7 @@
+Changes in version 0.2.1.2-alpha - 2008-??-??
+  o Minor features:
+    - Allow OpenSSL to use dynamic locks if it wants.
+
 Changes in version 0.2.1.1-alpha - 2008-06-13
   o Major features:
     - More work on making our TLS handshake blend in: modify the list

Modified: tor/trunk/src/common/crypto.c
===================================================================
--- tor/trunk/src/common/crypto.c	2008-06-13 16:05:37 UTC (rev 15221)
+++ tor/trunk/src/common/crypto.c	2008-06-13 16:35:12 UTC (rev 15222)
@@ -2227,6 +2227,43 @@
     tor_mutex_release(_openssl_mutexes[n]);
 }
 
+struct CRYPTO_dynlock_value {
+  tor_mutex_t *lock;
+};
+
+static struct CRYPTO_dynlock_value *
+_openssl_dynlock_create_cb(const char *file, int line)
+{
+  struct CRYPTO_dynlock_value *v;
+  (void)file;
+  (void)line;
+  v = tor_malloc(sizeof(struct CRYPTO_dynlock_value));
+  v->lock = tor_mutex_new();
+  return v;
+}
+
+static void
+_openssl_dynlock_lock_cb(int mode, struct CRYPTO_dynlock_value *v,
+                         const char *file, int line)
+{
+  (void)file;
+  (void)line;
+  if (mode & CRYPTO_LOCK)
+    tor_mutex_acquire(v->lock);
+  else
+    tor_mutex_release(v->lock);
+}
+
+static void
+_openssl_dynlock_destroy_cb(struct CRYPTO_dynlock_value *v,
+                            const char *file, int line)
+{
+  (void)file;
+  (void)line;
+  tor_mutex_free(v->lock);
+  tor_free(v);
+}
+
 /** Helper: Construct mutexes, and set callbacks to help OpenSSL handle being
  * multithreaded. */
 static int
@@ -2240,6 +2277,9 @@
     _openssl_mutexes[i] = tor_mutex_new();
   CRYPTO_set_locking_callback(_openssl_locking_cb);
   CRYPTO_set_id_callback(tor_get_thread_id);
+  CRYPTO_set_dynlock_create_callback(_openssl_dynlock_create_cb);
+  CRYPTO_set_dynlock_lock_callback(_openssl_dynlock_lock_cb);
+  CRYPTO_set_dynlock_destroy_callback(_openssl_dynlock_destroy_cb);
   return 0;
 }
 #else



More information about the tor-commits mailing list