mirror of https://github.com/wolfSSL/wolfssl.git
Make sure no mutexes are held when cond API are called
parent
7ba00f3b84
commit
d747df2ae4
|
@ -416,9 +416,9 @@ static int ServerMemSend(info_t* info, char* buf, int sz)
|
||||||
XMEMCPY(&info->to_client.buf[info->to_client.write_idx], buf, sz);
|
XMEMCPY(&info->to_client.buf[info->to_client.write_idx], buf, sz);
|
||||||
info->to_client.write_idx += sz;
|
info->to_client.write_idx += sz;
|
||||||
info->to_client.write_bytes += sz;
|
info->to_client.write_bytes += sz;
|
||||||
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_client.mutex));
|
||||||
|
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
|
||||||
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_client.mutex));
|
|
||||||
|
|
||||||
#ifdef BENCH_USE_NONBLOCK
|
#ifdef BENCH_USE_NONBLOCK
|
||||||
if (sz == 0) {
|
if (sz == 0) {
|
||||||
|
@ -436,7 +436,9 @@ static int ServerMemRecv(info_t* info, char* buf, int sz)
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
while (info->to_server.write_idx - info->to_server.read_idx < sz &&
|
while (info->to_server.write_idx - info->to_server.read_idx < sz &&
|
||||||
!info->to_client.done) {
|
!info->to_client.done) {
|
||||||
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_server.mutex));
|
||||||
THREAD_CHECK_RET(wolfSSL_CondWait(&info->to_server.cond));
|
THREAD_CHECK_RET(wolfSSL_CondWait(&info->to_server.cond));
|
||||||
|
THREAD_CHECK_RET(wc_LockMutex(&info->to_server.mutex));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (info->to_server.write_idx - info->to_server.read_idx < sz) {
|
if (info->to_server.write_idx - info->to_server.read_idx < sz) {
|
||||||
|
@ -491,8 +493,8 @@ static int ClientMemSend(info_t* info, char* buf, int sz)
|
||||||
info->to_server.write_idx += sz;
|
info->to_server.write_idx += sz;
|
||||||
info->to_server.write_bytes += sz;
|
info->to_server.write_bytes += sz;
|
||||||
|
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
|
|
||||||
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_server.mutex));
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_server.mutex));
|
||||||
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
|
||||||
|
|
||||||
#ifdef BENCH_USE_NONBLOCK
|
#ifdef BENCH_USE_NONBLOCK
|
||||||
if (sz == 0) {
|
if (sz == 0) {
|
||||||
|
@ -510,7 +512,9 @@ static int ClientMemRecv(info_t* info, char* buf, int sz)
|
||||||
#ifndef BENCH_USE_NONBLOCK
|
#ifndef BENCH_USE_NONBLOCK
|
||||||
while (info->to_client.write_idx - info->to_client.read_idx < sz &&
|
while (info->to_client.write_idx - info->to_client.read_idx < sz &&
|
||||||
!info->to_server.done) {
|
!info->to_server.done) {
|
||||||
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->to_client.mutex));
|
||||||
THREAD_CHECK_RET(wolfSSL_CondWait(&info->to_client.cond));
|
THREAD_CHECK_RET(wolfSSL_CondWait(&info->to_client.cond));
|
||||||
|
THREAD_CHECK_RET(wc_LockMutex(&info->to_client.mutex));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (info->to_client.write_idx - info->to_client.read_idx < sz) {
|
if (info->to_client.write_idx - info->to_client.read_idx < sz) {
|
||||||
|
@ -1052,7 +1056,9 @@ static int bench_tls_client(info_t* info)
|
||||||
if (info->doDTLS && !info->clientOrserverOnly) {
|
if (info->doDTLS && !info->clientOrserverOnly) {
|
||||||
THREAD_CHECK_RET(wc_LockMutex(&info->dtls_mutex));
|
THREAD_CHECK_RET(wc_LockMutex(&info->dtls_mutex));
|
||||||
if (info->serverReady != 1) {
|
if (info->serverReady != 1) {
|
||||||
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->dtls_mutex));
|
||||||
THREAD_CHECK_RET(wolfSSL_CondWait(&info->dtls_cond));
|
THREAD_CHECK_RET(wolfSSL_CondWait(&info->dtls_cond));
|
||||||
|
THREAD_CHECK_RET(wc_LockMutex(&info->dtls_mutex));
|
||||||
}
|
}
|
||||||
/* for next loop */
|
/* for next loop */
|
||||||
info->serverReady = 0;
|
info->serverReady = 0;
|
||||||
|
@ -1198,9 +1204,9 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
|
||||||
|
|
||||||
ret = bench_tls_client(info);
|
ret = bench_tls_client(info);
|
||||||
|
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
|
|
||||||
info->to_client.done = 1;
|
info->to_client.done = 1;
|
||||||
info->client.ret = ret;
|
info->client.ret = ret;
|
||||||
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
|
||||||
|
|
||||||
WOLFSSL_RETURN_FROM_THREAD(NULL);
|
WOLFSSL_RETURN_FROM_THREAD(NULL);
|
||||||
}
|
}
|
||||||
|
@ -1288,8 +1294,8 @@ static int SocketWaitClient(info_t* info)
|
||||||
if (!info->clientOrserverOnly) {
|
if (!info->clientOrserverOnly) {
|
||||||
THREAD_CHECK_RET(wc_LockMutex(&info->dtls_mutex));
|
THREAD_CHECK_RET(wc_LockMutex(&info->dtls_mutex));
|
||||||
info->serverReady = 1;
|
info->serverReady = 1;
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->dtls_cond));
|
|
||||||
THREAD_CHECK_RET(wc_UnLockMutex(&info->dtls_mutex));
|
THREAD_CHECK_RET(wc_UnLockMutex(&info->dtls_mutex));
|
||||||
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->dtls_cond));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
connd = (int)recvfrom(info->listenFd, (char *)msg, sizeof(msg),
|
connd = (int)recvfrom(info->listenFd, (char *)msg, sizeof(msg),
|
||||||
|
@ -1656,9 +1662,9 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
|
|
||||||
info->to_server.done = 1;
|
info->to_server.done = 1;
|
||||||
info->server.ret = ret;
|
info->server.ret = ret;
|
||||||
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
|
||||||
|
|
||||||
WOLFSSL_RETURN_FROM_THREAD(NULL);
|
WOLFSSL_RETURN_FROM_THREAD(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,8 @@ static void SignalReady(void* args, word16 port)
|
||||||
THREAD_CHECK_RET(wc_LockMutex(&ready->mutex));
|
THREAD_CHECK_RET(wc_LockMutex(&ready->mutex));
|
||||||
ready->ready = 1;
|
ready->ready = 1;
|
||||||
ready->port = port;
|
ready->port = port;
|
||||||
THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
|
|
||||||
THREAD_CHECK_RET(wc_UnLockMutex(&ready->mutex));
|
THREAD_CHECK_RET(wc_UnLockMutex(&ready->mutex));
|
||||||
|
THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
|
||||||
#endif /* NO_MAIN_DRIVER && WOLFSSL_COND */
|
#endif /* NO_MAIN_DRIVER && WOLFSSL_COND */
|
||||||
(void)args;
|
(void)args;
|
||||||
(void)port;
|
(void)port;
|
||||||
|
|
20
src/crl.c
20
src/crl.c
|
@ -936,7 +936,10 @@ static int SignalSetup(WOLFSSL_CRL* crl, int status)
|
||||||
return BAD_MUTEX_E;
|
return BAD_MUTEX_E;
|
||||||
}
|
}
|
||||||
crl->setup = status;
|
crl->setup = status;
|
||||||
wc_UnLockMutex(&crl->crlLock);
|
if (wc_UnLockMutex(&crl->crlLock) != 0) {
|
||||||
|
WOLFSSL_MSG("wc_UnLockMutex crlLock failed");
|
||||||
|
return BAD_MUTEX_E;
|
||||||
|
}
|
||||||
|
|
||||||
ret = wolfSSL_CondSignal(&crl->cond);
|
ret = wolfSSL_CondSignal(&crl->cond);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
|
@ -1492,9 +1495,15 @@ static int StartMonitorCRL(WOLFSSL_CRL* crl)
|
||||||
}
|
}
|
||||||
while (crl->setup == 0) {
|
while (crl->setup == 0) {
|
||||||
int condRet;
|
int condRet;
|
||||||
wc_UnLockMutex(&crl->crlLock);
|
if (wc_UnLockMutex(&crl->crlLock) != 0) {
|
||||||
|
WOLFSSL_MSG("wc_UnLockMutex crlLock failed");
|
||||||
|
return BAD_MUTEX_E;
|
||||||
|
}
|
||||||
condRet = wolfSSL_CondWait(&crl->cond);
|
condRet = wolfSSL_CondWait(&crl->cond);
|
||||||
wc_LockMutex(&crl->crlLock);
|
if (wc_LockMutex(&crl->crlLock) != 0) {
|
||||||
|
WOLFSSL_MSG("wc_LockMutex crlLock failed");
|
||||||
|
return BAD_MUTEX_E;
|
||||||
|
}
|
||||||
if (condRet != 0) {
|
if (condRet != 0) {
|
||||||
ret = BAD_COND_E;
|
ret = BAD_COND_E;
|
||||||
break;
|
break;
|
||||||
|
@ -1502,12 +1511,15 @@ static int StartMonitorCRL(WOLFSSL_CRL* crl)
|
||||||
}
|
}
|
||||||
if (ret >= 0 && crl->setup < 0)
|
if (ret >= 0 && crl->setup < 0)
|
||||||
ret = crl->setup; /* store setup error */
|
ret = crl->setup; /* store setup error */
|
||||||
wc_UnLockMutex(&crl->crlLock);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
WOLFSSL_MSG("DoMonitor setup failure");
|
WOLFSSL_MSG("DoMonitor setup failure");
|
||||||
crl->tid = INVALID_THREAD_VAL; /* thread already done */
|
crl->tid = INVALID_THREAD_VAL; /* thread already done */
|
||||||
}
|
}
|
||||||
|
if (wc_UnLockMutex(&crl->crlLock) != 0) {
|
||||||
|
WOLFSSL_MSG("wc_UnLockMutex crlLock failed");
|
||||||
|
return BAD_MUTEX_E;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3704,12 +3704,14 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
|
||||||
|
|
||||||
if (pthread_mutex_init(&cond->mutex, NULL) != 0)
|
if (pthread_mutex_init(&cond->mutex, NULL) != 0)
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
|
|
||||||
if (pthread_cond_init(&cond->cond, NULL) != 0) {
|
if (pthread_cond_init(&cond->cond, NULL) != 0) {
|
||||||
/* Keep compilers happy that we are using the return code */
|
/* Keep compilers happy that we are using the return code */
|
||||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3722,6 +3724,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
|
||||||
|
|
||||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||||
ret = MEMORY_E;
|
ret = MEMORY_E;
|
||||||
|
|
||||||
if (pthread_cond_destroy(&cond->cond) != 0)
|
if (pthread_cond_destroy(&cond->cond) != 0)
|
||||||
ret = MEMORY_E;
|
ret = MEMORY_E;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue