summaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
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-07-13Suppress new warnings in clang and clang-tidy 14David Robillard1-0/+1
2022-06-28Move zix_strerror to libraryDavid Robillard1-0/+28
2022-06-28Use uppercase integer literal suffixesDavid Robillard6-113/+112
I give in.
2022-06-28Simplify dep5 file by adding license headers where possibleDavid Robillard1-0/+3
2022-06-28Clean up build configurationDavid Robillard4-17/+43
2022-02-02Avoid fallthrough annotation on older GCC versionsDavid Robillard1-1/+1
2022-01-14Fix hash insertion tombstone replacement caseDavid Robillard1-0/+1
2021-12-17Suppress new warnings in clang-tidy 13David Robillard1-1/+2
2021-10-27Compile but fail at runtime if aligned allocation is not supportedDavid Robillard1-1/+1
2021-10-27Remove unnecessary includeDavid Robillard1-1/+0
2021-10-27Improve hash table performance slightlyDavid Robillard1-6/+9
2021-10-27Fix zix_digest64() to consume all inputDavid Robillard1-5/+5
This was a copy-paste bug since the loop in zix_digest32() worked differently. As a result only the first block was considered, making the digest nearly useless for larger values. The tests didn't (and unfortunately still don't) catch this because the 64-bit digest algorithm incorporates the size itself. Fix this by changing the loop to work the same way as zix_digest32(), so hopefully something like this doesn't happen again.
2021-09-16Add a simple bump pointer allocatorDavid Robillard1-0/+161
2021-09-14Add aligned allocation interface and use it in ZixBTreeDavid Robillard4-9/+132
2021-09-14Make ZixAllocator a single flat structDavid Robillard5-61/+60
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-13Correctly handle hash table reallocation failuresDavid Robillard1-8/+25
2021-09-11Fix zix_btree_lower_bound()David Robillard1-7/+8
This condition was converted to an assertion in an over-eager session of code simplification and coverage testing. It turns out this does happen.
2021-09-10Fix C11 buildDavid Robillard1-3/+6
2021-09-10Adopt REUSE machine-readable licensing standardDavid Robillard8-120/+16
2021-09-10Remove branches from zix_bitset_set() and zix_bitset_reset()David Robillard1-14/+10
2021-09-10Add custom allocator supportDavid Robillard5-84/+182
2021-09-10Add nullability annotationsDavid Robillard2-0/+52
This allows clang to issue warnings at compile time when null is passed to a non-null parameter. For public entry points, also add assertions to catch such issues when the compiler does not support this.
2021-09-10Rewrite ZixHash as a flat table with open addressingDavid Robillard1-145/+258
2021-09-10Replace CRC32 digest with more modern and appropriate algorithmsDavid Robillard1-100/+172
This makes the hassle of platform-specific code go away, and instead uses portable implementations of relatively standard modern hash algorithms. CRC32 is not great as a hash function anyway, though it is very fast when hardware accelerated.
2021-09-10Fix cast alignment warnings in SSE4.2 digest codeDavid Robillard1-5/+29
2021-09-10Add a user handle to destroy callbackDavid Robillard2-21/+30
2021-09-10Simplify BTree implementationDavid Robillard1-253/+388
2021-09-10Allow ZixBTreeIter to be allocated on the stackDavid Robillard1-170/+104
2021-09-10Remove destroy field of BTree and add zix_btree_clear()David Robillard1-29/+36
If this is used, it is only when clearing or freeing a tree. Allowing it to be given as a parameter directly there is clearer and avoids bloating the tree itself with information that isn't needed.
2021-09-10Remove BTree debug printingDavid Robillard1-37/+0
2021-09-10Avoid implicit padding in BTree nodes on 64-bitDavid Robillard1-8/+15
Might as well use 32-bit integers if the space is there anyway.
2021-09-10Be explicit about the sign of defined integer constantsDavid Robillard1-4/+4
2021-09-10Fix conversion warningsDavid Robillard1-1/+1
2021-09-10Remove ZixStrindexDavid Robillard1-263/+0
2021-07-17Remove ZixSortedArrayDavid Robillard1-193/+0
2021-07-17Avoid allegedly "suspicious" string comparisonsDavid Robillard1-1/+1
I guess these are suspicious if you've never seen C before?
2021-07-17Use line comments where appropriateDavid Robillard2-12/+12
2021-06-30Add pure attribute to internal BTree accessor functionsDavid Robillard1-0/+3
2021-06-30Fix hash size after removing elementsDavid Robillard1-1/+1
2021-01-16Allow all free functions to be called on nullDavid Robillard2-6/+10
2021-01-12Fix crash with optimized builds with GCC 10.1.0David Robillard1-1/+1
2020-12-31Fix zix_sorted_array_iter_is_end()David Robillard1-1/+1
2020-12-31Fix MinGW buildDavid Robillard1-1/+0
2020-12-31Fix potential balance overflowDavid Robillard1-4/+4