diff options
author | Richard Levitte <levitte@openssl.org> | 2003-11-28 13:10:58 +0000 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2003-11-28 13:10:58 +0000 |
commit | 4d8743f490a5f96fa26d41985ee12cb6b9815a4c (patch) | |
tree | 9668a30c8c9bcc3347eddb5b553d8f1c6ccc8524 /crypto/threads | |
parent | 4c8b4f9d03fb5db99fa22b235369b96039f60706 (diff) |
Netware-specific changes,
PR: 780
Submitted by: Verdon Walker <VWalker@novell.com>
Reviewed by: Richard Levitte
Diffstat (limited to 'crypto/threads')
-rw-r--r-- | crypto/threads/mttest.c | 115 | ||||
-rw-r--r-- | crypto/threads/netware.bat | 79 |
2 files changed, 194 insertions, 0 deletions
diff --git a/crypto/threads/mttest.c b/crypto/threads/mttest.c index 54d598565d..d0e088218b 100644 --- a/crypto/threads/mttest.c +++ b/crypto/threads/mttest.c @@ -77,6 +77,12 @@ #ifdef PTHREADS #include <pthread.h> #endif +#ifdef OPENSSL_SYS_NETWARE +#if !defined __int64 +# define __int64 long long +#endif +#include <nwmpk.h> +#endif #include <openssl/lhash.h> #include <openssl/crypto.h> #include <openssl/buffer.h> @@ -86,8 +92,18 @@ #include <openssl/err.h> #include <openssl/rand.h> +#ifdef OPENSSL_NO_FP_API +#define APPS_WIN16 +#include "../buffer/bss_file.c" +#endif + +#ifdef OPENSSL_SYS_NETWARE +#define TEST_SERVER_CERT "/openssl/apps/server.pem" +#define TEST_CLIENT_CERT "/openssl/apps/client.pem" +#else #define TEST_SERVER_CERT "../../apps/server.pem" #define TEST_CLIENT_CERT "../../apps/client.pem" +#endif #define MAX_THREAD_NUMBER 100 @@ -100,10 +116,18 @@ 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 pthreads_locking_callback(int mode,int type,char *file,int line); +void netware_locking_callback(int mode,int type,char *file,int line); unsigned long irix_thread_id(void ); unsigned long solaris_thread_id(void ); unsigned long pthreads_thread_id(void ); +unsigned long netware_thread_id(void ); + +#if defined(OPENSSL_SYS_NETWARE) +static MPKMutex *lock_cs; +static MPKSema ThreadSem; +static long *lock_count; +#endif BIO *bio_err=NULL; BIO *bio_stdout=NULL; @@ -383,6 +407,9 @@ int ndoit(SSL_CTX *ssl_ctx[2]) SSL_free((SSL *)ctx[2]); SSL_free((SSL *)ctx[3]); } +# ifdef OPENSSL_SYS_NETWARE + MPKSemaphoreSignal(ThreadSem); +# endif return(0); } @@ -626,6 +653,9 @@ int doit(char *ctx[4]) } if ((done & S_DONE) && (done & C_DONE)) break; +# if defined(OPENSSL_SYS_NETWARE) + ThreadSwitchWithDelay(); +# endif } SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); @@ -1093,3 +1123,88 @@ unsigned long pthreads_thread_id(void) +#ifdef OPENSSL_SYS_NETWARE + +void thread_setup(void) +{ + int i; + + lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(MPKMutex)); + lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); + for (i=0; i<CRYPTO_num_locks(); i++) + { + lock_count[i]=0; + lock_cs[i]=MPKMutexAlloc("OpenSSL mutex"); + } + + ThreadSem = MPKSemaphoreAlloc("OpenSSL mttest semaphore", 0 ); + + CRYPTO_set_id_callback((unsigned long (*)())netware_thread_id); + CRYPTO_set_locking_callback((void (*)())netware_locking_callback); +} + +void thread_cleanup(void) +{ + int i; + + CRYPTO_set_locking_callback(NULL); + + fprintf(stdout,"thread_cleanup\n"); + + for (i=0; i<CRYPTO_num_locks(); i++) + { + MPKMutexFree(lock_cs[i]); + fprintf(stdout,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); + } + OPENSSL_free(lock_cs); + OPENSSL_free(lock_count); + + MPKSemaphoreFree(ThreadSem); + + fprintf(stdout,"done cleanup\n"); +} + +void netware_locking_callback(int mode, int type, char *file, int line) +{ + if (mode & CRYPTO_LOCK) + { + MPKMutexLock(lock_cs[type]); + lock_count[type]++; + } + else + MPKMutexUnlock(lock_cs[type]); +} + +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) +{ + SSL_CTX *ssl_ctx[2]; + int i; + ssl_ctx[0]=s_ctx; + ssl_ctx[1]=c_ctx; + + for (i=0; i<thread_number; i++) + { + BeginThread( (void(*)(void*))ndoit, NULL, THREAD_STACK_SIZE, + (void*)ssl_ctx); + ThreadSwitchWithDelay(); + } + + printf("reaping\n"); + + /* loop until all threads have signaled the semaphore */ + for (i=0; i<thread_number; i++) + { + MPKSemaphoreWait(ThreadSem); + } + printf("netware threads done (%d,%d)\n", + s_ctx->references,c_ctx->references); +} + +unsigned long netware_thread_id(void) +{ + unsigned long ret; + + ret=(unsigned long)GetThreadID(); + return(ret); +} +#endif /* NETWARE */ diff --git a/crypto/threads/netware.bat b/crypto/threads/netware.bat new file mode 100644 index 0000000000..0b3eca3caf --- /dev/null +++ b/crypto/threads/netware.bat @@ -0,0 +1,79 @@ +@echo off +rem batch file to build multi-thread test ( mttest.nlm ) + +rem command line arguments: +rem debug => build using debug settings + +rem +rem After building, copy mttest.nlm to the server and run it, you'll probably +rem want to redirect stdout and stderr. An example command line would be +rem "mttest.nlm -thread 20 -loops 10 -CAfile \openssl\apps\server.pem >mttest.out 2>mttest.err" +rem + +del mttest.nlm + +set BLD_DEBUG= +set CFLAGS= +set LFLAGS= +set LIBS= + +if "%1" == "DEBUG" set BLD_DEBUG=YES +if "%1" == "debug" set BLD_DEBUG=YES + +if "%MWCIncludes%" == "" goto inc_error +if "%PRELUDE%" == "" goto prelude_error +if "%IMPORTS%" == "" goto imports_error + +set CFLAGS=-c -I..\..\outinc_nw -nosyspath -DOPENSSL_SYS_NETWARE -opt off -g -sym internal -maxerrors 20 + +if "%BLD_DEBUG%" == "YES" set LIBS=..\..\out_nw.dbg\ssl.lib ..\..\out_nw.dbg\crypto.lib +if "%BLD_DEBUG%" == "" set LIBS=..\..\out_nw\ssl.lib ..\..\out_nw\crypto.lib + +set LFLAGS=-msgstyle gcc -zerobss -stacksize 32768 -nostdlib -sym internal + +rem generate command file for metrowerks +echo. +echo Generating Metrowerks command file: mttest.def +echo # dynamically generated command file for metrowerks build > mttest.def +echo IMPORT @%IMPORTS%\clib.imp >> mttest.def +echo IMPORT @%IMPORTS%\threads.imp >> mttest.def +echo IMPORT @%IMPORTS%\ws2nlm.imp >> mttest.def +echo IMPORT GetProcessSwitchCount >> mttest.def +echo MODULE clib >> mttest.def + +rem compile +echo. +echo Compiling mttest.c +mwccnlm.exe mttest.c %CFLAGS% +if errorlevel 1 goto end + +rem link +echo. +echo Linking mttest.nlm +mwldnlm.exe %LFLAGS% -screenname mttest -commandfile mttest.def mttest.o "%PRELUDE%" %LIBS% -o mttest.nlm +if errorlevel 1 goto end + +goto end + +:inc_error +echo. +echo Environment variable MWCIncludes is not set - see install.nw +goto end + +:prelude_error +echo. +echo Environment variable PRELUDE is not set - see install.nw +goto end + +:imports_error +echo. +echo Environment variable IMPORTS is not set - see install.nw +goto end + + +:end +set BLD_DEBUG= +set CFLAGS= +set LFLAGS= +set LIBS= + |