Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/curve/lockpp
🔒 A C++20 Library that provides mutex protected objects
https://github.com/curve/lockpp
cmake cpp-library cpp20 cpp20-library cpp23 cpp23-library mutex mutex-lock mutex-locks safety thread-safe thread-safety
Last synced: 2 months ago
JSON representation
🔒 A C++20 Library that provides mutex protected objects
- Host: GitHub
- URL: https://github.com/curve/lockpp
- Owner: Curve
- License: mit
- Created: 2021-05-20T14:00:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T13:12:34.000Z (5 months ago)
- Last Synced: 2024-08-02T14:51:20.545Z (5 months ago)
- Topics: cmake, cpp-library, cpp20, cpp20-library, cpp23, cpp23-library, mutex, mutex-lock, mutex-locks, safety, thread-safe, thread-safety
- Language: C++
- Homepage:
- Size: 134 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A C++20 library providing mutex protection for any object## 📦 Installation
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
```cmake
CPMFindPackage(
NAME lockpp
VERSION 3.0
GIT_REPOSITORY "https://github.com/Curve/lockpp"
)
```* Using FetchContent
```cmake
include(FetchContent)FetchContent_Declare(lockpp GIT_REPOSITORY "https://github.com/Curve/lockpp" GIT_TAG v3.0)
FetchContent_MakeAvailable(lockpp)target_link_libraries( cr::lockpp)
```## 📃 Usage
```cpp
lockpp::lock 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](tests/custom-mutex.cpp) as well [as custom locks](tests/custom-lock.cpp) _(i.e `std::unique_lock`, `std::lock_guard`)_.
> For more examples see [tests](tests)