Cleanup mttest.c : modernise the threads setup
Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
parent
a3f9286556
commit
5c78e18352
1 changed files with 41 additions and 50 deletions
|
@ -111,18 +111,18 @@ 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 pthreads_locking_callback(int mode, int type, char *file, int line);
|
||||
void netware_locking_callback(int mode, int type, char *file, int line);
|
||||
void irix_locking_callback(int mode, int type, const char *file, int line);
|
||||
void solaris_locking_callback(int mode, int type, const char *file, int line);
|
||||
void win32_locking_callback(int mode, int type, const char *file, int line);
|
||||
void pthreads_locking_callback(int mode, int type, const char *file, int line);
|
||||
void netware_locking_callback(int mode, int type, const char *file, int line);
|
||||
void beos_locking_callback(int mode, int type, const 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);
|
||||
unsigned long beos_thread_id(void);
|
||||
void irix_thread_id(CRYPTO_THREADID *tid);
|
||||
void solaris_thread_id(CRYPTO_THREADID *tid);
|
||||
void pthreads_thread_id(CRYPTO_THREADID *tid);
|
||||
void netware_thread_id(CRYPTO_THREADID *tid);
|
||||
void beos_thread_id(CRYPTO_THREADID *tid);
|
||||
|
||||
#if defined(OPENSSL_SYS_NETWARE)
|
||||
static MPKMutex *lock_cs;
|
||||
|
@ -352,6 +352,7 @@ int ndoit(SSL_CTX *ssl_ctx[2])
|
|||
int i;
|
||||
int ret;
|
||||
char *ctx[4];
|
||||
CRYPTO_THREADID thread_id;
|
||||
|
||||
ctx[0] = (char *)ssl_ctx[0];
|
||||
ctx[1] = (char *)ssl_ctx[1];
|
||||
|
@ -364,22 +365,24 @@ int ndoit(SSL_CTX *ssl_ctx[2])
|
|||
ctx[3] = NULL;
|
||||
}
|
||||
|
||||
fprintf(stdout, "started thread %lu\n", CRYPTO_thread_id());
|
||||
CRYPTO_THREADID_current(&thread_id);
|
||||
BIO_printf(bio_stdout, "started thread %lu\n",
|
||||
CRYPTO_THREADID_hash(&thread_id));
|
||||
for (i = 0; i < number_of_loops; i++) {
|
||||
/*- fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n",
|
||||
CRYPTO_thread_id(),i,
|
||||
ssl_ctx[0]->references,
|
||||
ssl_ctx[1]->references); */
|
||||
/* pthread_delay_np(&tm); */
|
||||
/*- BIO_printf(bio_err,"%4d %2d ctx->ref (%3d,%3d)\n",
|
||||
CRYPTO_THREADID_hash(&thread_id),i,
|
||||
ssl_ctx[0]->references,
|
||||
ssl_ctx[1]->references); */
|
||||
/* pthread_delay_np(&tm); */
|
||||
|
||||
ret = doit(ctx);
|
||||
if (ret != 0) {
|
||||
fprintf(stdout, "error[%d] %lu - %d\n",
|
||||
i, CRYPTO_thread_id(), ret);
|
||||
BIO_printf(bio_stdout, "error[%d] %lu - %d\n",
|
||||
i, CRYPTO_THREADID_hash(&thread_id), ret);
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "DONE %lu\n", CRYPTO_thread_id());
|
||||
BIO_printf(bio_stdout, "DONE %lu\n", CRYPTO_THREADID_hash(&thread_id));
|
||||
if (reconnect) {
|
||||
SSL_free((SSL *)ctx[2]);
|
||||
SSL_free((SSL *)ctx[3]);
|
||||
|
@ -668,7 +671,7 @@ void thread_cleanup(void)
|
|||
OPENSSL_free(lock_cs);
|
||||
}
|
||||
|
||||
void win32_locking_callback(int mode, int type, char *file, int line)
|
||||
void win32_locking_callback(int mode, int type, const char *file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
WaitForSingleObject(lock_cs[type], INFINITE);
|
||||
|
@ -748,8 +751,8 @@ void thread_setup(void)
|
|||
mutex_init(&(lock_cs[i]), USYNC_THREAD, NULL);
|
||||
}
|
||||
|
||||
CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
|
||||
CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
|
||||
CRYPTO_set_id_callback(solaris_thread_id);
|
||||
CRYPTO_set_locking_callback(solaris_locking_callback);
|
||||
}
|
||||
|
||||
void thread_cleanup(void)
|
||||
|
@ -772,7 +775,7 @@ void thread_cleanup(void)
|
|||
|
||||
}
|
||||
|
||||
void solaris_locking_callback(int mode, int type, char *file, int line)
|
||||
void solaris_locking_callback(int mode, int type, const char *file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
mutex_lock(&(lock_cs[type]));
|
||||
|
@ -806,12 +809,9 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
|
|||
s_ctx->references, c_ctx->references);
|
||||
}
|
||||
|
||||
unsigned long solaris_thread_id(void)
|
||||
void solaris_thread_id(CRYPTO_THREADID *tid)
|
||||
{
|
||||
unsigned long ret;
|
||||
|
||||
ret = (unsigned long)thr_self();
|
||||
return (ret);
|
||||
CRYPTO_THREADID_set_numeric((unsigned long)thr_self());
|
||||
}
|
||||
#endif /* SOLARIS */
|
||||
|
||||
|
@ -840,8 +840,8 @@ void thread_setup(void)
|
|||
lock_cs[i] = usnewsema(arena, 1);
|
||||
}
|
||||
|
||||
CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
|
||||
CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
|
||||
CRYPTO_set_id_callback(irix_thread_id);
|
||||
CRYPTO_set_locking_callback(irix_locking_callback);
|
||||
}
|
||||
|
||||
void thread_cleanup(void)
|
||||
|
@ -859,7 +859,7 @@ void thread_cleanup(void)
|
|||
OPENSSL_free(lock_cs);
|
||||
}
|
||||
|
||||
void irix_locking_callback(int mode, int type, char *file, int line)
|
||||
void irix_locking_callback(int mode, int type, const char *file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
printf("lock %d\n", type);
|
||||
|
@ -895,10 +895,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
|
|||
|
||||
unsigned long irix_thread_id(void)
|
||||
{
|
||||
unsigned long ret;
|
||||
|
||||
ret = (unsigned long)getpid();
|
||||
return (ret);
|
||||
CRYPTO_THREADID_set_numeric((unsigned long)getpid());
|
||||
}
|
||||
#endif /* IRIX */
|
||||
|
||||
|
@ -918,8 +915,8 @@ void thread_setup(void)
|
|||
pthread_mutex_init(&(lock_cs[i]), NULL);
|
||||
}
|
||||
|
||||
CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
|
||||
CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
|
||||
CRYPTO_THREADID_set_callback(pthreads_thread_id);
|
||||
CRYPTO_set_locking_callback(pthreads_locking_callback);
|
||||
}
|
||||
|
||||
void thread_cleanup(void)
|
||||
|
@ -938,7 +935,7 @@ void thread_cleanup(void)
|
|||
fprintf(stderr, "done cleanup\n");
|
||||
}
|
||||
|
||||
void pthreads_locking_callback(int mode, int type, char *file, int line)
|
||||
void pthreads_locking_callback(int mode, int type, const char *file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
pthread_mutex_lock(&(lock_cs[type]));
|
||||
|
@ -974,12 +971,9 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
|
|||
s_ctx->references, c_ctx->references);
|
||||
}
|
||||
|
||||
unsigned long pthreads_thread_id(void)
|
||||
void pthreads_thread_id(CRYPTO_THREADID *tid)
|
||||
{
|
||||
unsigned long ret;
|
||||
|
||||
ret = (unsigned long)pthread_self();
|
||||
return (ret);
|
||||
CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
|
||||
}
|
||||
|
||||
#endif /* PTHREADS */
|
||||
|
@ -999,8 +993,8 @@ void thread_setup(void)
|
|||
|
||||
ThreadSem = MPKSemaphoreAlloc("OpenSSL mttest semaphore", 0);
|
||||
|
||||
CRYPTO_set_id_callback((unsigned long (*)())netware_thread_id);
|
||||
CRYPTO_set_locking_callback((void (*)())netware_locking_callback);
|
||||
CRYPTO_set_id_callback(netware_thread_id);
|
||||
CRYPTO_set_locking_callback(netware_locking_callback);
|
||||
}
|
||||
|
||||
void thread_cleanup(void)
|
||||
|
@ -1023,7 +1017,7 @@ void thread_cleanup(void)
|
|||
fprintf(stdout, "done cleanup\n");
|
||||
}
|
||||
|
||||
void netware_locking_callback(int mode, int type, char *file, int line)
|
||||
void netware_locking_callback(int mode, int type, const char *file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK) {
|
||||
MPKMutexLock(lock_cs[type]);
|
||||
|
@ -1057,9 +1051,6 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
|
|||
|
||||
unsigned long netware_thread_id(void)
|
||||
{
|
||||
unsigned long ret;
|
||||
|
||||
ret = (unsigned long)GetThreadID();
|
||||
return (ret);
|
||||
CRYPTO_THREADID_set_numeric((unsigned long)GetThreadID());
|
||||
}
|
||||
#endif /* NETWARE */
|
||||
|
|
Loading…
Reference in a new issue