diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2024-02-05 15:18:33 -0500 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2024-02-05 15:18:33 -0500 |
| commit | 0ff3cedf5df9c27bccd3053ce6339e317f87ff76 (patch) | |
| tree | 0ffdeb674cc31d8b285547e86b6939b0899f2113 /include/framework/structure/MutableBuffer.h | |
| parent | db4806d9dd9757273a14e6c3ea92e5a087239145 (diff) | |
| download | dynamic-extension-0ff3cedf5df9c27bccd3053ce6339e317f87ff76.tar.gz | |
BufferView: Adjusted BV to avoid repeated modulus operations
Diffstat (limited to 'include/framework/structure/MutableBuffer.h')
| -rw-r--r-- | include/framework/structure/MutableBuffer.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/include/framework/structure/MutableBuffer.h b/include/framework/structure/MutableBuffer.h index 94a9c41..415c95a 100644 --- a/include/framework/structure/MutableBuffer.h +++ b/include/framework/structure/MutableBuffer.h @@ -230,13 +230,16 @@ public: /* * Note: this returns the available physical storage capacity, * *not* now many more records can be inserted before the - * HWM is reached. - * - * FIXME: this logic is incorrect for the buffer prior to the - * first call to advance_head, and will under-report the available - * space. + * HWM is reached. It considers the old_head to be "free" + * when it has no remaining references. This should be true, + * but a buggy framework implementation may violate the + * assumption. */ size_t get_available_capacity() { + if (m_old_head.load().refcnt == 0) { + return m_cap - (m_tail.load() - m_head.load().head_idx); + } + return m_cap - (m_tail.load() - m_old_head.load().head_idx); } |