smart_engine 0.13.0 → 0.14.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 +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/lib/smart_core/engine/lock.rb +1 -1
- data/lib/smart_core/engine/read_write_lock.rb +47 -0
- data/lib/smart_core/engine/version.rb +2 -2
- data/lib/smart_core/engine.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 912e841987ba6da79b04609e0f86580d900676b10711d5e38b614099782702cf
|
4
|
+
data.tar.gz: 395c81f467a482cde8042dfb207df5aa70b7a865f317fcd068e110b127dfe95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '080a49d84507ca934dcf9435bcbe724cf8146167039e1ebbf0a56343249fbd4c39893a79508a0e08826fb9496eb6a721f5e335a0a9b19149263c8a73c4ebf9bf'
|
7
|
+
data.tar.gz: 0eb86cfe731f1911969025db50560148858f03d8b8842da9c3bac49fbd3c4dfe74c0c86392438c060c2ec43ff0453da8c9fc3eeed4076bc11c772e59c931ee7c
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [
|
4
|
+
## [0.14.0] - 2022-09-30
|
5
|
+
### Added
|
6
|
+
- Read/Write locking mechanizm: `SmartCore::Engine::ReadWriteLock`;
|
7
|
+
|
8
|
+
## [0.13.0] - 2022-09-30
|
5
9
|
### Added
|
6
10
|
- Simplest in-memory cache storage implementation: `SmartCore::Engine::Cache`;
|
7
11
|
### Changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,7 @@ require 'smart_core'
|
|
34
34
|
|
35
35
|
- [Global set of error types](#global-set-of-error-types)
|
36
36
|
- [Simple reentrant lock](#simple-reentrant-lock)
|
37
|
+
- [Read/Write Lock](#read-write-lock)
|
37
38
|
- [Cache Storage](#cache-storage)
|
38
39
|
- [Atomic thread-safe value container](#atomic-thread-safe-value-container)
|
39
40
|
- [Any Object Frozener](#any-object-frozener) (classic c-level `frozen?`/`freeze`)
|
@@ -62,6 +63,23 @@ lock.synchronize { your_code }
|
|
62
63
|
|
63
64
|
---
|
64
65
|
|
66
|
+
### Read/Write Lock
|
67
|
+
|
68
|
+
- non-controlable reader count;
|
69
|
+
- readers does not lock each other;
|
70
|
+
- readers waits for writer;
|
71
|
+
- writer waits for readers;
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
lock = SmartCore::Engine::ReadWriteLock.new
|
75
|
+
|
76
|
+
lock.read_sync { ...some-read-op... } # waits for writer
|
77
|
+
lock.read_sync { ...some-read-op... } # waits for writer
|
78
|
+
lock.write_sync { ... some-write-op... } # waits for all readers and current writer
|
79
|
+
```
|
80
|
+
|
81
|
+
---
|
82
|
+
|
65
83
|
### Cache Storage
|
66
84
|
|
67
85
|
- you can use any object as a cache key;
|
@@ -275,6 +293,8 @@ end
|
|
275
293
|
- support for `#keys` method;
|
276
294
|
- support for `#key?` method;
|
277
295
|
- think about some layer of cache object serialization;
|
296
|
+
- `SmartCore::Engine::ReadWriteLock`:
|
297
|
+
- an ability to set a maximum count of readers;
|
278
298
|
|
279
299
|
---
|
280
300
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api public
|
4
|
+
# @since 0.14.0
|
5
|
+
class SmartCore::Engine::ReadWriteLock
|
6
|
+
# @return [void]
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
# @sicne 0.14.0
|
10
|
+
def initialize
|
11
|
+
# NOTE:
|
12
|
+
# ivars has no readers cuz we want to avoid
|
13
|
+
# Ruby VM's context-switching during reade-method invokation.
|
14
|
+
@active_reader = false
|
15
|
+
@write_lock = ::Mutex.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param block [Block]
|
19
|
+
# @return [Any]
|
20
|
+
#
|
21
|
+
# @api public
|
22
|
+
# @since 0.14.0
|
23
|
+
def read_sync(&block)
|
24
|
+
@active_reader = true
|
25
|
+
while @write_lock.locked? do; end
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
@active_reader = false
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param block [Block]
|
32
|
+
# @return [Any]
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
# @since 0.14.0
|
36
|
+
def write_sync(&block)
|
37
|
+
while @active_reader do; end
|
38
|
+
@write_lock.synchronize do
|
39
|
+
@active_reader = true
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
@active_reader = false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/smart_core/engine.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/smart_core/engine/ext.rb
|
124
124
|
- lib/smart_core/engine/frozener.rb
|
125
125
|
- lib/smart_core/engine/lock.rb
|
126
|
+
- lib/smart_core/engine/read_write_lock.rb
|
126
127
|
- lib/smart_core/engine/rescue_ext.rb
|
127
128
|
- lib/smart_core/engine/version.rb
|
128
129
|
- lib/smart_core/errors.rb
|