tsafe 0.0.5 → 0.0.6
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.
- data/VERSION +1 -1
- data/lib/tsafe_monarray.rb +3 -3
- data/lib/tsafe_monhash.rb +3 -3
- data/lib/tsafe_monitored.rb +3 -3
- data/lib/tsafe_mrswlock.rb +7 -7
- data/lib/tsafe_mutexed.rb +3 -3
- data/lib/tsafe_proxy.rb +6 -6
- data/spec/mrswlock_spec.rb +8 -2
- data/tsafe.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/tsafe_monarray.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#Predefined synchronized array.
|
2
2
|
#
|
3
3
|
#===Examples
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# arr = Tsafe::MonArray.new
|
5
|
+
# arr << 5
|
6
|
+
# ret = arr[0]
|
7
7
|
class Tsafe::MonArray < ::Array
|
8
8
|
@@tsafe_rwmutex_w_methods = [:<<, :collect, :collect!, :compact!, :delete, :delete_at, :delete_if, :drop, :drop_while, :fill, :flatten!, :insert, :keep_if, :map, :map!, :replace, :shuffle!, :slice!, :shift, :sort!, :sort_by!, :unshift]
|
9
9
|
@@tsafe_rwmutex_r_methods = [:each, :each_index, :take_while]
|
data/lib/tsafe_monhash.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#Predefined synchronized hash.
|
2
2
|
#
|
3
3
|
#===Examples
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# h = Tsafe::MonHash.new
|
5
|
+
# h['test'] = 'trala'
|
6
|
+
# ret = h['test']
|
7
7
|
class Tsafe::MonHash < ::Hash
|
8
8
|
@@tsafe_mrswlock_w_methods = [:[]=, :clear, :delete, :delete_if, :keep_if, :merge!, :rehash, :reject!, :replace, :select!, :shift, :store, :update, :values_at]
|
9
9
|
@@tsafe_mrswlock_r_methods = [:each, :each_key, :each_pair, :each_value]
|
data/lib/tsafe_monitored.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#This module can be included on a class to make all method-calls synchronized (by using monitor). Examples with array and hash are below.
|
2
2
|
#
|
3
3
|
#===Examples
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# class MySyncedClass < SomeOtherClassThatNeedsToBeSynchronized
|
5
|
+
# include Tsafe::Monitored
|
6
|
+
# end
|
7
7
|
module Tsafe::Monitored
|
8
8
|
def self.included(base)
|
9
9
|
base.to_s.split("::").inject(Object, :const_get).class_eval do
|
data/lib/tsafe_mrswlock.rb
CHANGED
@@ -34,8 +34,8 @@ class Tsafe::Mrswlock
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
38
|
-
|
37
|
+
#Runs the given block through the write-synchronization (locks both reading and writing).
|
38
|
+
#===Examples
|
39
39
|
# lock.wsync do
|
40
40
|
# #do something within lock.
|
41
41
|
# end
|
@@ -65,11 +65,11 @@ class Tsafe::Mrswlock
|
|
65
65
|
|
66
66
|
#This module can be included in order to painlessly make a thread-safe multi-reader-single-writer thread-safe copy of a class.
|
67
67
|
#===Examples
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
68
|
+
# class Tsafe::MonHash < ::Hash
|
69
|
+
# @@tsafe_mrswlock_w_methods = [:[]=, :clear, :delete, :delete_if, :keep_if, :merge!, :rehash, :reject!, :replace, :select!, :shift, :store, :update, :values_at]
|
70
|
+
# @@tsafe_mrswlock_r_methods = [:each, :each_key, :each_pair, :each_value]
|
71
|
+
# include Tsafe::Mrswlock::SynModule
|
72
|
+
# end
|
73
73
|
module SynModule
|
74
74
|
def self.included(base)
|
75
75
|
base.to_s.split("::").inject(Object, :const_get).class_eval do
|
data/lib/tsafe_mutexed.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#This module can be included on a class to make all method-calls synchronized (by using mutex). Examples with array and hash are below.
|
2
2
|
#
|
3
3
|
#===Examples
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# class MySyncedClass < SomeOtherClassThatNeedsToBeSynchronized
|
5
|
+
# include Tsafe::Mutexed
|
6
|
+
# end
|
7
7
|
module Tsafe::Mutexed
|
8
8
|
def self.included(base)
|
9
9
|
base.to_s.split("::").inject(Object, :const_get).class_eval do
|
data/lib/tsafe_proxy.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#Instances of this class proxies calls to a given-object by using a mutex or monitor.
|
2
2
|
#
|
3
3
|
#==== Examples
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
4
|
+
# threadsafe_array = Tsafe::Proxy.new(:obj => [])
|
5
|
+
# threadsafe_array << 5
|
6
|
+
# ret = threadsafe_array[0]
|
7
|
+
#
|
8
|
+
# threadsafe_array = Tsafe::Proxy.new(:obj => [], :monitor => true)
|
9
9
|
class Tsafe::Proxy
|
10
|
-
#
|
10
|
+
#Spawns needed vars.
|
11
11
|
def initialize(args)
|
12
12
|
if args[:monitor]
|
13
13
|
@mutex = Monitor.new
|
data/spec/mrswlock_spec.rb
CHANGED
@@ -14,14 +14,20 @@ describe "Tsafe::Rwmutex" do
|
|
14
14
|
hash[realcount] = realcount
|
15
15
|
end
|
16
16
|
|
17
|
+
called = false
|
17
18
|
hash._tsafe_rsync do
|
18
|
-
|
19
|
+
called = true
|
19
20
|
end
|
20
21
|
|
22
|
+
raise "Expected to be called." if !called
|
23
|
+
|
24
|
+
called = false
|
21
25
|
hash._tsafe_wsync do
|
22
|
-
|
26
|
+
called = true
|
23
27
|
end
|
24
28
|
|
29
|
+
raise "Expected to be called." if !called
|
30
|
+
|
25
31
|
ts = []
|
26
32
|
|
27
33
|
1.upto(10) do |tcount|
|
data/tsafe.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tsafe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
hash:
|
103
|
+
hash: 1466962052017061704
|
104
104
|
segments:
|
105
105
|
- 0
|
106
106
|
version: "0"
|