Skip to content

Commit 64e68c3

Browse files
committed
docs: update readme
1 parent 0f13c23 commit 64e68c3

File tree

2 files changed

+125
-88
lines changed

2 files changed

+125
-88
lines changed

README.md

+34-88
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,58 @@
11
<div align="center">
2-
<img src="assets/logo.png" height=312>
2+
<img src="assets/logo.svg" height=312>
33
</div>
44

55
<br/>
66

7-
<p align="center">
8-
A C++20 library that provides mutex protection for any object
7+
<p align="center">
8+
A C++20 library providing mutex protection for any object
99
</p>
1010

11-
---
11+
## 📦 Installation
1212

13-
## ⚙️ Configuration
14-
### Tests
15-
```cmake
16-
set(lockpp_tests OFF)
17-
```
18-
> If set to `ON`, lockpp will build tests.
19-
20-
21-
## 📎 Installation
22-
23-
> **Note**
24-
> This library requires a C++20 capable compiler.
25-
> In case you need support for C++17 checkout [version 1.0.2](https://github.com/Soundux/lockpp/releases/tag/v1.0.2)
26-
27-
- FetchContent
28-
29-
```cmake
30-
include(FetchContent)
31-
FetchContent_Declare(lockpp GIT_REPOSITORY "https://github.com/Soundux/lockpp")
13+
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
14+
```cmake
15+
CPMFindPackage(
16+
NAME lockpp
17+
VERSION 2.3
18+
GIT_REPOSITORY "https://github.com/Soundux/lockpp"
19+
)
20+
```
3221

33-
FetchContent_MakeAvailable(lockpp)
34-
target_link_libraries(<YourLibrary> lockpp)
35-
```
22+
* Using FetchContent
23+
```cmake
24+
include(FetchContent)
3625
37-
- Git Submodule
26+
FetchContent_Declare(lockpp GIT_REPOSITORY "https://github.com/Soundux/lockpp" GIT_TAG v2.3)
27+
FetchContent_MakeAvailable(lockpp)
3828
39-
```bash
40-
git submodule add "https://github.com/Soundux/lockpp"
41-
```
42-
```cmake
43-
# Somewhere in your CMakeLists.txt
44-
add_subdirectory("<path_to_lockpp>")
45-
target_link_libraries(<YourLibrary> lockpp)
46-
```
29+
target_link_libraries(<target> lockpp)
30+
```
4731

48-
## 📔 Usage
32+
## 📃 Usage
4933

50-
### Simple example
5134
```cpp
52-
#include <lockpp/lock.hpp>
35+
lockpp::lock<std::string> var("Test");
5336

54-
int main()
37+
// Read only access
5538
{
56-
lockpp::lock<std::string> protected_string("Test");
57-
{
58-
auto read_access = protected_string.read();
59-
bool is_empty = read_access->empty();
60-
// read_access->clear(); <-- Will not work
61-
}
62-
{
63-
auto write_access = protected_string.write();
64-
65-
write_access->clear();
66-
*write_access = "New String!";
67-
68-
// auto another_write_access = protected_string.write(); <-- This will lock.
69-
}
70-
71-
return 0;
39+
auto locked = var.read();
40+
assert(!locked->empty());
7241
}
73-
```
7442

75-
### Custom Mutex
76-
```cpp
77-
#include <lockpp/lock.hpp>
78-
79-
int main()
43+
// Write access
8044
{
81-
lockpp::lock<std::string, std::recursive_mutex> protected_string("Test");
82-
{
83-
auto write_access = protected_string.write();
84-
85-
write_access->clear();
86-
*write_access = "New String!";
87-
88-
auto another_write_access = protected_string.write();
89-
*another_write_access = "This is fine!";
90-
}
45+
auto locked = var.write();
9146

92-
return 0;
47+
*write_access = "assignment";
48+
locked->clear();
9349
}
94-
```
95-
96-
### Custom Locks
97-
```cpp
98-
#include <lockpp/lock.hpp>
99-
100-
int main()
101-
{
102-
lockpp::lock<std::string> protected_string("Test");
103-
{
104-
auto read_1 = test.read<std::unique_lock>();
105-
auto read_2 = test.read<std::unique_lock>(std::adopt_lock); // <-- Also accepts custom arguments for lock
106-
}
10750

108-
return 0;
109-
}
51+
// One time access
52+
var.assign("another assignment");
53+
assert(var.copy() == "another assignment");
11054
```
11155
112-
> For more examples see [tests](tests/)
56+
_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`)_.
57+
58+
> For more examples see [tests](tests)

assets/logo.svg

+91
Loading

0 commit comments

Comments
 (0)