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 thread_cleanup(void);
|
||||||
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx);
|
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx);
|
||||||
|
|
||||||
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);
|
||||||
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);
|
||||||
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);
|
||||||
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);
|
||||||
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);
|
||||||
void beos_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);
|
void irix_thread_id(CRYPTO_THREADID *tid);
|
||||||
unsigned long solaris_thread_id(void);
|
void solaris_thread_id(CRYPTO_THREADID *tid);
|
||||||
unsigned long pthreads_thread_id(void);
|
void pthreads_thread_id(CRYPTO_THREADID *tid);
|
||||||
unsigned long netware_thread_id(void);
|
void netware_thread_id(CRYPTO_THREADID *tid);
|
||||||
unsigned long beos_thread_id(void);
|
void beos_thread_id(CRYPTO_THREADID *tid);
|
||||||
|
|
||||||
#if defined(OPENSSL_SYS_NETWARE)
|
#if defined(OPENSSL_SYS_NETWARE)
|
||||||
static MPKMutex *lock_cs;
|
static MPKMutex *lock_cs;
|
||||||
|
@ -352,6 +352,7 @@ int ndoit(SSL_CTX *ssl_ctx[2])
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
char *ctx[4];
|
char *ctx[4];
|
||||||
|
CRYPTO_THREADID thread_id;
|
||||||
|
|
||||||
ctx[0] = (char *)ssl_ctx[0];
|
ctx[0] = (char *)ssl_ctx[0];
|
||||||
ctx[1] = (char *)ssl_ctx[1];
|
ctx[1] = (char *)ssl_ctx[1];
|
||||||
|
@ -364,22 +365,24 @@ int ndoit(SSL_CTX *ssl_ctx[2])
|
||||||
ctx[3] = NULL;
|
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++) {
|
for (i = 0; i < number_of_loops; i++) {
|
||||||
/*- fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n",
|
/*- BIO_printf(bio_err,"%4d %2d ctx->ref (%3d,%3d)\n",
|
||||||
CRYPTO_thread_id(),i,
|
CRYPTO_THREADID_hash(&thread_id),i,
|
||||||
ssl_ctx[0]->references,
|
ssl_ctx[0]->references,
|
||||||
ssl_ctx[1]->references); */
|
ssl_ctx[1]->references); */
|
||||||
/* pthread_delay_np(&tm); */
|
/* pthread_delay_np(&tm); */
|
||||||
|
|
||||||
ret = doit(ctx);
|
ret = doit(ctx);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stdout, "error[%d] %lu - %d\n",
|
BIO_printf(bio_stdout, "error[%d] %lu - %d\n",
|
||||||
i, CRYPTO_thread_id(), ret);
|
i, CRYPTO_THREADID_hash(&thread_id), ret);
|
||||||
return (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) {
|
if (reconnect) {
|
||||||
SSL_free((SSL *)ctx[2]);
|
SSL_free((SSL *)ctx[2]);
|
||||||
SSL_free((SSL *)ctx[3]);
|
SSL_free((SSL *)ctx[3]);
|
||||||
|
@ -668,7 +671,7 @@ void thread_cleanup(void)
|
||||||
OPENSSL_free(lock_cs);
|
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) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
WaitForSingleObject(lock_cs[type], INFINITE);
|
WaitForSingleObject(lock_cs[type], INFINITE);
|
||||||
|
@ -748,8 +751,8 @@ void thread_setup(void)
|
||||||
mutex_init(&(lock_cs[i]), USYNC_THREAD, NULL);
|
mutex_init(&(lock_cs[i]), USYNC_THREAD, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
|
CRYPTO_set_id_callback(solaris_thread_id);
|
||||||
CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
|
CRYPTO_set_locking_callback(solaris_locking_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_cleanup(void)
|
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) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
mutex_lock(&(lock_cs[type]));
|
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);
|
s_ctx->references, c_ctx->references);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long solaris_thread_id(void)
|
void solaris_thread_id(CRYPTO_THREADID *tid)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
CRYPTO_THREADID_set_numeric((unsigned long)thr_self());
|
||||||
|
|
||||||
ret = (unsigned long)thr_self();
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
#endif /* SOLARIS */
|
#endif /* SOLARIS */
|
||||||
|
|
||||||
|
@ -840,8 +840,8 @@ void thread_setup(void)
|
||||||
lock_cs[i] = usnewsema(arena, 1);
|
lock_cs[i] = usnewsema(arena, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
|
CRYPTO_set_id_callback(irix_thread_id);
|
||||||
CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
|
CRYPTO_set_locking_callback(irix_locking_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_cleanup(void)
|
void thread_cleanup(void)
|
||||||
|
@ -859,7 +859,7 @@ void thread_cleanup(void)
|
||||||
OPENSSL_free(lock_cs);
|
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) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
printf("lock %d\n", type);
|
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 irix_thread_id(void)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
CRYPTO_THREADID_set_numeric((unsigned long)getpid());
|
||||||
|
|
||||||
ret = (unsigned long)getpid();
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
#endif /* IRIX */
|
#endif /* IRIX */
|
||||||
|
|
||||||
|
@ -918,8 +915,8 @@ void thread_setup(void)
|
||||||
pthread_mutex_init(&(lock_cs[i]), NULL);
|
pthread_mutex_init(&(lock_cs[i]), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
|
CRYPTO_THREADID_set_callback(pthreads_thread_id);
|
||||||
CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
|
CRYPTO_set_locking_callback(pthreads_locking_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_cleanup(void)
|
void thread_cleanup(void)
|
||||||
|
@ -938,7 +935,7 @@ void thread_cleanup(void)
|
||||||
fprintf(stderr, "done cleanup\n");
|
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) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
pthread_mutex_lock(&(lock_cs[type]));
|
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);
|
s_ctx->references, c_ctx->references);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long pthreads_thread_id(void)
|
void pthreads_thread_id(CRYPTO_THREADID *tid)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
|
||||||
|
|
||||||
ret = (unsigned long)pthread_self();
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PTHREADS */
|
#endif /* PTHREADS */
|
||||||
|
@ -999,8 +993,8 @@ void thread_setup(void)
|
||||||
|
|
||||||
ThreadSem = MPKSemaphoreAlloc("OpenSSL mttest semaphore", 0);
|
ThreadSem = MPKSemaphoreAlloc("OpenSSL mttest semaphore", 0);
|
||||||
|
|
||||||
CRYPTO_set_id_callback((unsigned long (*)())netware_thread_id);
|
CRYPTO_set_id_callback(netware_thread_id);
|
||||||
CRYPTO_set_locking_callback((void (*)())netware_locking_callback);
|
CRYPTO_set_locking_callback(netware_locking_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread_cleanup(void)
|
void thread_cleanup(void)
|
||||||
|
@ -1023,7 +1017,7 @@ void thread_cleanup(void)
|
||||||
fprintf(stdout, "done cleanup\n");
|
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) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
MPKMutexLock(lock_cs[type]);
|
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 netware_thread_id(void)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
CRYPTO_THREADID_set_numeric((unsigned long)GetThreadID());
|
||||||
|
|
||||||
ret = (unsigned long)GetThreadID();
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
#endif /* NETWARE */
|
#endif /* NETWARE */
|
||||||
|
|
Loading…
Reference in a new issue