File tree Expand file tree Collapse file tree 1 file changed +29
-14
lines changed Expand file tree Collapse file tree 1 file changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -28,41 +28,52 @@ def initialize
28
28
#
29
29
# @return [Boolean] indicating whether or not the `Event` has been set
30
30
def set?
31
- @mutex . synchronize do
32
- @set
33
- end
31
+ @mutex . lock
32
+ result = @set
33
+ @mutex . unlock
34
+
35
+ result
34
36
end
35
37
36
38
# Trigger the event, setting the state to `set` and releasing all threads
37
39
# waiting on the event. Has no effect if the `Event` has already been set.
38
40
#
39
41
# @return [Boolean] should always return `true`
40
42
def set
41
- @mutex . synchronize do
42
- return true if @set
43
+ @mutex . lock
44
+ unless @set
43
45
@set = true
44
46
@condition . broadcast
45
47
end
48
+ @mutex . unlock
46
49
47
50
true
48
51
end
49
52
50
53
def try?
51
- @mutex . synchronize do
52
- return false if @set
54
+ @mutex . lock
55
+
56
+ if @set
57
+ result = false
58
+ else
53
59
@set = true
54
60
@condition . broadcast
61
+ result = true
55
62
end
63
+
64
+ @mutex . unlock
65
+
66
+ result
56
67
end
57
68
58
69
# Reset a previously set event back to the `unset` state.
59
70
# Has no effect if the `Event` has not yet been set.
60
71
#
61
72
# @return [Boolean] should always return `true`
62
73
def reset
63
- @mutex . synchronize do
64
- @set = false
65
- end
74
+ @mutex . lock
75
+ @set = false
76
+ @mutex . unlock
66
77
67
78
true
68
79
end
@@ -73,16 +84,20 @@ def reset
73
84
#
74
85
# @return [Boolean] true if the `Event` was set before timeout else false
75
86
def wait ( timeout = nil )
76
- @mutex . synchronize do
77
- return true if @set
87
+ @mutex . lock
78
88
89
+ unless @set
79
90
remaining = Condition ::Result . new ( timeout )
80
91
while !@set && remaining . can_wait?
81
92
remaining = @condition . wait ( @mutex , remaining . remaining_time )
82
93
end
83
-
84
- @set
85
94
end
95
+
96
+ result = @set
97
+
98
+ @mutex . unlock
99
+
100
+ result
86
101
end
87
102
end
88
103
end
You can’t perform that action at this time.
0 commit comments