Module: Tsafe

Defined in:
lib/tsafe.rb

Overview

This module contains various tools to handle thread-safety easily and pretty.

Defined Under Namespace

Modules: Monitored, Mrswlock_synmodule, Mutexed Classes: MonArray, MonHash, Mrswlock, Proxy

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object

Autoloader for subclasses.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tsafe.rb', line 6

def self.const_missing(name)
  file_path = "#{File.dirname(__FILE__)}/tsafe_#{name.to_s.downcase}"

  if RUBY_ENGINE == "jruby" && File.exist?("#{file_path}_jruby.rb")
    require "#{file_path}_jruby.rb"
  else
    require file_path
  end

  return Tsafe.const_get(name) if Tsafe.const_defined?(name)
  super
end

.std_arrayObject

JRuby can corrupt an array in a threadded env. Use this method to only get a synchronized array when running JRuby in order to not having to write “if RUBY_ENGINE”-stuff.



20
21
22
23
# File 'lib/tsafe.rb', line 20

def self.std_array
  return Tsafe::MonArray.new if RUBY_ENGINE == "jruby"
  []
end