Method: FSDB::Modex#try_lock

Defined in:
lib/fsdb/modex.rb

#try_lock(mode) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fsdb/modex.rb', line 21

def try_lock mode
  @m.synchronize do
    thread = Thread.current
    raise ThreadError, "nesting not allowed" if @locked.include?(thread)

    if @mode == mode and mode == SH and @waiting.empty? # strict queue
      @locked << thread
      true
    elsif not @mode
      @mode = mode
      @locked << thread
      true
    else
      false
    end
  end
end