summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2024-01-09 16:33:30 +0900
committerHiroshi SHIBATA <[email protected]>2024-01-10 17:28:16 +0900
commitd16f992e1bfacb638b8a9b8b5a7ef8149ee1d50d (patch)
tree007fc47989240247a1f61d5bf52cd30171455260
parente59a7304779c6a51a89ff39695743a470f086c4e (diff)
Extract mutex_m as bundled gems
-rw-r--r--doc/maintainers.md8
-rw-r--r--doc/standard_library.rdoc2
-rw-r--r--lib/mutex_m.gemspec28
-rw-r--r--lib/mutex_m.rb116
-rw-r--r--test/test_mutex_m.rb79
5 files changed, 4 insertions, 229 deletions
diff --git a/doc/maintainers.md b/doc/maintainers.md
index 631371e178..e879034209 100644
--- a/doc/maintainers.md
+++ b/doc/maintainers.md
@@ -181,11 +181,6 @@ have commit right, others don't.
* https://github.com/ruby/logger
* https://rubygems.org/gems/logger
-#### lib/mutex_m.rb
-* Keiju ISHITSUKA (keiju)
-* https://github.com/ruby/mutex_m
-* https://rubygems.org/gems/mutex_m
-
#### lib/net/http.rb, lib/net/https.rb
* NARUSE, Yui (naruse)
* https://github.com/ruby/net-http
@@ -487,6 +482,9 @@ have commit right, others don't.
### racc
* https://github.com/ruby/racc
+#### mutex_m
+* https://github.com/ruby/mutex_m
+
## Platform Maintainers
### mswin64 (Microsoft Windows)
diff --git a/doc/standard_library.rdoc b/doc/standard_library.rdoc
index 2282d7226b..d0a7ba4207 100644
--- a/doc/standard_library.rdoc
+++ b/doc/standard_library.rdoc
@@ -53,7 +53,6 @@ IPAddr:: Provides methods to manipulate IPv4 and IPv6 IP addresses
IRB:: Interactive Ruby command-line tool for REPL (Read Eval Print Loop)
OptionParser:: Ruby-oriented class for command-line option analysis
Logger:: Provides a simple logging utility for outputting messages
-Mutex_m:: Mixin to extend objects to be handled like a Mutex
Net::HTTP:: HTTP client api for Ruby
Observable:: Provides a mechanism for publish/subscribe pattern in Ruby
Open3:: Provides access to stdin, stdout and stderr when running other programs
@@ -130,3 +129,4 @@ RBS:: RBS is a language to describe the structure of Ruby programs
TypeProf:: A type analysis tool for Ruby code based on abstract interpretation
DEBUGGER__:: Debugging functionality for Ruby
Racc:: A LALR(1) parser generator written in Ruby.
+Mutex_m:: Mixin to extend objects to be handled like a Mutex
diff --git a/lib/mutex_m.gemspec b/lib/mutex_m.gemspec
deleted file mode 100644
index ebbda2606c..0000000000
--- a/lib/mutex_m.gemspec
+++ /dev/null
@@ -1,28 +0,0 @@
-begin
- require_relative "lib/mutex_m"
-rescue LoadError
- # for Ruby core repository
- require_relative "mutex_m"
-end
-
-Gem::Specification.new do |spec|
- spec.name = "mutex_m"
- spec.version = Mutex_m::VERSION
- spec.authors = ["Keiju ISHITSUKA"]
- spec.email = ["[email protected]"]
-
- spec.summary = %q{Mixin to extend objects to be handled like a Mutex.}
- spec.description = %q{Mixin to extend objects to be handled like a Mutex.}
- spec.homepage = "https://github.com/ruby/mutex_m"
- spec.licenses = ["Ruby", "BSD-2-Clause"]
-
- spec.files = ["Gemfile", "LICENSE.txt", "README.md", "Rakefile", "lib/mutex_m.rb", "mutex_m.gemspec"]
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
- spec.require_paths = ["lib"]
- spec.required_ruby_version = '>= 2.5'
-
- spec.add_development_dependency "bundler"
- spec.add_development_dependency "rake"
- spec.add_development_dependency "test-unit"
-end
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
deleted file mode 100644
index 7e55181881..0000000000
--- a/lib/mutex_m.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-# frozen_string_literal: false
-#
-# mutex_m.rb -
-# $Release Version: 3.0$
-# $Revision: 1.7 $
-# Original from mutex.rb
-# by Keiju ISHITSUKA([email protected])
-# modified by matz
-# patched by akira yamada
-#
-# --
-
-# = mutex_m.rb
-#
-# 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:
-#
-# require "mutex_m.rb"
-#
-# From here you can extend an object with Mutex instance methods:
-#
-# obj = Object.new
-# obj.extend Mutex_m
-#
-# Or mixin Mutex_m into your module to your class inherit Mutex instance
-# methods --- remember to call super() in your class initialize method.
-#
-# class Foo
-# include Mutex_m
-# def initialize
-# # ...
-# super()
-# end
-# # ...
-# end
-# obj = Foo.new
-# # this obj can be handled like Mutex
-#
-module Mutex_m
-
- VERSION = "0.2.0"
- Ractor.make_shareable(VERSION) if defined?(Ractor)
-
- def Mutex_m.define_aliases(cl) # :nodoc:
- cl.alias_method(:locked?, :mu_locked?)
- cl.alias_method(:lock, :mu_lock)
- cl.alias_method(:unlock, :mu_unlock)
- cl.alias_method(:try_lock, :mu_try_lock)
- cl.alias_method(:synchronize, :mu_synchronize)
- end
-
- def Mutex_m.append_features(cl) # :nodoc:
- super
- define_aliases(cl) unless cl.instance_of?(Module)
- end
-
- def Mutex_m.extend_object(obj) # :nodoc:
- super
- obj.mu_extended
- end
-
- def mu_extended # :nodoc:
- unless (defined? locked? and
- defined? lock and
- defined? unlock and
- defined? try_lock and
- defined? synchronize)
- Mutex_m.define_aliases(singleton_class)
- end
- mu_initialize
- end
-
- # See Thread::Mutex#synchronize
- def mu_synchronize(&block)
- @_mutex.synchronize(&block)
- end
-
- # See Thread::Mutex#locked?
- def mu_locked?
- @_mutex.locked?
- end
-
- # See Thread::Mutex#try_lock
- def mu_try_lock
- @_mutex.try_lock
- end
-
- # See Thread::Mutex#lock
- def mu_lock
- @_mutex.lock
- end
-
- # See Thread::Mutex#unlock
- def mu_unlock
- @_mutex.unlock
- end
-
- # See Thread::Mutex#sleep
- def sleep(timeout = nil)
- @_mutex.sleep(timeout)
- end
-
- private
-
- def mu_initialize # :nodoc:
- @_mutex = Thread::Mutex.new
- end
-
- def initialize(*args) # :nodoc:
- mu_initialize
- super
- end
- ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
-end
diff --git a/test/test_mutex_m.rb b/test/test_mutex_m.rb
deleted file mode 100644
index f938e71729..0000000000
--- a/test/test_mutex_m.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-# frozen_string_literal: false
-require 'test/unit'
-require 'mutex_m'
-
-class TestMutexM < Test::Unit::TestCase
- def test_cv_wait
- o = Object.new
- o.instance_variable_set(:@foo, nil)
- o.extend(Mutex_m)
- c = Thread::ConditionVariable.new
- t = Thread.start {
- o.synchronize do
- until foo = o.instance_variable_get(:@foo)
- c.wait(o)
- end
- foo
- end
- }
- sleep(0.0001)
- o.synchronize do
- o.instance_variable_set(:@foo, "abc")
- end
- c.signal
- assert_equal "abc", t.value
- end
-
- class KeywordInitializeParent
- def initialize(x:)
- end
- end
-
- class KeywordInitializeChild < KeywordInitializeParent
- include Mutex_m
- def initialize
- super(x: 1)
- end
- end
-
- def test_initialize_with_keyword_arg
- assert KeywordInitializeChild.new
- end
-
- class NoArgInitializeParent
- def initialize
- end
- end
-
- class NoArgInitializeChild < NoArgInitializeParent
- include Mutex_m
- def initialize
- super()
- end
- end
-
- def test_initialize_no_args
- assert NoArgInitializeChild.new
- end
-
- def test_alias_extended_object
- object = Object.new
- object.extend(Mutex_m)
-
- assert object.respond_to?(:locked?)
- assert object.respond_to?(:lock)
- assert object.respond_to?(:unlock)
- assert object.respond_to?(:try_lock)
- assert object.respond_to?(:synchronize)
- end
-
- def test_alias_included_class
- object = NoArgInitializeChild.new
-
- assert object.respond_to?(:locked?)
- assert object.respond_to?(:lock)
- assert object.respond_to?(:unlock)
- assert object.respond_to?(:try_lock)
- assert object.respond_to?(:synchronize)
- end
-end