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)
  filep = "#{File.dirname(__FILE__)}/tsafe_#{name.to_s.downcase}"
  
  if RUBY_ENGINE == "jruby" and File.exists?("#{filep}_jruby.rb")
    require "#{filep}_jruby.rb"
  else
    require filep
  end
  
  raise "Still not loaded: '#{name}'." if !Tsafe.const_defined?(name)
  return Tsafe.const_get(name)
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"
  return []
end