Skip to content

Commit e82ed48

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

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

wolfssl/wolfcrypt/mem_track.h

Lines changed: 9 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(memList);
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,7 @@ static WC_INLINE int InitMemoryTracker(void)
369368
}
370369

371370
#ifdef DO_MEM_LIST
372-
if (pthread_mutex_lock(&memLock) == 0)
371+
if (wc_LockMutex(&memLock) == 0)
373372
#endif
374373
{
375374
#ifdef DO_MEM_STATS
@@ -388,7 +387,7 @@ static WC_INLINE int InitMemoryTracker(void)
388387
XMEMSET(&ourMemList, 0, sizeof(ourMemList));
389388
ourMemStats.memList = &ourMemList;
390389

391-
pthread_mutex_unlock(&memLock);
390+
wc_UnLockMutex(&memLock);
392391
#endif
393392
}
394393

@@ -400,7 +399,7 @@ static WC_INLINE int InitMemoryTracker(void)
400399
static WC_INLINE void ShowMemoryTracker(void)
401400
{
402401
#ifdef DO_MEM_LIST
403-
if (pthread_mutex_lock(&memLock) == 0)
402+
if (wc_LockMutex(&memLock) == 0)
404403
#endif
405404
{
406405
#ifdef DO_MEM_STATS
@@ -430,7 +429,7 @@ static WC_INLINE void ShowMemoryTracker(void)
430429
}
431430
}
432431

433-
pthread_mutex_unlock(&memLock);
432+
wc_UnLockMutex(&memLock);
434433
#endif
435434
}
436435
}

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)