Skip to content

Commit 0d12153

Browse files
committed
Refactored more ReadWriteLock bitwise operations into method calls.
1 parent f2c77de commit 0d12153

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/concurrent/atomic/read_write_lock.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ def acquire_write_lock
185185
# Then we are OK to stop waiting and go ahead
186186
# Otherwise go back and wait again
187187
c = @counter.value
188-
break if (c < RUNNING_WRITER) &&
189-
((c & MAX_READERS) == 0) &&
188+
break if !running_writer?(c) && !running_readers?(c) &&
190189
@counter.compare_and_swap(c,c+RUNNING_WRITER-WAITING_WRITER)
191190
end
192191
break
@@ -244,12 +243,12 @@ def has_waiters?
244243
private
245244

246245
# @!visibility private
247-
def running_readers(c)
246+
def running_readers(c = @counter.value)
248247
c & MAX_READERS
249248
end
250249

251250
# @!visibility private
252-
def running_readers?(c)
251+
def running_readers?(c = @counter.value)
253252
(c & MAX_READERS) > 0
254253
end
255254

@@ -259,7 +258,7 @@ def running_writer?(c = @counter.value)
259258
end
260259

261260
# @!visibility private
262-
def waiting_writers(c)
261+
def waiting_writers(c = @counter.value)
263262
(c & MAX_WRITERS) / WAITING_WRITER
264263
end
265264

@@ -269,12 +268,12 @@ def waiting_writer?(c = @counter.value)
269268
end
270269

271270
# @!visibility private
272-
def max_readers?(c)
271+
def max_readers?(c = @counter.value)
273272
(c & MAX_READERS) == MAX_READERS
274273
end
275274

276275
# @!visibility private
277-
def max_writers?(c)
276+
def max_writers?(c = @counter.value)
278277
(c & MAX_WRITERS) == MAX_WRITERS
279278
end
280279
end

0 commit comments

Comments
 (0)