threadlock 1.3.2 → 2.0.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/USAGE.rb +6 -0
- data/lib/threadlock.rb +17 -8
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f4d9ebbc0fa0fd4dd7c28101f899614b7819cf4
|
4
|
+
data.tar.gz: 9cac3c19d6a2b5506ce1a221011e0b9cb6ef9b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0071aa7664651818f98bb1f53100d4c1d3bb996c5f3fa2c5bf09e01787d94991f8bc7affedc73ac88ba0e4b3baa5103c1dfa6365dc87ffd399d0bc0c32fdf41e
|
7
|
+
data.tar.gz: cd58382a5f462ebd020ee8b24c8506cc85bdf4aa98ed26eb88e5f6b0aa5c3402084f9bb0d0607e60ac56569ff30d0a4aeda29ffd0e4e4d3e56538d2391133612
|
data/USAGE.rb
CHANGED
@@ -3,6 +3,7 @@ require 'threadlock'
|
|
3
3
|
|
4
4
|
|
5
5
|
class Example1
|
6
|
+
include Threadlock
|
6
7
|
|
7
8
|
def foo
|
8
9
|
@foo = true
|
@@ -28,6 +29,7 @@ end
|
|
28
29
|
|
29
30
|
|
30
31
|
class Example2
|
32
|
+
include Threadlock
|
31
33
|
|
32
34
|
def foo
|
33
35
|
@foo = true
|
@@ -52,6 +54,7 @@ end
|
|
52
54
|
|
53
55
|
|
54
56
|
class Example3
|
57
|
+
include Threadlock
|
55
58
|
|
56
59
|
def foo
|
57
60
|
@foo = true
|
@@ -76,6 +79,7 @@ end
|
|
76
79
|
|
77
80
|
|
78
81
|
class Example4
|
82
|
+
include Threadlock
|
79
83
|
|
80
84
|
def foo
|
81
85
|
@foo = true
|
@@ -101,6 +105,7 @@ end
|
|
101
105
|
|
102
106
|
|
103
107
|
class Example5
|
108
|
+
include Threadlock
|
104
109
|
|
105
110
|
def initialize
|
106
111
|
@custom_lock_name = Mutex.new
|
@@ -129,6 +134,7 @@ end
|
|
129
134
|
|
130
135
|
|
131
136
|
class Example6 # Ruby 2.1 only
|
137
|
+
include Threadlock
|
132
138
|
|
133
139
|
# Ruby 2.1 only: wrap new method foo in a re-entrant lock
|
134
140
|
threadlock def foo
|
data/lib/threadlock.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
+
|
1
2
|
require 'monitor'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Threadlock
|
5
|
+
|
6
|
+
def self.included(mod)
|
7
|
+
mod.extend Threadlock
|
8
|
+
end
|
9
|
+
|
10
|
+
def threadlock(*meths, lock: :@___threadlock___)
|
11
|
+
meths.flatten.each do |meth|
|
12
|
+
m = instance_method(meth)
|
13
|
+
define_method(meth) do |*args, &block|
|
14
|
+
(instance_variable_get(lock) or \
|
15
|
+
instance_variable_set(lock, Monitor.new))
|
16
|
+
.synchronize do
|
17
|
+
m.bind(self).call(*args, &block)
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|
22
|
+
|
14
23
|
end
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threadlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: "Use the threadlock method in your class definition to automatically
|
14
14
|
run instance methods inside of an instance-wide re-entrant lock (Monitor). All
|
15
|
-
locked methods in an instance are
|
16
|
-
or some of your methods from being run
|
17
|
-
can also be
|
15
|
+
locked methods in an instance are protected by a single lock, unless a specific
|
16
|
+
lock is specified. You can protect all or some of your methods from being run concurrently.
|
17
|
+
\ In Ruby>=2.1, threadlock can also be used as a syntactic decorator. \n Enjoy."
|
18
18
|
email: joe.eli.mac@gmail.com
|
19
19
|
executables: []
|
20
20
|
extensions: []
|
@@ -50,3 +50,4 @@ signing_key:
|
|
50
50
|
specification_version: 4
|
51
51
|
summary: 'threadlock: Easy, featherweight thread protection for basic ruby objects.'
|
52
52
|
test_files: []
|
53
|
+
has_rdoc:
|