lib/monitor.rb: prevent to initialize MonitorMixin twice

and allow to initialize again when obj.dup.

Suggested by Benoit Daloze.  [ruby-core:88504] [Feature #15000]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kazu 2018-12-05 09:07:54 +00:00
Родитель 3913092624
Коммит 1eba8ecb66
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -255,9 +255,13 @@ module MonitorMixin
# Initializes the MonitorMixin after being included in a class or when an
# object has been extended with the MonitorMixin
def mon_initialize
if defined?(@mon_mutex) && @mon_mutex_owner_object_id == object_id
raise ThreadError, "already initialized"
end
@mon_mutex = Thread::Mutex.new
@mon_mutex_owner_object_id = object_id
@mon_owner = nil
@mon_count = 0
@mon_mutex = Thread::Mutex.new
end
def mon_check_owner