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: 8 days 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 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T13:12:34.000Z (over 1 year ago)
- Last Synced: 2025-02-13T23:37:08.249Z (9 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: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A C++23 library providing mutex protection for any object
## 📦 Installation
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
```cmake
CPMFindPackage(
NAME lockpp
VERSION 3.2.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.2.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)