smart_engine 0.13.0 → 0.15.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: 571c427f764fe322ccc465dbe90d760ffde9ffa324bd55a15e6046da6a18909f
4
+ data.tar.gz: 446a429d3c440bfa0bc1bc16a3abdb58289810d56bd7eec86b66307c59c5227a
5
5
  SHA512:
6
- metadata.gz: dda02f4e36e5c85f3a1117ba85013ab99120956166501c31e0178f6f58898a8a9fb87a585d80a1d9174d5f0eca72139e954bb73a1b0ea72dd7d79a36a41636e8
7
- data.tar.gz: 905bb7bea34f0d101633dd64e0709f50671d81eaa8ed0b7d5880892f760e62a038605173936ea9d27f8e51680d11495f5b1de0cfefd57490450a67f7ebc3ec69
6
+ metadata.gz: 3493139baf67304edaa0fd7db320987b6ed860efc2d80e393a1baa73d590cd0b63e80e0069430bc3d286f7bcf095161ea51782643792ce0a4f3b8dca4e5e9ce5
7
+ data.tar.gz: 7702c746ab952d345e935a40a51d581f8f2ecb81f8f12c867e295813e74df9f08bd7b7db31b644194fe6e5e428026577c33de2e17e37a1287c2f6dd42781a20e
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [Unreleased]
4
+ ## [0.15.0] - 2022-09-30
5
+ ### Added
6
+ - `SmartCore::Engine::ReadWriteLock#write_owned?` - checking that write lock is owned by current thread or not;
7
+
8
+ ## [0.14.0] - 2022-09-30
9
+ ### Added
10
+ - Read/Write locking mechanizm: `SmartCore::Engine::ReadWriteLock`;
11
+
12
+ ## [0.13.0] - 2022-09-30
5
13
  ### Added
6
14
  - Simplest in-memory cache storage implementation: `SmartCore::Engine::Cache`;
7
15
  ### 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.15.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,26 @@ 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
+ # is write_sync lock is owned by current thread?
81
+ lock.write_owned? # true or false
82
+ ```
83
+
84
+ ---
85
+
65
86
  ### Cache Storage
66
87
 
67
88
  - you can use any object as a cache key;
@@ -275,6 +296,8 @@ end
275
296
  - support for `#keys` method;
276
297
  - support for `#key?` method;
277
298
  - think about some layer of cache object serialization;
299
+ - `SmartCore::Engine::ReadWriteLock`:
300
+ - an ability to set a maximum count of readers;
278
301
 
279
302
  ---
280
303
 
@@ -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,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api public
4
+ # @since 0.14.0
5
+ # @version 0.15.0
6
+ class SmartCore::Engine::ReadWriteLock
7
+ # @return [void]
8
+ #
9
+ # @api public
10
+ # @sicne 0.14.0
11
+ def initialize
12
+ # NOTE:
13
+ # ivars has no readers cuz we want to avoid
14
+ # Ruby VM's context-switching during reade-method invokation.
15
+ @active_reader = false
16
+ @write_lock = ::Mutex.new
17
+ end
18
+
19
+ # @param block [Block]
20
+ # @return [Any]
21
+ #
22
+ # @api public
23
+ # @since 0.14.0
24
+ def read_sync(&block)
25
+ @active_reader = true
26
+ while @write_lock.locked? do; end
27
+ yield
28
+ ensure
29
+ @active_reader = false
30
+ end
31
+
32
+ # @return [Boolean]
33
+ #
34
+ # @api public
35
+ # @since 0.15.0
36
+ def write_owned?
37
+ @write_lock.owned?
38
+ end
39
+
40
+ # @param block [Block]
41
+ # @return [Any]
42
+ #
43
+ # @api public
44
+ # @since 0.14.0
45
+ def write_sync(&block)
46
+ while @active_reader do; end
47
+ @write_lock.synchronize do
48
+ @active_reader = true
49
+ begin
50
+ yield
51
+ ensure
52
+ @active_reader = false
53
+ end
54
+ end
55
+ end
56
+ 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.15.0
10
+ VERSION = '0.15.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.15.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