Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 3.0.1
- Fixed `LOCKFREE_CACHE_COHERENT` being silently ignored: the variable's value wasn't forwarded to the compiler, so `-DLOCKFREE_CACHE_COHERENT=false` had no effect and cacheline padding was always enabled
- **Important**: `LOCKFREE_CACHE_COHERENT` and `LOCKFREE_CACHELINE_LENGTH` are now sourced exclusively from CMake; non-CMake builds must define both macros themselves and will fail to compile with an `#error` if either is missing
- Fixed broken example code in [Bipartite Buffer](docs/spsc/bipartite_buf.md) docs (unbalanced parentheses)
- Fixed incorrect `@retval` text for `Read`/`Peek`/`Skip` in [Ring Buffer](docs/spsc/ring_buf.md) (was copy-pasted from `Write`)
- Removed incorrect single-thread caveats from [mpmc::PriorityQueue](docs/mpmc/priority_queue.md) `Push`/`Pop` documentation
- Added missing parameter names to Doxygen `@param` tags across all data structure headers
- Various README and documentation fixes

## 3.0.0
- **Breaking**: `PopOptional()` has been renamed to `Pop()` as an overload for the [Queue](docs/spsc/queue.md)s
- **Breaking**: [mpmc::Queue](docs/mpmc/queue.md) now enforces a power-of-2 `size`. This is necessary to prevent deadlocks on index overflows.
Expand All @@ -17,7 +26,7 @@
- Ensured [PriorityQueue](docs/mpmc/priority_queue.md)s must have at least 2 priorities

## 2.0.10
- Added a missing include in the [Ring Buffer](docs/spsc/ring_buf.md) causing errors for `memcpy use
- Added a missing include in the [Ring Buffer](docs/spsc/ring_buf.md) causing errors for `memcpy` use

## 2.0.9
- Fixed the initialization order in the [Bipartite Buffer](docs/spsc/bipartite_buf.md) constructor
Expand Down
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
cmake_minimum_required(VERSION 3.16)

project(lockfree
VERSION 3.0.0
VERSION 3.0.1
LANGUAGES CXX
)

add_subdirectory(${PROJECT_NAME})

# Library configuration
if (DEFINED LOCKFREE_CACHE_COHERENT)
target_compile_definitions(${PROJECT_NAME} INTERFACE LOCKFREE_CACHE_COHERENT)
endif()

if (DEFINED LOCKFREE_CACHELINE_LENGTH)
target_compile_definitions(${PROJECT_NAME}
INTERFACE
LOCKFREE_CACHELINE_LENGTH=${LOCKFREE_CACHELINE_LENGTH}
)
endif()
option(LOCKFREE_CACHE_COHERENT
"Pad data structures to cacheline boundaries to eliminate false sharing" ON)
set(LOCKFREE_CACHELINE_LENGTH 64 CACHE STRING
"Cacheline length in bytes used for alignment when LOCKFREE_CACHE_COHERENT is on")
target_compile_definitions(${PROJECT_NAME}
INTERFACE
LOCKFREE_CACHE_COHERENT=$<BOOL:${LOCKFREE_CACHE_COHERENT}>
LOCKFREE_CACHELINE_LENGTH=${LOCKFREE_CACHELINE_LENGTH}
)

# Only build tests if we're actually working on the library,
# not when the library is being used in a project
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# lockfree
![CMake](https://github.com/DNedic/lockfree/actions/workflows/.github/workflows/cmake.yml/badge.svg)
![CMake](https://github.com/DNedic/lockfree/actions/workflows/cmake.yml/badge.svg)

`lockfree` is a collection of lock-free data structures written in standard C++11 and suitable for all platforms - from deeply embedded to HPC.

Expand Down
2 changes: 1 addition & 1 deletion docs/mpmc/priority_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ if (read) {

This implementation has `O(1)` time complexity for `Push` and `O(current_max_priority)` for `Pop` making it extremely fast.

On the other hand the memory usage is a function of `size * priority_count`, so adequately chosing the number of priorities is necessary.
On the other hand the memory usage is a function of `size * priority_count`, so adequately choosing the number of priorities is necessary.
6 changes: 3 additions & 3 deletions docs/spsc/bipartite_buf.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (!write_started) {
write_started = true;
}
} else {
if (ADC_PollDmaComplete(&adc_dma_h) {
if (ADC_PollDmaComplete(&adc_dma_h)) {
bb_adc.WriteRelease(data.size());
write_started = false;
}
Expand All @@ -47,7 +47,7 @@ There is also a `std::span` based API for those using C++20 and up:
```cpp
auto read = bb_adc.ReadAcquireSpan();

if (!read.empty())) {
if (!read.empty()) {
auto span_used = DoStuffWithData(read);
bb_adc.ReadRelease(span_used);
}
Expand All @@ -62,7 +62,7 @@ if (!write_started) {
write_started = true;
}
} else {
if (ADC_PollDmaComplete(&adc_dma_h) {
if (ADC_PollDmaComplete(&adc_dma_h)) {
bb_adc.WriteRelease(data.size());
write_started = false;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/spsc/priority_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ if (read) {

This implementation has `O(1)` time complexity for `Push` and `O(current_max_priority)` for `Pop` making it extremely fast.

On the other hand the memory usage is a function of `size * priority_count`, so adequately chosing the number of priorities is necessary.
On the other hand the memory usage is a function of `size * priority_count`, so adequately choosing the number of priorities is necessary.
12 changes: 1 addition & 11 deletions lockfree/lockfree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,12 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

#ifndef LOCKFREE_HPP
#define LOCKFREE_HPP

/************************** DEFINE ****************************/

#ifndef LOCKFREE_CACHE_COHERENT
#define LOCKFREE_CACHE_COHERENT true
#endif

#ifndef LOCKFREE_CACHELINE_LENGTH
#define LOCKFREE_CACHELINE_LENGTH 64U
#endif

/************************** INCLUDE ***************************/

#include "spsc/bipartite_buf.hpp"
Expand Down
11 changes: 4 additions & 7 deletions lockfree/mpmc/priority_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
Expand Down Expand Up @@ -63,25 +63,22 @@ template <typename T, size_t size, size_t priority_count> class PriorityQueue {
public:
/**
* @brief Adds an element with a specified priority into the queue.
* Should only be called from the producer thread.
* @param[in] Element
* @param[in] Element priority
* @param[in] element Element to push
* @param[in] priority Element priority
* @retval Operation success
*/
bool Push(const T &element, size_t priority);

/**
* @brief Removes an element with the highest priority from the queue.
* Should only be called from the consumer thread.
* @param[out] Element
* @param[out] element Element popped
* @retval Operation success
*/
bool Pop(T &element);

#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
/**
* @brief Removes an element with the highest priority from the queue.
* Should only be called from the consumer thread.
* @retval Either the element or nothing if the queue is empty.
*/
std::optional<T> Pop();
Expand Down
2 changes: 1 addition & 1 deletion lockfree/mpmc/priority_queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
Expand Down
7 changes: 6 additions & 1 deletion lockfree/mpmc/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
#ifndef LOCKFREE_MPMC_QUEUE_HPP
#define LOCKFREE_MPMC_QUEUE_HPP

#if !defined(LOCKFREE_CACHE_COHERENT) || !defined(LOCKFREE_CACHELINE_LENGTH)
#error \
"lockfree requires LOCKFREE_CACHE_COHERENT and LOCKFREE_CACHELINE_LENGTH to be defined; use the CMake build or define them manually"
#endif

#include <atomic>
#include <cstddef>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion lockfree/mpmc/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

namespace lockfree {
Expand Down
19 changes: 12 additions & 7 deletions lockfree/spsc/bipartite_buf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
#ifndef LOCKFREE_BIPARTITE_BUF_HPP
#define LOCKFREE_BIPARTITE_BUF_HPP

#if !defined(LOCKFREE_CACHE_COHERENT) || !defined(LOCKFREE_CACHELINE_LENGTH)
#error \
"lockfree requires LOCKFREE_CACHE_COHERENT and LOCKFREE_CACHELINE_LENGTH to be defined; use the CMake build or define them manually"
#endif

#include <atomic>
#include <cstddef>
#include <type_traits>
Expand All @@ -65,7 +70,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Acquires a linear region in the bipartite buffer for writing
* Should only be called from the producer thread.
* @param[in] Free linear space in the buffer required
* @param[in] free_required Free linear space in the buffer required
* @retval Pointer to the beginning of the linear space, nullptr if no space
*/
T *WriteAcquire(size_t free_required);
Expand All @@ -74,7 +79,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Acquires a linear region in the bipartite buffer for writing
* Should only be called from the producer thread.
* @param[in] Free linear space in the buffer required
* @param[in] free_required Free linear space in the buffer required
* @retval Span of the linear space
*/
std::span<T> WriteAcquireSpan(size_t free_required);
Expand All @@ -83,7 +88,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Releases the bipartite buffer after a write
* Should only be called from the producer thread.
* @param[in] Elements written to the linear space
* @param[in] written Elements written to the linear space
* @retval None
*/
void WriteRelease(size_t written);
Expand All @@ -92,7 +97,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Releases the bipartite buffer after a write
* Should only be called from the producer thread.
* @param[in] Span of the linear space
* @param[in] written Span of the linear space
* @retval None
*/
void WriteRelease(std::span<T> written);
Expand All @@ -118,7 +123,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Releases the bipartite buffer after a read
* Should only be called from the consumer thread.
* @param[in] Elements read from the linear region
* @param[in] read Elements read from the linear region
* @retval None
*/
void ReadRelease(size_t read);
Expand All @@ -127,7 +132,7 @@ template <typename T, size_t size> class BipartiteBuf {
/**
* @brief Releases the bipartite buffer after a read
* Should only be called from the consumer thread.
* @param[in] Span of the linear space
* @param[in] read Span of the linear space
* @retval None
*/
void ReadRelease(std::span<T> read);
Expand Down
2 changes: 1 addition & 1 deletion lockfree/spsc/bipartite_buf_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
Expand Down
8 changes: 4 additions & 4 deletions lockfree/spsc/priority_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
Expand Down Expand Up @@ -65,16 +65,16 @@ template <typename T, size_t size, size_t priority_count> class PriorityQueue {
/**
* @brief Adds an element with a specified priority into the queue.
* Should only be called from the producer thread.
* @param[in] Element
* @param[in] Element priority
* @param[in] element Element to push
* @param[in] priority Element priority
* @retval Operation success
*/
bool Push(const T &element, size_t priority);

/**
* @brief Removes an element with the highest priority from the queue.
* Should only be called from the consumer thread.
* @param[out] Element
* @param[out] element Element popped
* @retval Operation success
*/
bool Pop(T &element);
Expand Down
2 changes: 1 addition & 1 deletion lockfree/spsc/priority_queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
Expand Down
7 changes: 6 additions & 1 deletion lockfree/spsc/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

/************************** INCLUDE ***************************/
#ifndef LOCKFREE_QUEUE_HPP
#define LOCKFREE_QUEUE_HPP

#if !defined(LOCKFREE_CACHE_COHERENT) || !defined(LOCKFREE_CACHELINE_LENGTH)
#error \
"lockfree requires LOCKFREE_CACHE_COHERENT and LOCKFREE_CACHELINE_LENGTH to be defined; use the CMake build or define them manually"
#endif

#include <atomic>
#include <cstddef>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion lockfree/spsc/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* This file is part of lockfree
*
* Author: Djordje Nedic <nedic.djordje2@gmail.com>
* Version: v3.0.0
* Version: v3.0.1
**************************************************************/

namespace lockfree {
Expand Down
Loading
Loading