This library provides convenient, production-ready wrappers around C++20 standard library synchronization primitives:
- RWLContainer: A reader-writer lock protected dictionary that wraps
std::unordered_mapwithstd::shared_mutexfor safe concurrent access - WaitableQueue: A thread-safe queue that augments
std::queuewithstd::shared_mutexandstd::counting_semaphorefor efficient producer-consumer patterns
These classes eliminate boilerplate synchronization code and provide a simple, type-safe API for common concurrent programming scenarios.
- C++20 or later
<shared_mutex>and<mutex>support- CMake 3.20+
Tested and built on:
- Windows (Visual Studio 2022)
- Linux (Fedora)
- macOS
All platforms are tested in the CI/CD pipeline with comprehensive test coverage.
A thread-safe dictionary with reader-writer locking for efficient concurrent access.
RWLContainer<KeyType, StorageType>
├── Configuration
│ ├── ReplaceExisting
│ └── FailOnCollission
├── Methods
│ ├── add(key, value)
│ ├── add(key, shared_ptr)
│ ├── add(key, callback)
│ ├── remove(key)
│ ├── find(key)
│ ├── size()
│ ├── scan(callback)
│ └── toJson()
└── Properties
├── addCounter
└── removeCounter
| Method | Description | Link |
|---|---|---|
add(key, StorageType&&) |
Add element by moving value | Details |
add(key, StorageTypePtr&&) |
Add element via shared_ptr | Details |
add(key, callback) |
Add element via callback | Details |
remove(key) |
Remove and return element | Details |
find(key) |
Find element without removing | Details |
size() |
Get number of elements | Details |
scan(callback) |
Iterate and find elements | Details |
toJson() |
Serialize to JSON | Details |
A thread-safe queue with timeout-based waiting for producer-consumer patterns.
WaitableQueue<StorageType>
├── Methods
│ ├── push(value)
│ ├── emplace(value)
│ ├── tryWaitItem(timeout)
│ ├── waitUntilEmpty(timeout)
│ ├── size()
│ ├── addCounter()
│ ├── removeCounter()
│ └── toJson()
└── Properties
├── Deleted: copy constructor
├── Deleted: move constructor
├── Deleted: copy assignment
└── Deleted: move assignment
| Method | Description | Link |
|---|---|---|
push(StorageType&&) |
Add element to queue | Details |
emplace(StorageType&&) |
Construct element in-place | Details |
tryWaitItem(timeout) |
Wait for element with timeout | Details |
waitUntilEmpty(timeout) |
Wait until queue is empty | Details |
size() |
Get number of elements | Details |
addCounter() |
Get total adds | Details |
removeCounter() |
Get total removes | Details |
toJson() |
Serialize to JSON | Details |
For detailed API documentation, method signatures, and comprehensive examples, see API.md and some notes on tests.
- Use the nuget SiddiqSoft.RWLContainer
- Use CPM to integrate into your CMake project
#include "siddiqsoft/RWLContainer.hpp"
int main() {
siddiqsoft::RWLContainer<std::string, int> cache;
// Add items
cache.add("count", 42);
cache.add("value", 100);
// Find items
if (auto val = cache.find("count")) {
std::cout << "Found: " << *val << std::endl;
}
// Remove items
cache.remove("count");
std::cout << "Size: " << cache.size() << std::endl;
return 0;
}#include "siddiqsoft/WaitableQueue.hpp"
#include <thread>
int main() {
siddiqsoft::WaitableQueue<std::string> queue;
// Producer thread
std::thread producer([&queue]() {
for (int i = 0; i < 5; ++i) {
queue.push(std::string("item_") + std::to_string(i));
}
});
// Consumer thread
std::thread consumer([&queue]() {
while (true) {
auto item = queue.tryWaitItem(std::chrono::milliseconds(500));
if (item) {
std::cout << "Processed: " << *item << std::endl;
} else {
break;
}
}
});
producer.join();
consumer.join();
return 0;
}Uses GitVersion for semantic versioning (MAJOR.MINOR.PATCH). Version is automatically determined from git history.
© 2021 Siddiq Software LLC. All rights reserved.