# frozen_string_literal: false
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
# patched by akira yamada
# When 'mutex_m' is required, any object that extends or includes Mutex_m will
# be treated like a Mutex.
# Start by requiring the standard library Mutex_m:
# From here you can extend an object with Mutex instance methods:
# Or mixin Mutex_m into your module to your class inherit Mutex instance
# methods --- remember to call super() in your class initialize method.
# # this obj can be handled like Mutex
Ractor.make_shareable(VERSION) if defined?(Ractor)
def Mutex_m.define_aliases(cl) # :nodoc:
alias try_lock mu_try_lock
alias synchronize mu_synchronize
def Mutex_m.append_features(cl) # :nodoc:
define_aliases(cl) unless cl.instance_of?(Module)
def Mutex_m.extend_object(obj) # :nodoc:
def mu_extended # :nodoc:
unless (defined? locked? and
Mutex_m.define_aliases(singleton_class)
# See Thread::Mutex#synchronize
def mu_synchronize(&block)
@_mutex.synchronize(&block)
# See Thread::Mutex#locked?
# See Thread::Mutex#try_lock
# See Thread::Mutex#unlock
# See Thread::Mutex#sleep
def mu_initialize # :nodoc:
@_mutex = Thread::Mutex.new
def initialize(*args) # :nodoc:
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)