smart_engine 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +9 -1
 - data/Gemfile.lock +1 -1
 - data/README.md +23 -0
 - data/lib/smart_core/engine/lock.rb +1 -1
 - data/lib/smart_core/engine/read_write_lock.rb +56 -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: 571c427f764fe322ccc465dbe90d760ffde9ffa324bd55a15e6046da6a18909f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 446a429d3c440bfa0bc1bc16a3abdb58289810d56bd7eec86b66307c59c5227a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
            ## [ 
     | 
| 
      
 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
    
    
    
        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 
     | 
    
         | 
| 
         @@ -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
         
     | 
    
        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.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
         
     |