futex 0.6.0 → 0.6.1
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/.rubocop.yml +3 -1
- data/futex.gemspec +1 -1
- data/lib/futex.rb +4 -0
- data/test/test_futex.rb +9 -0
- 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: 729dc25954a8a169668ca2d458d24156c8b4d2555a5945714ededf99fadad3fe
         | 
| 4 | 
            +
              data.tar.gz: 82fb28cad4a9ad74152ebb4e5160971a66d14b0897c952297a69868ee2b0a067
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 43337117eab085f589235a636f33fc801a27b21378011ff199a805fd213f9df7a5c6c2e90467290547184f0777ecc58a3c2a77a06c5d562f7d4eae1f62dacf4d
         | 
| 7 | 
            +
              data.tar.gz: 024ddc3edc4bcf35beb17f468867d8f9d4feccf1214e8ba4f05f3c9718770653edf70fc8060f47c0ddb9637241e3a837915e6ea926d6e5b669f8d3082f6adec9
         | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/futex.gemspec
    CHANGED
    
    | @@ -31,7 +31,7 @@ Gem::Specification.new do |s| | |
| 31 31 | 
             
              s.rubygems_version = '2.3.3'
         | 
| 32 32 | 
             
              s.required_ruby_version = '>=2.3'
         | 
| 33 33 | 
             
              s.name = 'futex'
         | 
| 34 | 
            -
              s.version = '0.6. | 
| 34 | 
            +
              s.version = '0.6.1'
         | 
| 35 35 | 
             
              s.license = 'MIT'
         | 
| 36 36 | 
             
              s.summary = 'File-based mutex'
         | 
| 37 37 | 
             
              s.description = 'Ruby Gem for file-based locking'
         | 
    
        data/lib/futex.rb
    CHANGED
    
    | @@ -76,6 +76,8 @@ class Futex | |
| 76 76 | 
             
                  cycle = 0
         | 
| 77 77 | 
             
                  loop do
         | 
| 78 78 | 
             
                    if f.flock((exclusive ? File::LOCK_EX : File::LOCK_SH) | File::LOCK_NB)
         | 
| 79 | 
            +
                      Thread.current.thread_variable_set(:futex_cycle, nil)
         | 
| 80 | 
            +
                      Thread.current.thread_variable_set(:futex_time, nil)
         | 
| 79 81 | 
             
                      break
         | 
| 80 82 | 
             
                    end
         | 
| 81 83 | 
             
                    sleep(@sleep)
         | 
| @@ -98,6 +100,8 @@ access to #{@path}, #{age(start)} already: #{IO.read(@lock)}") | |
| 98 100 | 
             
                  acq = Time.now
         | 
| 99 101 | 
             
                  res = yield(@path)
         | 
| 100 102 | 
             
                  debug("Unlocked by #{b} in #{age(acq)}, #{prefix}exclusive: #{@path}")
         | 
| 103 | 
            +
                  Thread.current.thread_variable_set(:futex_lock, nil)
         | 
| 104 | 
            +
                  Thread.current.thread_variable_set(:futex_badge, nil)
         | 
| 101 105 | 
             
                  res
         | 
| 102 106 | 
             
                end
         | 
| 103 107 | 
             
              end
         | 
    
        data/test/test_futex.rb
    CHANGED
    
    | @@ -141,6 +141,15 @@ class FutexTest < Minitest::Test | |
| 141 141 | 
             
                end
         | 
| 142 142 | 
             
              end
         | 
| 143 143 |  | 
| 144 | 
            +
              def test_removes_thread_vars
         | 
| 145 | 
            +
                Dir.mktmpdir do |dir|
         | 
| 146 | 
            +
                  Futex.new(File.join(dir, 'hey.txt')).open do |f|
         | 
| 147 | 
            +
                    # nothing
         | 
| 148 | 
            +
                  end
         | 
| 149 | 
            +
                  assert(Thread.current.thread_variable_get(:futex_lock).nil?)
         | 
| 150 | 
            +
                end
         | 
| 151 | 
            +
              end
         | 
| 152 | 
            +
             | 
| 144 153 | 
             
              def test_saves_calling_file_name_in_lock
         | 
| 145 154 | 
             
                Dir.mktmpdir do |dir|
         | 
| 146 155 | 
             
                  Futex.new(File.join(dir, 'hey.txt')).open do |f|
         |