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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48de1362f022e1e37a6a234db4936b0077c9d5cc818ac2bb73a72157f4b949dc
4
- data.tar.gz: cf4e6d5a6c51d926fc6d5186d0857006d7a114811be4d4f753283e1872575cdf
3
+ metadata.gz: 912e841987ba6da79b04609e0f86580d900676b10711d5e38b614099782702cf
4
+ data.tar.gz: 395c81f467a482cde8042dfb207df5aa70b7a865f317fcd068e110b127dfe95e
5
5
  SHA512:
6
- metadata.gz: dda02f4e36e5c85f3a1117ba85013ab99120956166501c31e0178f6f58898a8a9fb87a585d80a1d9174d5f0eca72139e954bb73a1b0ea72dd7d79a36a41636e8
7
- data.tar.gz: 905bb7bea34f0d101633dd64e0709f50671d81eaa8ed0b7d5880892f760e62a038605173936ea9d27f8e51680d11495f5b1de0cfefd57490450a67f7ebc3ec69
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
- ## [Unreleased]
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_engine (0.13.0)
4
+ smart_engine (0.14.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -8,7 +8,7 @@ class SmartCore::Engine::Lock
8
8
  # @api public
9
9
  # @since 0.4.0
10
10
  def initialize
11
- @lock = Mutex.new
11
+ @lock = ::Mutex.new
12
12
  end
13
13
 
14
14
  # @param block [Block]
@@ -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
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.13.0
10
- VERSION = '0.13.0'
9
+ # @version 0.14.0
10
+ VERSION = '0.14.0'
11
11
  end
12
12
  end
@@ -5,6 +5,7 @@
5
5
  module SmartCore::Engine
6
6
  require_relative 'engine/version'
7
7
  require_relative 'engine/lock'
8
+ require_relative 'engine/read_write_lock'
8
9
  require_relative 'engine/rescue_ext'
9
10
  require_relative 'engine/atom'
10
11
  require_relative 'engine/frozener'
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.13.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