SiddiqSoft.RWLEnvelope
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SiddiqSoft.RWLEnvelope --version 1.0.0
NuGet\Install-Package SiddiqSoft.RWLEnvelope -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SiddiqSoft.RWLEnvelope" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SiddiqSoft.RWLEnvelope --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SiddiqSoft.RWLEnvelope, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SiddiqSoft.RWLEnvelope as a Cake Addin #addin nuget:?package=SiddiqSoft.RWLEnvelope&version=1.0.0 // Install SiddiqSoft.RWLEnvelope as a Cake Tool #tool nuget:?package=SiddiqSoft.RWLEnvelope&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RWLEnvelope : A simple read-writer lock wrapper for modern C++
Objective
- Avoid re-implementing the rw-lock; standard C++ (since C++14) has a good reader-writer lock implementation.
- Provide a simple, convenience layer atop the underlying
std::unique_lock
andstd::shared_lock
access to some type.
WE DO NOT IMPLEMENT a read-writer lock, rather we provide a simple pattern where the most frequent use of the underlying facility is in a neat package.
Requirements
You must be able to use <shared_mutex>
and <mutex>
The build and tests are for Visual Studio 2019 under x64.
Usage
- Use the nuget SiddiqSoft.RWLEnvelope
- Copy paste..whatever works.
- Two methods: -- Observer/mutator model with callback and custom return
#include "gtest/gtest.h"
#include "nlohmann/json.hpp"
#include "../src/RWLEnvelope.hpp"
TEST(examples, WithCallbacks)
{
siddiqsoft::RWLEnvelope<nlohmann::json> docl({{"foo", "bar"}, {"few", "lar"}});
// Check we have pre-change value..
EXPECT_EQ("bar", docl.observe<std::string>([](const auto& doc) { return doc.value("foo", ""); }));
// Modify the item
docl.mutate<void>([](auto& doc) { doc["foo"] = "bare"; });
// Check we have pre-change value.. Note that here we return a boolean to avoid data copy
EXPECT_TRUE(docl.observe<bool>([](const auto& doc) { return doc.value("foo", "").find("bare") == 0; }));
// Check to make sure that the statistics match
auto info = nlohmann::json(docl);
EXPECT_EQ(1, info.value("readWriteActions", 0));
}
TEST(examples, WithDirectLocks)
{
siddiqsoft::RWLEnvelope<nlohmann::json> docl({{"foo", "bar"}, {"few", "lar"}});
// Check we have pre-change value..
if (const auto& [doc, rl] = docl.readLock(); rl) { EXPECT_EQ("bar", doc.value("foo", "")); }
// Modify the item
if (auto& [doc, wl] = docl.writeLock(); wl) { doc["foo"] = "bare"; };
// Check we have pre-change value.. Note that here we return a boolean to avoid data copy
if (const auto& [doc, rl] = docl.readLock(); rl) { EXPECT_TRUE(doc.value("foo", "").find("bare") == 0); }
}
<small align="right">
© 2021 Siddiq Software LLC. All rights reserved.
</small>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
native | native is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SiddiqSoft.RWLEnvelope:
Package | Downloads |
---|---|
SiddiqSoft.CosmosClient
Azure Cosmos REST-API Client for Modern C++ |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.0 | 138 | 12/7/2024 |
1.1.1 | 442 | 12/2/2021 |
1.1.0 | 9,060 | 7/22/2021 |
1.1.0-main0001 | 261 | 7/22/2021 |
1.0.0 | 1,465 | 7/22/2021 |
0.10.0-main0001 | 235 | 7/22/2021 |