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 containers

Build Status

Objective

WaitableQueue

  • Implements a thread-safe queue
  • Any number of threads can tryWaitItem with a given timeout on the object.
  • The queue must be given ownership of the StorageType and the thread receiving the object is going to destroy the object.

RWLContainer

  • 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 internal storage type is a std::shared_ptr<>

Requirements

  • You must be able to use <shared_mutex> and <mutex>.
  • Minimal target is C++20.
  • We use nlohmann::json only in our tests and the library is aware to provide a conversion operator if library is detected.
  • CMake build system with development on MacOSX, Linux (Fedora) and Windows (VS2022).

Usage

Examples

#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.
    }
}

© 2021 Siddiq Software LLC. All rights reserved.