From 12cac42e31653323ec607ba3b6512fe9a734d083 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 18 Aug 2022 20:02:18 -0400 Subject: Add return status to zix_ring_mlock() --- include/zix/ring.h | 2 +- src/ring.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/zix/ring.h b/include/zix/ring.h index 872f963..8100d2b 100644 --- a/include/zix/ring.h +++ b/include/zix/ring.h @@ -66,7 +66,7 @@ zix_ring_free(ZixRing* ZIX_NULLABLE ring); using the ring. */ ZIX_API -void +ZixStatus zix_ring_mlock(ZixRing* ZIX_NONNULL ring); /** diff --git a/src/ring.c b/src/ring.c index 922def8..4932e9e 100644 --- a/src/ring.c +++ b/src/ring.c @@ -14,7 +14,7 @@ # define ZIX_MLOCK(ptr, size) mlock((ptr), (size)) #elif defined(_WIN32) # include -# define ZIX_MLOCK(ptr, size) VirtualLock((ptr), (size)) +# define ZIX_MLOCK(ptr, size) !VirtualLock((ptr), (size)) #else # pragma message("warning: No memory locking, possible RT violations") # define ZIX_MLOCK(ptr, size) @@ -106,11 +106,12 @@ zix_ring_free(ZixRing* const ring) } } -void +ZixStatus zix_ring_mlock(ZixRing* const ring) { - ZIX_MLOCK(ring, sizeof(ZixRing)); - ZIX_MLOCK(ring->buf, ring->size); + return (ZIX_MLOCK(ring, sizeof(ZixRing)) || ZIX_MLOCK(ring->buf, ring->size)) + ? ZIX_STATUS_ERROR + : ZIX_STATUS_SUCCESS; } void -- cgit v1.2.1