threadlock 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +13 -0
  4. data/lib/threadlock.rb +29 -0
  5. metadata +54 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e468f9ee53ba62c0e93e867676cd0b221333065
4
+ data.tar.gz: 64dd811925f0137922f72f2a1c6021a25d8ed0b7
5
+ SHA512:
6
+ metadata.gz: f85ac803a6a94032f89163c06bf0b926c059dc36272c0fb6de843f01730d3f26237674b16ab5da5b50b87d9553179a73919ae55311f5c143c79fe53522ca5fdc
7
+ data.tar.gz: 48e1909828e0a6aeff375d9ccc89774e0015d55b2ed55941bbbc4b97da55ac422fd3799e657dd97aed86e626dc30137d67af931edb2bd999681dbb1717ef27ca
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <year> <copyright holders>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ threadlock
2
+ ==========
3
+
4
+ Use the threadlock function in your class definition to automatically run instance methods inside of an instance-wide re-entrant lock (Monitor).
5
+
6
+ All locked methods in an instance are protect by a single lock. You can protect all or some of your methods from being run asynchronously. The goal is to be able to easily make basic objects threadsafe with as little thought and code as using the attr_accessor family of functions to make your instance attributes accessible.
7
+
8
+ The codebase is small and I intend to keep it that way, but bug reports and patches are welcome.
9
+
10
+ Enjoy.
11
+
12
+ Copyright 2013 : Joe McIlvain
13
+ MIT Licensed.
data/lib/threadlock.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'monitor'
2
+
3
+ def threadlock(*funcs)
4
+ for f in funcs.flatten
5
+ f2 = f.to_s
6
+ .gsub(/\=/, "_eQUAL")
7
+ .gsub(/\!/, "_nOT")
8
+ .gsub(/\~/, "_tILDE")
9
+ .gsub(/\</, "_lESS")
10
+ .gsub(/\>/, "_mORE")
11
+ .gsub(/\+/, "_aDD")
12
+ .gsub(/\-/, "_sUB")
13
+ .gsub(/\*/, "_mULT")
14
+ .gsub(/\//, "_dIV")
15
+ .gsub(/\//, "_mOD")
16
+ .gsub(/^/, "___")
17
+
18
+ class_eval\
19
+ ("
20
+ alias :#{f2} :#{f}
21
+ def #{f}(*args)
22
+ @___threadlock___ ||= Monitor.new
23
+ @___threadlock___.synchronize do
24
+ #{f2}(*args)
25
+ end
26
+ end
27
+ ")
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: threadlock
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe McIlvain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "Use the threadlock function in your class definition to automatically
14
+ run instance methods inside of an instance-wide re-entrant lock (Monitor). All
15
+ locked methods in an instance are protect by a single lock. You can protect all
16
+ or some of your methods from being run asynchronously. The goal is to be able to
17
+ easily make basic objects threadsafe with as little thought and code as using the
18
+ attr_accessor family of functions to make your instance attributes accessible. The
19
+ codebase is small and I intend to keep it that way, but bug reports and patches
20
+ are welcome. \n Enjoy."
21
+ email: joe.eli.mac@gmail.com
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - lib/threadlock.rb
27
+ - LICENSE
28
+ - README.md
29
+ homepage: https://github.com/jemc/threadlock/
30
+ licenses:
31
+ - MIT License
32
+ - Copyright 2013 Joe McIlvain
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.0.2
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: threadlock
54
+ test_files: []