dguettler-god 0.7.13.2 → 0.7.13.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/god/driver.rb +10 -25
- metadata +1 -1
data/lib/god/driver.rb
CHANGED
@@ -61,7 +61,6 @@ module God
|
|
61
61
|
@waiting.taint
|
62
62
|
@events.taint
|
63
63
|
self.taint
|
64
|
-
@mutex = Mutex.new
|
65
64
|
end
|
66
65
|
|
67
66
|
#
|
@@ -69,13 +68,8 @@ module God
|
|
69
68
|
#
|
70
69
|
def shutdown
|
71
70
|
@shutdown = true
|
72
|
-
|
73
|
-
|
74
|
-
@waiting.each do |t|
|
75
|
-
t.run
|
76
|
-
end
|
77
|
-
ensure
|
78
|
-
@mutex.unlock
|
71
|
+
@waiting.each do |t|
|
72
|
+
t.run
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
@@ -83,22 +77,16 @@ module God
|
|
83
77
|
# Sleep until the queue has something due
|
84
78
|
#
|
85
79
|
def pop
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if @
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
@mutex.unlock
|
94
|
-
sleep @events.first.at - Time.now
|
95
|
-
@mutex.lock
|
96
|
-
end
|
80
|
+
while (@events.empty? or !@events.first.due?)
|
81
|
+
@waiting.push Thread.current
|
82
|
+
if @events.empty?
|
83
|
+
raise ThreadError, "queue empty" if @shutdown
|
84
|
+
Thread.stop
|
85
|
+
else
|
86
|
+
sleep @events.first.at - Time.now
|
97
87
|
end
|
98
|
-
@events.shift
|
99
|
-
ensure
|
100
|
-
@mutex.unlock
|
101
88
|
end
|
89
|
+
@events.shift
|
102
90
|
end
|
103
91
|
|
104
92
|
alias shift pop
|
@@ -109,7 +97,6 @@ module God
|
|
109
97
|
# happen sooner than the next pending event
|
110
98
|
#
|
111
99
|
def push(event)
|
112
|
-
@mutex.lock
|
113
100
|
@events << event
|
114
101
|
@events.sort!
|
115
102
|
begin
|
@@ -117,8 +104,6 @@ module God
|
|
117
104
|
t.wakeup if t
|
118
105
|
rescue ThreadError
|
119
106
|
retry
|
120
|
-
ensure
|
121
|
-
@mutex.unlock
|
122
107
|
end
|
123
108
|
begin
|
124
109
|
t.run if t
|