summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/threads/mttest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/threads/mttest.c')
-rw-r--r--src/lib/libcrypto/threads/mttest.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c
index f6f3df4b6a..eba7aa8a6e 100644
--- a/src/lib/libcrypto/threads/mttest.c
+++ b/src/lib/libcrypto/threads/mttest.c
@@ -117,11 +117,13 @@ void solaris_locking_callback(int mode,int type,char *file,int line);
117void win32_locking_callback(int mode,int type,char *file,int line); 117void win32_locking_callback(int mode,int type,char *file,int line);
118void pthreads_locking_callback(int mode,int type,char *file,int line); 118void pthreads_locking_callback(int mode,int type,char *file,int line);
119void netware_locking_callback(int mode,int type,char *file,int line); 119void netware_locking_callback(int mode,int type,char *file,int line);
120void beos_locking_callback(int mode,int type,const char *file,int line);
120 121
121unsigned long irix_thread_id(void ); 122unsigned long irix_thread_id(void );
122unsigned long solaris_thread_id(void ); 123unsigned long solaris_thread_id(void );
123unsigned long pthreads_thread_id(void ); 124unsigned long pthreads_thread_id(void );
124unsigned long netware_thread_id(void ); 125unsigned long netware_thread_id(void );
126unsigned long beos_thread_id(void );
125 127
126#if defined(OPENSSL_SYS_NETWARE) 128#if defined(OPENSSL_SYS_NETWARE)
127static MPKMutex *lock_cs; 129static MPKMutex *lock_cs;
@@ -1209,3 +1211,100 @@ unsigned long netware_thread_id(void)
1209 return(ret); 1211 return(ret);
1210} 1212}
1211#endif /* NETWARE */ 1213#endif /* NETWARE */
1214
1215#ifdef BEOS_THREADS
1216
1217#include <Locker.h>
1218
1219static BLocker** lock_cs;
1220static long* lock_count;
1221
1222void thread_setup(void)
1223 {
1224 int i;
1225
1226 lock_cs=(BLocker**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(BLocker*));
1227 lock_count=(long*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
1228 for (i=0; i<CRYPTO_num_locks(); i++)
1229 {
1230 lock_count[i]=0;
1231 lock_cs[i] = new BLocker(CRYPTO_get_lock_name(i));
1232 }
1233
1234 CRYPTO_set_id_callback((unsigned long (*)())beos_thread_id);
1235 CRYPTO_set_locking_callback(beos_locking_callback);
1236 }
1237
1238void thread_cleanup(void)
1239 {
1240 int i;
1241
1242 CRYPTO_set_locking_callback(NULL);
1243 fprintf(stderr,"cleanup\n");
1244 for (i=0; i<CRYPTO_num_locks(); i++)
1245 {
1246 delete lock_cs[i];
1247 fprintf(stderr,"%8ld:%s\n",lock_count[i],
1248 CRYPTO_get_lock_name(i));
1249 }
1250 OPENSSL_free(lock_cs);
1251 OPENSSL_free(lock_count);
1252
1253 fprintf(stderr,"done cleanup\n");
1254 }
1255
1256void beos_locking_callback(int mode, int type, const char *file, int line)
1257 {
1258#if 0
1259 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
1260 CRYPTO_thread_id(),
1261 (mode&CRYPTO_LOCK)?"l":"u",
1262 (type&CRYPTO_READ)?"r":"w",file,line);
1263#endif
1264 if (mode & CRYPTO_LOCK)
1265 {
1266 lock_cs[type]->Lock();
1267 lock_count[type]++;
1268 }
1269 else
1270 {
1271 lock_cs[type]->Unlock();
1272 }
1273 }
1274
1275void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
1276 {
1277 SSL_CTX *ssl_ctx[2];
1278 thread_id thread_ctx[MAX_THREAD_NUMBER];
1279 int i;
1280
1281 ssl_ctx[0]=s_ctx;
1282 ssl_ctx[1]=c_ctx;
1283
1284 for (i=0; i<thread_number; i++)
1285 {
1286 thread_ctx[i] = spawn_thread((thread_func)ndoit,
1287 NULL, B_NORMAL_PRIORITY, (void *)ssl_ctx);
1288 resume_thread(thread_ctx[i]);
1289 }
1290
1291 printf("waiting...\n");
1292 for (i=0; i<thread_number; i++)
1293 {
1294 status_t result;
1295 wait_for_thread(thread_ctx[i], &result);
1296 }
1297
1298 printf("beos threads done (%d,%d)\n",
1299 s_ctx->references,c_ctx->references);
1300 }
1301
1302unsigned long beos_thread_id(void)
1303 {
1304 unsigned long ret;
1305
1306 ret=(unsigned long)find_thread(NULL);
1307 return(ret);
1308 }
1309
1310#endif /* BEOS_THREADS */