-#define USE_MUTEX
-
-static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
-#ifdef USE_MUTEX
-static long lock_count[CRYPTO_NUM_LOCKS];
-#else
-static rwlock_t lock_cs[CRYPTO_NUM_LOCKS];
-#endif
-
-void CRYPTO_thread_setup()
- {
- int i;
-
- for (i=0; i<CRYPTO_NUM_LOCKS; i++)
- {
- lock_count[i]=0;
-#ifdef USE_MUTEX
- mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
-#else
- rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL);
-#endif
- }
-
- CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
- CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
- }
-
-void CRYPTO_thread_cleanup()
- {
- int i;
-
- CRYPTO_set_locking_callback(NULL);
- for (i=0; i<CRYPTO_NUM_LOCKS; i++)
- {
-#ifdef USE_MUTEX
- mutex_destroy(&(lock_cs[i]));
-#else
- rwlock_destroy(&(lock_cs[i]));
-#endif
- }
- }
-
-void solaris_locking_callback(mode,type,file,line)
-int mode;
-int type;
-char *file;
-int line;
- {
-#if 0
- fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
- CRYPTO_thread_id(),
- (mode&CRYPTO_LOCK)?"l":"u",
- (type&CRYPTO_READ)?"r":"w",file,line);
-#endif
-
-#if 0
- if (CRYPTO_LOCK_SSL_CERT == type)
- fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
- CRYPTO_thread_id(),
- mode,file,line);
-#endif
- if (mode & CRYPTO_LOCK)
- {
-#ifdef USE_MUTEX
- mutex_lock(&(lock_cs[type]));
-#else
- if (mode & CRYPTO_READ)
- rw_rdlock(&(lock_cs[type]));
- else
- rw_wrlock(&(lock_cs[type]));
-#endif
- lock_count[type]++;
- }
- else
- {
-#ifdef USE_MUTEX
- mutex_unlock(&(lock_cs[type]));
-#else
- rw_unlock(&(lock_cs[type]));
-#endif
- }
- }
-
-unsigned long solaris_thread_id()
- {
- unsigned long ret;
-
- ret=(unsigned long)thr_self();
- return(ret);
- }
-#endif /* SOLARIS */
+# define USE_MUTEX
+
+# ifdef USE_MUTEX
+static mutex_t *lock_cs;
+# else
+static rwlock_t *lock_cs;
+# endif
+static long *lock_count;
+
+void CRYPTO_thread_setup(void)
+{
+ int i;
+
+# ifdef USE_MUTEX
+ lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t));
+# else
+ lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(rwlock_t));
+# endif
+ if(!lock_cs) {
+ /* Nothing we can do about this...void function! */
+ return;
+ }
+ lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
+ for (i = 0; i < CRYPTO_num_locks(); i++) {
+ lock_count[i] = 0;
+# ifdef USE_MUTEX
+ mutex_init(&(lock_cs[i]), USYNC_THREAD, NULL);
+# else
+ rwlock_init(&(lock_cs[i]), USYNC_THREAD, NULL);
+# endif
+ }
+
+ CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
+ CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
+}
+
+void CRYPTO_thread_cleanup(void)
+{
+ int i;
+
+ CRYPTO_set_locking_callback(NULL);
+ for (i = 0; i < CRYPTO_num_locks(); i++) {
+# ifdef USE_MUTEX
+ mutex_destroy(&(lock_cs[i]));
+# else
+ rwlock_destroy(&(lock_cs[i]));
+# endif
+ }
+ OPENSSL_free(lock_cs);
+ OPENSSL_free(lock_count);
+}
+
+void solaris_locking_callback(int mode, int type, char *file, int line)
+{
+ if (mode & CRYPTO_LOCK) {
+# ifdef USE_MUTEX
+ mutex_lock(&(lock_cs[type]));
+# else
+ if (mode & CRYPTO_READ)
+ rw_rdlock(&(lock_cs[type]));
+ else
+ rw_wrlock(&(lock_cs[type]));
+# endif
+ lock_count[type]++;
+ } else {
+# ifdef USE_MUTEX
+ mutex_unlock(&(lock_cs[type]));
+# else
+ rw_unlock(&(lock_cs[type]));
+# endif
+ }
+}
+
+unsigned long solaris_thread_id(void)
+{
+ unsigned long ret;
+
+ ret = (unsigned long)thr_self();
+ return (ret);
+}
+#endif /* SOLARIS */