Skip to content
/ lockpp Public

πŸ”’ A C++20 Library that provides mutex protected objects

License

Notifications You must be signed in to change notification settings

Curve/lockpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ab65683 Β· Aug 2, 2024

History

59 Commits
Jul 28, 2024
Oct 10, 2023
Jul 31, 2024
Aug 2, 2024
Aug 2, 2024
Jul 28, 2024
Oct 10, 2023
Nov 3, 2021
Aug 2, 2024
May 5, 2024
Aug 2, 2024

Repository files navigation


A C++20 library providing mutex protection for any object

πŸ“¦ Installation

  • Using CPM

    CPMFindPackage(
      NAME           lockpp
      VERSION        3.0
      GIT_REPOSITORY "https://github.com/Curve/lockpp"
    )
  • Using FetchContent

    include(FetchContent)
    
    FetchContent_Declare(lockpp GIT_REPOSITORY "https://github.com/Curve/lockpp" GIT_TAG v3.0)
    FetchContent_MakeAvailable(lockpp)
    
    target_link_libraries(<target> cr::lockpp)

πŸ“ƒ Usage

lockpp::lock<std::string> var("Test");

// Read only access
{
    auto locked = var.read();
    assert(!locked->empty());
}

// Write access
{
    auto locked = var.write();

    *write_access = "assignment";
    locked->clear();
}

// One time access
var.assign("another assignment");
assert(var.copy() == "another assignment");

lockpp also allows you to supply the mutex to be used as well as custom locks (i.e std::unique_lock, std::lock_guard).

For more examples see tests