Peer review cleanups.

pull/5430/head
David Garske 2022-12-14 09:25:04 -08:00
parent e33d59cd76
commit 6be0512728
3 changed files with 43 additions and 33 deletions

View File

@ -600,18 +600,21 @@ typedef struct {
} wm_Sem;
/* Posix style semaphore */
static int wm_SemInit(wm_Sem *s){
static int wm_SemInit(wm_Sem *s)
{
s->lockCount = 0;
pthread_mutex_init(&s->mutex, NULL);
pthread_cond_init(&s->cond, NULL);
return 0;
}
static int wm_SemFree(wm_Sem *s){
static int wm_SemFree(wm_Sem *s)
{
pthread_mutex_destroy(&s->mutex);
pthread_cond_destroy(&s->cond);
return 0;
}
static int wm_SemLock(wm_Sem *s){
static int wm_SemLock(wm_Sem *s)
{
pthread_mutex_lock(&s->mutex);
while (s->lockCount > 0)
pthread_cond_wait(&s->cond, &s->mutex);
@ -619,7 +622,8 @@ static int wm_SemLock(wm_Sem *s){
pthread_mutex_unlock(&s->mutex);
return 0;
}
static int wm_SemUnlock(wm_Sem *s){
static int wm_SemUnlock(wm_Sem *s)
{
pthread_mutex_lock(&s->mutex);
s->lockCount--;
pthread_cond_signal(&s->cond);

View File

@ -291,37 +291,43 @@ typedef struct wolfSSL_Ref {
} wolfSSL_Ref;
#ifdef SINGLE_THREADED
#define wolfSSL_RefInit(ref, err) do { \
#define wolfSSL_RefInit(ref, err) \
do { \
(ref)->count = 1; \
*(err) = 0; \
} while(0);
} while(0)
#define wolfSSL_RefFree(ref)
#define wolfSSL_RefInc(ref, err) do { \
#define wolfSSL_RefInc(ref, err) \
do { \
(ref)->count++; \
*(err) = 0; \
} while(0);
#define wolfSSL_RefDec(ref, isZero, err) do { \
} while(0)
#define wolfSSL_RefDec(ref, isZero, err) \
do { \
(ref)->count--; \
*(isZero) = ((ref)->count == 0); \
*(err) = 0; \
} while(0);
} while(0)
#elif defined(HAVE_C___ATOMIC)
#define wolfSSL_RefInit(ref, err) do { \
#define wolfSSL_RefInit(ref, err) \
do { \
(ref)->count = 1; \
*(err) = 0; \
} while(0);
} while(0)
#define wolfSSL_RefFree(ref)
#define wolfSSL_RefInc(ref, err) do { \
#define wolfSSL_RefInc(ref, err) \
do { \
__atomic_fetch_add(&(ref)->count, 1, \
__ATOMIC_RELAXED); \
*(err) = 0; \
} while(0);
#define wolfSSL_RefDec(ref, isZero, err) do { \
} while(0)
#define wolfSSL_RefDec(ref, isZero, err) \
do { \
__atomic_fetch_sub(&(ref)->count, 1, \
__ATOMIC_RELAXED); \
*(isZero) = ((ref)->count == 0); \
*(err) = 0; \
} while(0);
} while(0)
#else
WOLFSSL_LOCAL void wolfSSL_RefInit(wolfSSL_Ref* ref, int* err);
WOLFSSL_LOCAL void wolfSSL_RefFree(wolfSSL_Ref* ref);