Skip to content

Commit 72a23a2

Browse files
committed
Allow Zephyr build w/o having posix api enabled
1 parent 3181e2b commit 72a23a2

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

wolfssl/wolfcrypt/mem_track.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ static memoryStats ourMemStats;
142142
WOLFSSL_API extern memoryStats *wc_MemStats_Ptr;
143143

144144
#ifdef DO_MEM_LIST
145-
#include <pthread.h>
146145
static memoryList ourMemList;
147-
static pthread_mutex_t memLock = PTHREAD_MUTEX_INITIALIZER;
146+
static wolfSSL_Mutex memLock WOLFSSL_MUTEX_INITIALIZER_CLAUSE(memLock);
148147
#endif
149148

150149
#ifdef WOLFSSL_DEBUG_MEMORY
@@ -182,7 +181,7 @@ static WC_INLINE void* TrackMalloc(size_t sz)
182181
#endif
183182
#endif
184183
#if !defined(SINGLE_THREADED) && (defined(DO_MEM_LIST) || defined(DO_MEM_STATS))
185-
if (pthread_mutex_lock(&memLock) == 0)
184+
if (wc_LockMutex(&memLock) == 0)
186185
{
187186
#endif
188187

@@ -228,7 +227,7 @@ static WC_INLINE void* TrackMalloc(size_t sz)
228227
ourMemList.count++;
229228
#endif
230229
#if !defined(SINGLE_THREADED) && (defined(DO_MEM_LIST) || defined(DO_MEM_STATS))
231-
pthread_mutex_unlock(&memLock);
230+
wc_UnLockMutex(&memLock);
232231
}
233232
#endif /* DO_MEM_LIST */
234233

@@ -255,7 +254,7 @@ static WC_INLINE void TrackFree(void* ptr)
255254
sz = header->thisSize;
256255

257256
#if !defined(SINGLE_THREADED) && (defined(DO_MEM_LIST) || defined(DO_MEM_STATS))
258-
if (pthread_mutex_lock(&memLock) == 0)
257+
if (wc_LockMutex(&memLock) == 0)
259258
{
260259
#endif
261260

@@ -289,7 +288,7 @@ static WC_INLINE void TrackFree(void* ptr)
289288
#endif
290289

291290
#if !defined(SINGLE_THREADED) && (defined(DO_MEM_LIST) || defined(DO_MEM_STATS))
292-
pthread_mutex_unlock(&memLock);
291+
wc_UnLockMutex(&memLock);
293292
}
294293
#endif
295294

@@ -369,7 +368,10 @@ static WC_INLINE int InitMemoryTracker(void)
369368
}
370369

371370
#ifdef DO_MEM_LIST
372-
if (pthread_mutex_lock(&memLock) == 0)
371+
#ifndef WOLFSSL_MUTEX_INITIALIZER
372+
wc_InitMutex(&memLock);
373+
#endif
374+
if (wc_LockMutex(&memLock) == 0)
373375
#endif
374376
{
375377
#ifdef DO_MEM_STATS
@@ -388,7 +390,7 @@ static WC_INLINE int InitMemoryTracker(void)
388390
XMEMSET(&ourMemList, 0, sizeof(ourMemList));
389391
ourMemStats.memList = &ourMemList;
390392

391-
pthread_mutex_unlock(&memLock);
393+
wc_UnLockMutex(&memLock);
392394
#endif
393395
}
394396

@@ -400,7 +402,7 @@ static WC_INLINE int InitMemoryTracker(void)
400402
static WC_INLINE void ShowMemoryTracker(void)
401403
{
402404
#ifdef DO_MEM_LIST
403-
if (pthread_mutex_lock(&memLock) == 0)
405+
if (wc_LockMutex(&memLock) == 0)
404406
#endif
405407
{
406408
#ifdef DO_MEM_STATS
@@ -430,13 +432,16 @@ static WC_INLINE void ShowMemoryTracker(void)
430432
}
431433
}
432434

433-
pthread_mutex_unlock(&memLock);
435+
wc_UnLockMutex(&memLock);
434436
#endif
435437
}
436438
}
437439

438440
static WC_INLINE int CleanupMemoryTracker(void)
439441
{
442+
#ifndef WOLFSSL_MUTEX_INITIALIZER
443+
wc_FreeMutex(&memLock);
444+
#endif
440445
wc_MemStats_Ptr = NULL;
441446
/* restore default allocators */
442447
return wolfSSL_SetAllocators(mfDefault, ffDefault, rfDefault);

wolfssl/wolfcrypt/wc_port.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,12 @@
314314
* before Zephyr's posix_types.h can define a conflicting timer_t */
315315
#include <sys/types.h>
316316
#ifndef SINGLE_THREADED
317-
#if !defined(CONFIG_PTHREAD_IPC) && !defined(CONFIG_POSIX_THREADS)
318-
#error "Threading needs CONFIG_PTHREAD_IPC / CONFIG_POSIX_THREADS"
319-
#endif
320317
#if KERNEL_VERSION_NUMBER >= 0x30100
321318
#include <zephyr/kernel.h>
322-
#ifndef CONFIG_ARCH_POSIX
323-
#include <zephyr/posix/posix_types.h>
324-
#include <zephyr/posix/pthread.h>
325-
#endif
326319
#else
320+
#if !defined(CONFIG_PTHREAD_IPC) && !defined(CONFIG_POSIX_THREADS)
321+
#error "Threading needs CONFIG_PTHREAD_IPC / CONFIG_POSIX_THREADS"
322+
#endif
327323
#include <kernel.h>
328324
#ifndef CONFIG_ARCH_POSIX
329325
#include <posix/posix_types.h>
@@ -1557,12 +1553,12 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
15571553
#include <posix/time.h>
15581554
#endif
15591555

1560-
#ifndef CLOCK_REALTIME
1561-
#ifdef SYS_CLOCK_REALTIME
1556+
#ifdef SYS_CLOCK_REALTIME
1557+
#ifndef CLOCK_REALTIME
15621558
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
1563-
#define clock_gettime sys_clock_gettime
1564-
#define clock_settime sys_clock_settime
15651559
#endif
1560+
#define clock_gettime sys_clock_gettime
1561+
#define clock_settime sys_clock_settime
15661562
#endif
15671563

15681564
#if defined(CONFIG_RTC)

0 commit comments

Comments
 (0)