tlopo-futex 0.1.0 → 0.1.1

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: b51aaa540ac3d6cb14a0eefb6d906a84aa11481044b19ca454531d49570cd209
4
- data.tar.gz: f96afdc48e141e80ef6f7d1513ef8b8eb4da89cb4ad6f5af88c1cbe0c56f8aa8
3
+ metadata.gz: 5ec8a84e0e591eb7b334bb93e18ea64b461897df65ba32bedeca4559e66df78f
4
+ data.tar.gz: ed879b97b4bce2c9c2fa8f4a3fc825d442dc4ed6b30a57d6df0119ba5576f2c4
5
5
  SHA512:
6
- metadata.gz: 1d1b04a20c69bf970ce9002f84da033dec7c8738dc9c6dda3403fd773c3b3cde9cbc63a06f019f4b468b5cc4877c3aee9a4802cabb6006ee73973685b639cf7e
7
- data.tar.gz: 62cb5d5d659b40811a298b4315651f718761bd5f74246d8cc6cd164ce0e723a76dbc9ecc76b90d498af357a5e609133d14f4c740e304fdb5a3dd46b9b12a885a
6
+ metadata.gz: 15ed9bb3c7f84b18030f7f5c54ba03ecc88913f98e2249ba7efd14927ea38c9dff0f269643eb199600c9a92524ef1b7fa2813fab9abd892844643c2e7b07d6b1
7
+ data.tar.gz: 332b4abe57e58d430c7df7b0cdfa3a8a370341ebf6ad2cbb275b3bbff38adc2cc4bcbd6354dfc5c7b891cf3faadc9c77bf6f9dfef4842233d579b8ea04b01ac1
data/README.md CHANGED
@@ -1,34 +1,83 @@
1
- # Tlopo::Futex
1
+ # TLOPO-Futex
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ **tlopo-futex** is a Ruby gem providing a simple interface for file-based locking. It enables mutual exclusion between processes to ensure safe access to shared resources.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tlopo/futex`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Features
6
+
7
+ - File-based locking mechanism
8
+ - `lock`, `release`, and `synchronize` methods for efficient, non-blocking resource handling
9
+ - Lightweight and reliable
6
10
 
7
11
  ## Installation
8
12
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
13
+ Add this line to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'tlopo-futex'
17
+ ```
10
18
 
11
- Install the gem and add to the application's Gemfile by executing:
19
+ Then run:
12
20
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```bash
22
+ bundle install
23
+ ```
14
24
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
25
+ Or install directly with:
16
26
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
27
+ ```bash
28
+ gem install tlopo-futex
29
+ ```
18
30
 
19
31
  ## Usage
20
32
 
21
- TODO: Write usage instructions here
33
+ ### Basic Lock and Unlock Example
34
+
35
+ ```ruby
36
+ require 'tlopo/futex'
37
+
38
+ # Initialize the lock with a path to a lock file
39
+ lock = Tlopo::Futex.new('/tmp/my_lock_file')
40
+
41
+ # Lock, execute critical code, then release
42
+ lock.lock
43
+ # Critical section code goes here
44
+ lock.release
45
+ ```
46
+
47
+ ### Checking Lock Status
48
+
49
+ You can check if the lock is currently active:
22
50
 
23
- ## Development
51
+ ```ruby
52
+ if lock.locked?
53
+ puts "Resource is locked by another process"
54
+ else
55
+ lock.lock
56
+ # Critical section code
57
+ lock.release
58
+ end
59
+ ```
24
60
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+ ### Using `synchronize` for Automatic Locking
26
62
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+ The `synchronize` method locks and releases automatically, ensuring that the lock is properly released even if an error occurs.
64
+
65
+ ```ruby
66
+ lock.synchronize do
67
+ # Critical section code that needs exclusive access
68
+ end
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/tlopo-ruby/tlopo-futex](https://github.com/tlopo-ruby/tlopo-futex).
74
+
75
+ ## License
28
76
 
77
+ This gem is available under the MIT License.
29
78
  ## Contributing
30
79
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tlopo-futex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tlopo-futex/blob/main/CODE_OF_CONDUCT.md).
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tlopo-ruby/tlopo-futex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tlopo-ruby/tlopo-futex/blob/main/CODE_OF_CONDUCT.md).
32
81
 
33
82
  ## License
34
83
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tlopo
4
4
  class Futex
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
data/lib/tlopo/futex.rb CHANGED
@@ -25,6 +25,7 @@ module Tlopo
25
25
  def release
26
26
  @fh.flock File::LOCK_UN
27
27
  @fh.close
28
+ rescue IOError
28
29
  end
29
30
 
30
31
  def synchronize
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlopo-futex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tlopo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-28 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File based mutual exclusive lock
14
14
  email: