- Made sure some changed behavior is documented in CHANGES.
[openssl.git] / mt / mttest.c
index 3a927a293754129acd4706fd0227684eec8855c6..b2f332602dac1efd21c3340edacac457ee0e1cdb 100644 (file)
@@ -1,5 +1,5 @@
 /* mt/mttest.c */
 /* mt/mttest.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
  * All rights reserved.
  *
  * This package is an SSL implementation written
 #include <ulocks.h>
 #include <sys/prctl.h>
 #endif
 #include <ulocks.h>
 #include <sys/prctl.h>
 #endif
-#include "lhash.h"
-#include "crypto.h"
-#include "buffer.h"
+#include <openssl/lhash.h>
+#include <openssl/crypto.h>
+#include <openssl/buffer.h>
 #include "../e_os.h"
 #include "../e_os.h"
-#include "x509.h"
-#include "ssl.h"
-#include "err.h"
+#include <openssl/x509.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
 
 
-#ifdef WIN16
+#ifdef NO_FP_API
 #define APPS_WIN16
 #include "../crypto/buffer/bss_file.c"
 #endif
 #define APPS_WIN16
 #include "../crypto/buffer/bss_file.c"
 #endif
 
 #define MAX_THREAD_NUMBER      100
 
 
 #define MAX_THREAD_NUMBER      100
 
-#ifndef NOPROTO
 int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
        int error,char *arg);
 void thread_setup(void);
 void thread_cleanup(void);
 void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
 int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
        int error,char *arg);
 void thread_setup(void);
 void thread_cleanup(void);
 void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
+
 void irix_locking_callback(int mode,int type,char *file,int line);
 void solaris_locking_callback(int mode,int type,char *file,int line);
 void win32_locking_callback(int mode,int type,char *file,int line);
 void irix_locking_callback(int mode,int type,char *file,int line);
 void solaris_locking_callback(int mode,int type,char *file,int line);
 void win32_locking_callback(int mode,int type,char *file,int line);
-void linux_locking_callback(int mode,int type,char *file,int line);
+void pthreads_locking_callback(int mode,int type,char *file,int line);
+
 unsigned long irix_thread_id(void );
 unsigned long solaris_thread_id(void );
 unsigned long irix_thread_id(void );
 unsigned long solaris_thread_id(void );
-unsigned long linix_thread_id(void );
-#else
-int MS_CALLBACK verify_callback();
-void thread_setup();
-void thread_cleanup();
-void do_threads();
-void irix_locking_callback();
-void solaris_locking_callback();
-void win32_locking_callback();
-void linux_locking_callback();
-unsigned long irix_thread_id();
-unsigned long solaris_thread_id();
-unsigned long linix_thread_id();
-#endif
+unsigned long pthreads_thread_id(void );
 
 BIO *bio_err=NULL;
 BIO *bio_stdout=NULL;
 
 BIO *bio_err=NULL;
 BIO *bio_stdout=NULL;
@@ -133,12 +121,7 @@ int number_of_loops=10;
 int reconnect=0;
 int cache_stats=0;
 
 int reconnect=0;
 int cache_stats=0;
 
-#ifndef  NOPROTO
 int doit(char *ctx[4]);
 int doit(char *ctx[4]);
-#else
-int doit();
-#endif
-
 static void print_stats(fp,ctx)
 FILE *fp;
 SSL_CTX *ctx;
 static void print_stats(fp,ctx)
 FILE *fp;
 SSL_CTX *ctx;
@@ -700,7 +683,7 @@ char *arg;
 
 #ifdef WIN32
 
 
 #ifdef WIN32
 
-static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
+static PRLOCK lock_cs[CRYPTO_NUM_LOCKS];
 
 void thread_setup()
        {
 
 void thread_setup()
        {
@@ -792,7 +775,7 @@ SSL_CTX *s_ctx,*c_ctx;
        printf("win32 threads done - %.3f seconds\n",ret);
        }
 
        printf("win32 threads done - %.3f seconds\n",ret);
        }
 
-#endif
+#endif /* WIN32 */
 
 #ifdef SOLARIS
 
 
 #ifdef SOLARIS
 
@@ -903,7 +886,7 @@ unsigned long solaris_thread_id()
        ret=(unsigned long)thr_self();
        return(ret);
        }
        ret=(unsigned long)thr_self();
        return(ret);
        }
-#endif
+#endif /* SOLARIS */
 
 #ifdef IRIX
 
 
 #ifdef IRIX
 
@@ -1001,5 +984,109 @@ unsigned long irix_thread_id()
        ret=(unsigned long)getpid();
        return(ret);
        }
        ret=(unsigned long)getpid();
        return(ret);
        }
+#endif /* IRIX */
+
+#ifdef PTHREADS
+
+static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
+static long lock_count[CRYPTO_NUM_LOCKS];
+
+void thread_setup()
+       {
+       int i;
+
+       for (i=0; i<CRYPTO_NUM_LOCKS; i++)
+               {
+               lock_count[i]=0;
+               pthread_mutex_init(&(lock_cs[i]),NULL);
+               }
+
+       CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
+       CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
+       }
+
+void thread_cleanup()
+       {
+       int i;
+
+       CRYPTO_set_locking_callback(NULL);
+       fprintf(stderr,"cleanup\n");
+       for (i=0; i<CRYPTO_NUM_LOCKS; i++)
+               {
+               pthread_mutex_destroy(&(lock_cs[i]));
+               fprintf(stderr,"%8ld:%s\n",lock_count[i],
+                       CRYPTO_get_lock_name(i));
+               }
+       fprintf(stderr,"done cleanup\n");
+       }
+
+void pthreads_locking_callback(mode,type,file,line)
+int mode;
+int type;
+char *file;
+int line;
+      {
+#ifdef undef
+       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
 #endif
+/*
+       if (CRYPTO_LOCK_SSL_CERT == type)
+               fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
+               CRYPTO_thread_id(),
+               mode,file,line);
+*/
+       if (mode & CRYPTO_LOCK)
+               {
+               pthread_mutex_lock(&(lock_cs[type]));
+               lock_count[type]++;
+               }
+       else
+               {
+               pthread_mutex_unlock(&(lock_cs[type]));
+               }
+       }
+
+void do_threads(s_ctx,c_ctx)
+SSL_CTX *s_ctx,*c_ctx;
+       {
+       SSL_CTX *ssl_ctx[2];
+       pthread_t thread_ctx[MAX_THREAD_NUMBER];
+       int i;
+
+       ssl_ctx[0]=s_ctx;
+       ssl_ctx[1]=c_ctx;
+
+       /*
+       thr_setconcurrency(thread_number);
+       */
+       for (i=0; i<thread_number; i++)
+               {
+               pthread_create(&(thread_ctx[i]), NULL,
+                       (void *(*)())ndoit, (void *)ssl_ctx);
+               }
+
+       printf("reaping\n");
+       for (i=0; i<thread_number; i++)
+               {
+               pthread_join(thread_ctx[i],NULL);
+               }
+
+       printf("pthreads threads done (%d,%d)\n",
+       s_ctx->references,c_ctx->references);
+       }
+
+unsigned long pthreads_thread_id()
+       {
+       unsigned long ret;
+
+       ret=(unsigned long)pthread_self();
+       return(ret);
+       }
+
+#endif /* PTHREADS */
+
+