summaryrefslogtreecommitdiffstats
path: root/src/ring.c
AgeCommit message (Collapse)AuthorFilesLines
2022-10-21Split up common headerDavid Robillard1-1/+1
2022-10-21Hide errno utility functionsDavid Robillard1-1/+5
2022-09-02Improve test coverageDavid Robillard1-2/+2
2022-09-02Improve zix_ring_mlock() return statusDavid Robillard1-11/+16
2022-08-19Avoid mixing signed and unsigned integersDavid Robillard1-2/+2
2022-08-18Add return status to zix_ring_mlock()David Robillard1-4/+5
2022-08-18Make all ring parameters constDavid Robillard1-18/+22
2022-08-18Add transactional ring APIDavid Robillard1-5/+39
2022-08-12Fix ring thread safetyDavid Robillard1-25/+53
The previous code was "probably fine" in practice, but was both missing some necessary synchronization, and using unnecessarily heavyweight barriers on Windows. Since this code conveniently has a 1:1 relationship between barriers and atomic accesses anyway, rewrite things to use an "atomic" interface closer to standard C11 and C++11. Harden things in the process, so that the thread-safety guarantees are followed, and hopefully clearer to see in the code (1 synchronized read of "their" index, then maybe 1 synchronized write of "your" index). Windows/MSVC annoyingly does not provide a suitable C API for this, so just ignore the existence of Windows on ARM and use x86/x64 Windows intrinsics to prevent compiler reordering (which is all that's required on those architectures). Note that MSVC can make some reordering guarantees about volatile variables, but: * Only with a certain option, /volatile:ms, which Microsoft "strongly recommend" against using. It is disabled by default (and painfully slow if enabled) on ARM. * This guarantee does not prevent reordering of access to other memory (only the volatile variables themselves), which is required by a ring buffer. So, deal with that case by using explicit read and write barriers like before, but only in the atomic abstractions. In the process, switch to more lightweight barriers, which should marginally improve performance on Windows. When MSVC adds stdatomic.h support, most of the platform-specific gunk here can go away entirely.
2022-08-12Simplify ring writing codeDavid Robillard1-6/+8
The compiler is surely smart enough to factor out these common expressions, but I find this easier to read this way anyway.
2022-08-12Use a consistent error handling styleDavid Robillard1-6/+5
2022-08-12Simplify ring space calculationsDavid Robillard1-14/+2
It isn't necessary to branch here to avoid underflow. Essentially, the way that unsigned binary integers work "automatically" does what this code was doing. Note that these expressions only work for a ring buffer that, like this one, has a power of 2 (real) size and a maximum capacity 1 less than that.
2022-06-28Use uppercase integer literal suffixesDavid Robillard1-5/+5
I give in.
2022-06-28Clean up build configurationDavid Robillard1-1/+3
2021-09-14Make ZixAllocator a single flat structDavid Robillard1-7/+7
I can never decide between these two patterns for polymorphic objects in C, but this one seems more appropriate here since it's more conducive to inheritance.
2021-09-10Adopt REUSE machine-readable licensing standardDavid Robillard1-15/+2
2021-09-10Add custom allocator supportDavid Robillard1-14/+24
2021-01-16Allow all free functions to be called on nullDavid Robillard1-2/+4
2020-12-31Update copyright headersDavid Robillard1-1/+1
2020-12-31Separate source from headersDavid Robillard1-0/+222
2012-08-10Minimal space overhead inline value hash table.David Robillard1-225/+0
Add ZixChunk. Add SSE 4.2 accelerated digest (with fallback) in zix/digest.h. Make library optionally header-only (define ZIX_INLINE). git-svn-id: http://svn.drobilla.net/zix/trunk@76 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2012-08-09Fix warnings: -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes ↵David Robillard1-1/+1
-Wmissing-prototypes. git-svn-id: http://svn.drobilla.net/zix/trunk@72 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2012-01-31Windows/Visual C++ portability.David Robillard1-8/+14
git-svn-id: http://svn.drobilla.net/zix/trunk@51 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2012-01-31Full test coverage for ZixRing.David Robillard1-10/+5
Update waf. git-svn-id: http://svn.drobilla.net/zix/trunk@50 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2011-10-09Fix ZixRing error when reading split/wrapped messages.David Robillard1-1/+1
Use a non-power-of-two message size in ZixRing test to test this. git-svn-id: http://svn.drobilla.net/zix/trunk@43 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2011-09-18Tidy.David Robillard1-2/+2
git-svn-id: http://svn.drobilla.net/zix/trunk@14 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
2011-09-18Add ZixRing.David Robillard1-0/+224
git-svn-id: http://svn.drobilla.net/zix/trunk@13 df6676b4-ccc9-40e5-b5d6-7c4628a128e3