senotrusov-ruby-threading-toolkit 1.0.1 → 1.0.2

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.
@@ -21,6 +21,8 @@ class SmartQueue
21
21
  @arrived = ConditionVariable.new
22
22
  @shifted = ConditionVariable.new
23
23
 
24
+ @persistent = false
25
+
24
26
  if dumped && (dumped = Marshal.restore(dumped))
25
27
  @regular = dumped[:regular]
26
28
  @priority = dumped[:priority]
@@ -34,6 +36,8 @@ class SmartQueue
34
36
  @stop_list = {}
35
37
  end
36
38
 
39
+ attr_accessor :persistent
40
+
37
41
  def release_blocked thread
38
42
  @mutex.synchronize do
39
43
  # Cleaning up @stop_list right here, so, at maximum, it holds only one dead thread.
@@ -101,7 +105,42 @@ class SmartQueue
101
105
  end
102
106
  end
103
107
  end
108
+
109
+ def select
110
+ @mutex.synchronize do
111
+ result = []
112
+
113
+ unless @priority.empty?
114
+ @priority.reject! { |item| result.push(item) if yield(item) }
115
+ end
116
+
117
+ unless @regular.empty?
118
+ @shifted.signal if @regular.reject! { |item| result.push(item) if yield(item) }
119
+ end
120
+
121
+ return result
122
+ end
123
+ end
104
124
 
125
+ def flush
126
+ @mutex.synchronize do
127
+ result = []
128
+
129
+ unless @priority.empty?
130
+ result += @priority
131
+ @priority.clear
132
+ end
133
+
134
+ unless @regular.empty?
135
+ result += @regular
136
+ @regular.clear
137
+ @shifted.signal
138
+ end
139
+
140
+ return result
141
+ end
142
+ end
143
+
105
144
  def empty?
106
145
  @mutex.synchronize do
107
146
  @regular.empty? && @priority.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senotrusov-ruby-threading-toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Senotrusov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-23 00:00:00 -07:00
12
+ date: 2009-07-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/ruby-threading-toolkit.rb
56
56
  has_rdoc: false
57
57
  homepage: http://github.com/senotrusov
58
+ licenses:
58
59
  post_install_message:
59
60
  rdoc_options:
60
61
  - --inline-source
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements: []
77
78
 
78
79
  rubyforge_project:
79
- rubygems_version: 1.2.0
80
+ rubygems_version: 1.3.5
80
81
  signing_key:
81
82
  specification_version: 3
82
83
  summary: Ruby multithreading development helpers