Skip to content

Small thread-safe read-writer locked container support class.

License

Notifications You must be signed in to change notification settings

SiddiqSoft/rwlcontainer

Repository files navigation

RWLContainer : Reader-writer protected container

CodeQL Build Status

Objective

  • Avoid re-implementing the rw-lock; standard C++ (since C++14) has a good reader-writer lock implementation.
  • Provide a simple, convenience layer for dictionary containers.
  • The storage type is a std::shared_ptr<>

Requirements

  • You must be able to use <shared_mutex> and <mutex>.
  • Minimal target is C++17.
  • The build and tests are for Visual Studio 2019 under x64.
  • We use nlohmann::json only in our tests and the library is aware to provide a conversion operator if library is detected.

Usage

#include "gtest/gtest.h"
#include "nlohmann/json.hpp"
#include "siddiqsoft/RWLContainer.hpp"


TEST(examples, Example1)
{
    try
    {
        siddiqsoft::RWLContainer<std::string, std::string> myContainer;

        auto item = myContainer.add("foo", "bar");
        ASSERT_TRUE(item);
        EXPECT_EQ("bar", *item);
    }
    catch (...)
    {
        EXPECT_TRUE(false); // if we throw then the test fails.
    }
}

Additional examples.

© 2021 Siddiq Software LLC. All rights reserved.