From 1a4a2c607782eac013088ea8afb5a899e72b1f22 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 1 Sep 2022 23:54:54 -0400 Subject: Improve zix_ring_mlock() return status --- src/ring.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/ring.c') diff --git a/src/ring.c b/src/ring.c index bcbeb4c..10b31e5 100644 --- a/src/ring.c +++ b/src/ring.c @@ -6,18 +6,10 @@ #include "zix_config.h" -#include -#include - #if USE_MLOCK # include -# define ZIX_MLOCK(ptr, size) mlock((ptr), (size)) #elif defined(_WIN32) # include -# define ZIX_MLOCK(ptr, size) !VirtualLock((ptr), (size)) -#else -# pragma message("warning: No memory locking, possible RT violations") -# define ZIX_MLOCK(ptr, size) #endif /* @@ -29,6 +21,9 @@ # include #endif +#include +#include + struct ZixRingImpl { ZixAllocator* allocator; ///< User allocator uint32_t write_head; ///< Read index into buf @@ -109,9 +104,19 @@ zix_ring_free(ZixRing* const ring) ZixStatus zix_ring_mlock(ZixRing* const ring) { - return (ZIX_MLOCK(ring, sizeof(ZixRing)) || ZIX_MLOCK(ring->buf, ring->size)) - ? ZIX_STATUS_ERROR - : ZIX_STATUS_SUCCESS; +#if USE_MLOCK + return zix_errno_status_if(mlock(ring, sizeof(ZixRing)) + + mlock(ring->buf, ring->size)); + +#elif defined(_WIN32) + return (VirtualLock(ring, sizeof(ZixRing)) && + VirtualLock(ring->buf, ring->size)) + ? ZIX_STATUS_SUCCESS + : ZIX_STATUS_ERROR; + +#else + return ZIX_STATUS_NOT_SUPPORTED; +#endif } void -- cgit v1.2.1