diff options
author | David Robillard <d@drobilla.net> | 2022-09-01 23:54:54 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-09-02 00:05:26 -0400 |
commit | 1a4a2c607782eac013088ea8afb5a899e72b1f22 (patch) | |
tree | 369b5bff79ac9b01bdefdafeca88c15762f4291a /src | |
parent | bb3a59f1eff2ad2ac203d063cb714189955bbc93 (diff) | |
download | zix-1a4a2c607782eac013088ea8afb5a899e72b1f22.tar.gz zix-1a4a2c607782eac013088ea8afb5a899e72b1f22.tar.bz2 zix-1a4a2c607782eac013088ea8afb5a899e72b1f22.zip |
Improve zix_ring_mlock() return status
Diffstat (limited to 'src')
-rw-r--r-- | src/ring.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -6,18 +6,10 @@ #include "zix_config.h" -#include <stdlib.h> -#include <string.h> - #if USE_MLOCK # include <sys/mman.h> -# define ZIX_MLOCK(ptr, size) mlock((ptr), (size)) #elif defined(_WIN32) # include <windows.h> -# 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 <intrin.h> #endif +#include <stdlib.h> +#include <string.h> + 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 |