Index: gwlib/conn.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/conn.c,v
retrieving revision 1.88
diff -u -w -8 -r1.88 conn.c
--- gwlib/conn.c	12 Jan 2009 16:46:54 -0000	1.88
+++ gwlib/conn.c	7 Apr 2009 20:14:22 -0000
@@ -1259,53 +1259,67 @@
 	   rsa = RSA_generate_key(key_len, RSA_F4, NULL, NULL);
     } else {
 	   debug("gwlib.http", 0, "SSL: Export not set");
     }
     return rsa;
 }
 */
 
-static Mutex **ssl_static_locks = NULL;
+static pthread_mutex_t *ssl_static_locks = NULL;
+static int ssl_lock_num_locks = 0;
 
 /* the call-back function for the openssl crypto thread locking */
 static void openssl_locking_function(int mode, int n, const char *file, int line)
 {
-    if (mode & CRYPTO_LOCK)
-        mutex_lock(ssl_static_locks[n-1]);
-    else
-        mutex_unlock(ssl_static_locks[n-1]);
+    if (n & ssl_lock_num_locks) {
+        if (mode & CRYPTO_LOCK) {
+            pthread_mutex_lock(&(ssl_static_locks[n]));
+        } else {
+            pthread_mutex_unlock(&(ssl_static_locks[n]));
+        }
+    }
+}
+
+static unsigned long openssl_thread_id(void)
+{
+    return (unsigned long) pthread_self();
 }
 
 void openssl_init_locks(void)
 {
-    int c, maxlocks = CRYPTO_num_locks();
+    int c;
+    
+    ssl_lock_num_locks = CRYPTO_num_locks();
 
     gw_assert(ssl_static_locks == NULL);
 
-    ssl_static_locks = gw_malloc(sizeof(Mutex *) * maxlocks);
-    for (c = 0; c < maxlocks; c++)
-        ssl_static_locks[c] = mutex_create();
+    ssl_static_locks = gw_malloc(sizeof(pthread_mutex_t) * ssl_lock_num_locks);
+    for (c = 0; c < ssl_lock_num_locks; c++) {
+        pthread_mutex_init(&(ssl_static_locks[c]), NULL);
+    }   
 
     /* after the mutexes have been created, apply the call-back to it */
+	CRYPTO_set_id_callback(openssl_thread_id);
     CRYPTO_set_locking_callback(openssl_locking_function);
-    CRYPTO_set_id_callback((CRYPTO_CALLBACK_PTR)gwthread_self);
 }
 
 void openssl_shutdown_locks(void)
 {
-    int c, maxlocks = CRYPTO_num_locks();
+	int c;
 
     gw_assert(ssl_static_locks != NULL);
 
     /* remove call-back from the locks */
     CRYPTO_set_locking_callback(NULL);
+	CRYPTO_set_id_callback(NULL);
 
-    for (c = 0; c < maxlocks; c++) 
-        mutex_destroy(ssl_static_locks[c]);
+    for (c = 0; c < ssl_lock_num_locks; c++) {
+        pthread_mutex_destroy(&(ssl_static_locks[c]));
+    }
 
     gw_free(ssl_static_locks);
     ssl_static_locks = NULL;
 }
 
 void conn_init_ssl(void)
 {
     SSL_library_init();
