smart_engine 0.14.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/smart_core/engine/read_write_lock.rb +21 -7
- data/lib/smart_core/engine/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f6a846502241aa2029b692dc4f0c81ee004527a3242b750b7c6ea10a37872a
|
4
|
+
data.tar.gz: 9bec4690bf081407fc7262610e978065f99422f57df2c1d673469d53cf6f142f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40e93990c49475cf764d2baf118f32409d0cc6461f5892de680d5222f040110f17c755540284c35a5dbf34d604a62d5255a5d63fa7e9c03035fad1680eafa867
|
7
|
+
data.tar.gz: c182166a23faf3ae36202af92048b1a258847ea1de9541deabbee367101af68cfb67bb1d818c634ae8a92da7e8a24c4f94102185f8a7c75c3b43c2da9057f456
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.16.0] - 2022-09-30
|
5
|
+
### Changed
|
6
|
+
- `SmartCore::Engine::ReadWriteLock` does not lock the current thread if the current thread has already acquired the lock;
|
7
|
+
|
8
|
+
## [0.15.0] - 2022-09-30
|
9
|
+
### Added
|
10
|
+
- `SmartCore::Engine::ReadWriteLock#write_owned?` - checking that write lock is owned by current thread or not;
|
11
|
+
|
4
12
|
## [0.14.0] - 2022-09-30
|
5
13
|
### Added
|
6
14
|
- Read/Write locking mechanizm: `SmartCore::Engine::ReadWriteLock`;
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,9 @@ lock = SmartCore::Engine::ReadWriteLock.new
|
|
76
76
|
lock.read_sync { ...some-read-op... } # waits for writer
|
77
77
|
lock.read_sync { ...some-read-op... } # waits for writer
|
78
78
|
lock.write_sync { ... some-write-op... } # waits for all readers and current writer
|
79
|
+
|
80
|
+
# is write_sync lock is owned by current thread?
|
81
|
+
lock.write_owned? # true or false
|
79
82
|
```
|
80
83
|
|
81
84
|
---
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# @api public
|
4
4
|
# @since 0.14.0
|
5
|
+
# @version 0.15.0
|
5
6
|
class SmartCore::Engine::ReadWriteLock
|
6
7
|
# @return [void]
|
7
8
|
#
|
@@ -28,19 +29,32 @@ class SmartCore::Engine::ReadWriteLock
|
|
28
29
|
@active_reader = false
|
29
30
|
end
|
30
31
|
|
32
|
+
# @return [Boolean]
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
# @since 0.15.0
|
36
|
+
def write_owned?
|
37
|
+
@write_lock.owned?
|
38
|
+
end
|
39
|
+
|
31
40
|
# @param block [Block]
|
32
41
|
# @return [Any]
|
33
42
|
#
|
34
43
|
# @api public
|
35
44
|
# @since 0.14.0
|
45
|
+
# @version 0.16.0
|
36
46
|
def write_sync(&block)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
if @write_lock.owned?
|
48
|
+
yield
|
49
|
+
else
|
50
|
+
while @active_reader do; end
|
51
|
+
@write_lock.synchronize do
|
52
|
+
@active_reader = true
|
53
|
+
begin
|
54
|
+
yield
|
55
|
+
ensure
|
56
|
+
@active_reader = false
|
57
|
+
end
|
44
58
|
end
|
45
59
|
end
|
46
60
|
end
|