File: task_set.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (51 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "set"
require "forwardable"

module Celluloid
  module Internals
    if RUBY_PLATFORM == "java"
      require "jruby/synchronized"

      class TaskSet
        extend Forwardable
        include JRuby::Synchronized

        def_delegators :@tasks, :<<, :delete, :first, :empty?, :to_a

        def initialize
          @tasks = Set.new
        end
      end
    elsif RUBY_ENGINE == "rbx"
      class TaskSet
        def initialize
          @tasks = Set.new
        end

        def <<(task)
          Rubinius.synchronize(self) { @tasks << task }
        end

        def delete(task)
          Rubinius.synchronize(self) { @tasks.delete task }
        end

        def first
          Rubinius.synchronize(self) { @tasks.first }
        end

        def empty?
          Rubinius.synchronize(self) { @tasks.empty? }
        end

        def to_a
          Rubinius.synchronize(self) { @tasks.to_a }
        end
      end
    else
      # Assume we're on MRI, where we have the GIL. But what about IronRuby?
      # Or MacRuby. Do people care? This will break Celluloid::Internals::StackDumps
      TaskSet = Set
    end
  end
end