concurrent-ruby 0.7.0.rc0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +166 -0
  4. data/ext/concurrent_ruby_ext/atomic_reference.c +78 -0
  5. data/ext/concurrent_ruby_ext/atomic_reference.h +12 -0
  6. data/ext/concurrent_ruby_ext/extconf.rb +59 -0
  7. data/ext/concurrent_ruby_ext/rb_concurrent.c +28 -0
  8. data/lib/1.9/concurrent_ruby_ext.so +0 -0
  9. data/lib/2.0/concurrent_ruby_ext.so +0 -0
  10. data/lib/concurrent.rb +45 -0
  11. data/lib/concurrent/actress.rb +221 -0
  12. data/lib/concurrent/actress/ad_hoc.rb +20 -0
  13. data/lib/concurrent/actress/context.rb +98 -0
  14. data/lib/concurrent/actress/core.rb +228 -0
  15. data/lib/concurrent/actress/core_delegations.rb +42 -0
  16. data/lib/concurrent/actress/envelope.rb +41 -0
  17. data/lib/concurrent/actress/errors.rb +14 -0
  18. data/lib/concurrent/actress/reference.rb +64 -0
  19. data/lib/concurrent/actress/type_check.rb +48 -0
  20. data/lib/concurrent/agent.rb +232 -0
  21. data/lib/concurrent/async.rb +319 -0
  22. data/lib/concurrent/atomic.rb +46 -0
  23. data/lib/concurrent/atomic/atomic_boolean.rb +157 -0
  24. data/lib/concurrent/atomic/atomic_fixnum.rb +162 -0
  25. data/lib/concurrent/atomic/condition.rb +67 -0
  26. data/lib/concurrent/atomic/copy_on_notify_observer_set.rb +118 -0
  27. data/lib/concurrent/atomic/copy_on_write_observer_set.rb +117 -0
  28. data/lib/concurrent/atomic/count_down_latch.rb +116 -0
  29. data/lib/concurrent/atomic/cyclic_barrier.rb +106 -0
  30. data/lib/concurrent/atomic/event.rb +98 -0
  31. data/lib/concurrent/atomic/thread_local_var.rb +117 -0
  32. data/lib/concurrent/atomic_reference/concurrent_update_error.rb +7 -0
  33. data/lib/concurrent/atomic_reference/delegated_update.rb +28 -0
  34. data/lib/concurrent/atomic_reference/direct_update.rb +28 -0
  35. data/lib/concurrent/atomic_reference/jruby.rb +8 -0
  36. data/lib/concurrent/atomic_reference/mutex_atomic.rb +47 -0
  37. data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +24 -0
  38. data/lib/concurrent/atomic_reference/rbx.rb +16 -0
  39. data/lib/concurrent/atomic_reference/ruby.rb +16 -0
  40. data/lib/concurrent/atomics.rb +10 -0
  41. data/lib/concurrent/channel/buffered_channel.rb +85 -0
  42. data/lib/concurrent/channel/channel.rb +41 -0
  43. data/lib/concurrent/channel/unbuffered_channel.rb +34 -0
  44. data/lib/concurrent/channel/waitable_list.rb +40 -0
  45. data/lib/concurrent/channels.rb +5 -0
  46. data/lib/concurrent/collection/blocking_ring_buffer.rb +71 -0
  47. data/lib/concurrent/collection/priority_queue.rb +305 -0
  48. data/lib/concurrent/collection/ring_buffer.rb +59 -0
  49. data/lib/concurrent/collections.rb +3 -0
  50. data/lib/concurrent/configuration.rb +158 -0
  51. data/lib/concurrent/dataflow.rb +91 -0
  52. data/lib/concurrent/delay.rb +112 -0
  53. data/lib/concurrent/dereferenceable.rb +101 -0
  54. data/lib/concurrent/errors.rb +30 -0
  55. data/lib/concurrent/exchanger.rb +34 -0
  56. data/lib/concurrent/executor/cached_thread_pool.rb +44 -0
  57. data/lib/concurrent/executor/executor.rb +229 -0
  58. data/lib/concurrent/executor/fixed_thread_pool.rb +33 -0
  59. data/lib/concurrent/executor/immediate_executor.rb +16 -0
  60. data/lib/concurrent/executor/java_cached_thread_pool.rb +31 -0
  61. data/lib/concurrent/executor/java_fixed_thread_pool.rb +33 -0
  62. data/lib/concurrent/executor/java_single_thread_executor.rb +21 -0
  63. data/lib/concurrent/executor/java_thread_pool_executor.rb +187 -0
  64. data/lib/concurrent/executor/per_thread_executor.rb +24 -0
  65. data/lib/concurrent/executor/ruby_cached_thread_pool.rb +29 -0
  66. data/lib/concurrent/executor/ruby_fixed_thread_pool.rb +32 -0
  67. data/lib/concurrent/executor/ruby_single_thread_executor.rb +73 -0
  68. data/lib/concurrent/executor/ruby_thread_pool_executor.rb +286 -0
  69. data/lib/concurrent/executor/ruby_thread_pool_worker.rb +72 -0
  70. data/lib/concurrent/executor/safe_task_executor.rb +35 -0
  71. data/lib/concurrent/executor/serialized_execution.rb +90 -0
  72. data/lib/concurrent/executor/single_thread_executor.rb +35 -0
  73. data/lib/concurrent/executor/thread_pool_executor.rb +68 -0
  74. data/lib/concurrent/executor/timer_set.rb +143 -0
  75. data/lib/concurrent/executors.rb +9 -0
  76. data/lib/concurrent/future.rb +124 -0
  77. data/lib/concurrent/ivar.rb +111 -0
  78. data/lib/concurrent/logging.rb +17 -0
  79. data/lib/concurrent/mvar.rb +200 -0
  80. data/lib/concurrent/obligation.rb +171 -0
  81. data/lib/concurrent/observable.rb +40 -0
  82. data/lib/concurrent/options_parser.rb +46 -0
  83. data/lib/concurrent/promise.rb +169 -0
  84. data/lib/concurrent/scheduled_task.rb +78 -0
  85. data/lib/concurrent/supervisor.rb +343 -0
  86. data/lib/concurrent/timer_task.rb +341 -0
  87. data/lib/concurrent/tvar.rb +252 -0
  88. data/lib/concurrent/utilities.rb +3 -0
  89. data/lib/concurrent/utility/processor_count.rb +150 -0
  90. data/lib/concurrent/utility/timeout.rb +35 -0
  91. data/lib/concurrent/utility/timer.rb +21 -0
  92. data/lib/concurrent/version.rb +3 -0
  93. data/lib/concurrent_ruby.rb +1 -0
  94. data/lib/concurrent_ruby_ext.so +0 -0
  95. data/lib/extension_helper.rb +9 -0
  96. metadata +142 -0
@@ -0,0 +1,3 @@
1
+ require 'concurrent/utility/processor_count'
2
+ require 'concurrent/utility/timeout'
3
+ require 'concurrent/utility/timer'
@@ -0,0 +1,150 @@
1
+ require 'rbconfig'
2
+ require 'concurrent/delay'
3
+
4
+ module Concurrent
5
+
6
+ class ProcessorCounter
7
+ def initialize
8
+ @processor_count = Delay.new { compute_processor_count }
9
+ @physical_processor_count = Delay.new { compute_physical_processor_count }
10
+ end
11
+
12
+ # Number of processors seen by the OS and used for process scheduling. For performance
13
+ # reasons the calculated value will be memoized on the first call.
14
+ #
15
+ # When running under JRuby the Java runtime call `java.lang.Runtime.getRuntime.availableProcessors`
16
+ # will be used. According to the Java documentation this "value may change
17
+ # during a particular invocation of the virtual machine... [applications]
18
+ # should therefore occasionally poll this property." Subsequently the result
19
+ # will NOT be memoized under JRuby.
20
+ #
21
+ # On Windows the Win32 API will be queried for the `NumberOfLogicalProcessors from Win32_Processor`.
22
+ # This will return the total number "logical processors for the current instance of the processor",
23
+ # which taked into account hyperthreading.
24
+ #
25
+ # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
26
+ # * BSD: /sbin/sysctl
27
+ # * Cygwin: /proc/cpuinfo
28
+ # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
29
+ # * HP-UX: /usr/sbin/ioscan
30
+ # * IRIX: /usr/sbin/sysconf
31
+ # * Linux: /proc/cpuinfo
32
+ # * Minix 3+: /proc/cpuinfo
33
+ # * Solaris: /usr/sbin/psrinfo
34
+ # * Tru64 UNIX: /usr/sbin/psrinfo
35
+ # * UnixWare: /usr/sbin/psrinfo
36
+ #
37
+ # @return [Integer] number of processors seen by the OS or Java runtime
38
+ #
39
+ # @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
40
+ #
41
+ # @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
42
+ # @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
43
+ def processor_count
44
+ @processor_count.value
45
+ end
46
+
47
+ # Number of physical processor cores on the current system. For performance reasons
48
+ # the calculated value will be memoized on the first call.
49
+ #
50
+ # On Windows the Win32 API will be queried for the `NumberOfCores from Win32_Processor`.
51
+ # This will return the total number "of cores for the current instance of the processor."
52
+ # On Unix-like operating systems either the `hwprefs` or `sysctl` utility will be called
53
+ # in a subshell and the returned value will be used. In the rare case where none of these
54
+ # methods work or an exception is raised the function will simply return 1.
55
+ #
56
+ # @return [Integer] number physical processor cores on the current system
57
+ #
58
+ # @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
59
+ #
60
+ # @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
61
+ # @see http://www.unix.com/man-page/osx/1/HWPREFS/
62
+ # @see http://linux.die.net/man/8/sysctl
63
+ def physical_processor_count
64
+ @physical_processor_count.value
65
+ end
66
+
67
+ private
68
+
69
+ def compute_processor_count
70
+ if RUBY_PLATFORM == 'java'
71
+ java.lang.Runtime.getRuntime.availableProcessors
72
+ else
73
+ os_name = RbConfig::CONFIG["target_os"]
74
+ if os_name =~ /mingw|mswin/
75
+ require 'win32ole'
76
+ result = WIN32OLE.connect("winmgmts://").ExecQuery(
77
+ "select NumberOfLogicalProcessors from Win32_Processor")
78
+ result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
79
+ elsif File.readable?("/proc/cpuinfo")
80
+ IO.read("/proc/cpuinfo").scan(/^processor/).size
81
+ elsif File.executable?("/usr/bin/hwprefs")
82
+ IO.popen("/usr/bin/hwprefs thread_count").read.to_i
83
+ elsif File.executable?("/usr/sbin/psrinfo")
84
+ IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
85
+ elsif File.executable?("/usr/sbin/ioscan")
86
+ IO.popen("/usr/sbin/ioscan -kC processor") do |out|
87
+ out.read.scan(/^.*processor/).size
88
+ end
89
+ elsif File.executable?("/usr/sbin/pmcycles")
90
+ IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
91
+ elsif File.executable?("/usr/sbin/lsdev")
92
+ IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
93
+ elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
94
+ IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
95
+ elsif File.executable?("/usr/sbin/sysctl")
96
+ IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
97
+ elsif File.executable?("/sbin/sysctl")
98
+ IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
99
+ else
100
+ 1
101
+ end
102
+ end
103
+ rescue
104
+ return 1
105
+ end
106
+
107
+ def compute_physical_processor_count
108
+ ppc = case RbConfig::CONFIG["target_os"]
109
+ when /darwin1/
110
+ IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
111
+ when /linux/
112
+ cores = {} # unique physical ID / core ID combinations
113
+ phy = 0
114
+ IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
115
+ if ln.start_with?("physical")
116
+ phy = ln[/\d+/]
117
+ elsif ln.start_with?("core")
118
+ cid = phy + ":" + ln[/\d+/]
119
+ cores[cid] = true if not cores[cid]
120
+ end
121
+ end
122
+ cores.count
123
+ when /mswin|mingw/
124
+ require 'win32ole'
125
+ result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
126
+ "select NumberOfCores from Win32_Processor")
127
+ result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
128
+ else
129
+ processor_count
130
+ end
131
+ # fall back to logical count if physical info is invalid
132
+ ppc > 0 ? ppc : processor_count
133
+ rescue
134
+ return 1
135
+ end
136
+ end
137
+
138
+ # create the default ProcessorCounter on load
139
+ @processor_counter = ProcessorCounter.new
140
+ singleton_class.send :attr_reader, :processor_counter
141
+
142
+ def self.processor_count
143
+ processor_counter.processor_count
144
+ end
145
+
146
+ def self.physical_processor_count
147
+ processor_counter.physical_processor_count
148
+ end
149
+
150
+ end
@@ -0,0 +1,35 @@
1
+ require 'rbconfig'
2
+ require 'thread'
3
+
4
+ require 'concurrent/errors'
5
+
6
+ module Concurrent
7
+
8
+ # Wait the given number of seconds for the block operation to complete.
9
+ #
10
+ # @param [Integer] seconds The number of seconds to wait
11
+ #
12
+ # @return [Object] The result of the block operation
13
+ #
14
+ # @raise [Concurrent::TimeoutError] when the block operation does not complete
15
+ # in the allotted number of seconds.
16
+ #
17
+ # @note This method is intended to be a simpler and more reliable replacement
18
+ # to the Ruby standard library `Timeout::timeout` method.
19
+ def timeout(seconds)
20
+
21
+ thread = Thread.new do
22
+ Thread.current[:result] = yield
23
+ end
24
+ success = thread.join(seconds)
25
+
26
+ if success
27
+ return thread[:result]
28
+ else
29
+ raise TimeoutError
30
+ end
31
+ ensure
32
+ Thread.kill(thread) unless thread.nil?
33
+ end
34
+ module_function :timeout
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'concurrent/configuration'
2
+ require 'thread'
3
+
4
+ module Concurrent
5
+
6
+ # Perform the given operation asynchronously after the given number of seconds.
7
+ #
8
+ # @param [Fixnum] seconds the interval in seconds to wait before executing the task
9
+ #
10
+ # @yield the task to execute
11
+ #
12
+ # @return [Boolean] true
13
+ def timer(seconds, *args, &block)
14
+ raise ArgumentError.new('no block given') unless block_given?
15
+ raise ArgumentError.new('interval must be greater than or equal to zero') if seconds < 0
16
+
17
+ Concurrent.configuration.global_timer_set.post(seconds, *args, &block)
18
+ true
19
+ end
20
+ module_function :timer
21
+ end
@@ -0,0 +1,3 @@
1
+ module Concurrent
2
+ VERSION = '0.7.0.rc0'
3
+ end
@@ -0,0 +1 @@
1
+ require 'concurrent'
@@ -0,0 +1,9 @@
1
+ require 'rbconfig'
2
+
3
+ module Concurrent
4
+ def self.use_c_extensions?
5
+ host_os = RbConfig::CONFIG['host_os']
6
+ ruby_name = RbConfig::CONFIG['ruby_install_name']
7
+ (ruby_name =~ /^ruby$/i || host_os =~ /mswin32/i || host_os =~ /mingw32/i)
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: concurrent-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0.rc0
5
+ platform: x86-mingw32
6
+ authors:
7
+ - Jerry D'Antonio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! " Modern concurrency tools including agents, futures, promises,
14
+ thread pools, actors, supervisors, and more.\n Inspired by Erlang, Clojure, Go,
15
+ JavaScript, actors, and classic concurrency patterns.\n"
16
+ email: jerry.dantonio@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ - LICENSE.txt
22
+ files:
23
+ - LICENSE.txt
24
+ - README.md
25
+ - ext/concurrent_ruby_ext/atomic_reference.c
26
+ - ext/concurrent_ruby_ext/atomic_reference.h
27
+ - ext/concurrent_ruby_ext/extconf.rb
28
+ - ext/concurrent_ruby_ext/rb_concurrent.c
29
+ - lib/1.9/concurrent_ruby_ext.so
30
+ - lib/2.0/concurrent_ruby_ext.so
31
+ - lib/concurrent.rb
32
+ - lib/concurrent/actress.rb
33
+ - lib/concurrent/actress/ad_hoc.rb
34
+ - lib/concurrent/actress/context.rb
35
+ - lib/concurrent/actress/core.rb
36
+ - lib/concurrent/actress/core_delegations.rb
37
+ - lib/concurrent/actress/envelope.rb
38
+ - lib/concurrent/actress/errors.rb
39
+ - lib/concurrent/actress/reference.rb
40
+ - lib/concurrent/actress/type_check.rb
41
+ - lib/concurrent/agent.rb
42
+ - lib/concurrent/async.rb
43
+ - lib/concurrent/atomic.rb
44
+ - lib/concurrent/atomic/atomic_boolean.rb
45
+ - lib/concurrent/atomic/atomic_fixnum.rb
46
+ - lib/concurrent/atomic/condition.rb
47
+ - lib/concurrent/atomic/copy_on_notify_observer_set.rb
48
+ - lib/concurrent/atomic/copy_on_write_observer_set.rb
49
+ - lib/concurrent/atomic/count_down_latch.rb
50
+ - lib/concurrent/atomic/cyclic_barrier.rb
51
+ - lib/concurrent/atomic/event.rb
52
+ - lib/concurrent/atomic/thread_local_var.rb
53
+ - lib/concurrent/atomic_reference/concurrent_update_error.rb
54
+ - lib/concurrent/atomic_reference/delegated_update.rb
55
+ - lib/concurrent/atomic_reference/direct_update.rb
56
+ - lib/concurrent/atomic_reference/jruby.rb
57
+ - lib/concurrent/atomic_reference/mutex_atomic.rb
58
+ - lib/concurrent/atomic_reference/numeric_cas_wrapper.rb
59
+ - lib/concurrent/atomic_reference/rbx.rb
60
+ - lib/concurrent/atomic_reference/ruby.rb
61
+ - lib/concurrent/atomics.rb
62
+ - lib/concurrent/channel/buffered_channel.rb
63
+ - lib/concurrent/channel/channel.rb
64
+ - lib/concurrent/channel/unbuffered_channel.rb
65
+ - lib/concurrent/channel/waitable_list.rb
66
+ - lib/concurrent/channels.rb
67
+ - lib/concurrent/collection/blocking_ring_buffer.rb
68
+ - lib/concurrent/collection/priority_queue.rb
69
+ - lib/concurrent/collection/ring_buffer.rb
70
+ - lib/concurrent/collections.rb
71
+ - lib/concurrent/configuration.rb
72
+ - lib/concurrent/dataflow.rb
73
+ - lib/concurrent/delay.rb
74
+ - lib/concurrent/dereferenceable.rb
75
+ - lib/concurrent/errors.rb
76
+ - lib/concurrent/exchanger.rb
77
+ - lib/concurrent/executor/cached_thread_pool.rb
78
+ - lib/concurrent/executor/executor.rb
79
+ - lib/concurrent/executor/fixed_thread_pool.rb
80
+ - lib/concurrent/executor/immediate_executor.rb
81
+ - lib/concurrent/executor/java_cached_thread_pool.rb
82
+ - lib/concurrent/executor/java_fixed_thread_pool.rb
83
+ - lib/concurrent/executor/java_single_thread_executor.rb
84
+ - lib/concurrent/executor/java_thread_pool_executor.rb
85
+ - lib/concurrent/executor/per_thread_executor.rb
86
+ - lib/concurrent/executor/ruby_cached_thread_pool.rb
87
+ - lib/concurrent/executor/ruby_fixed_thread_pool.rb
88
+ - lib/concurrent/executor/ruby_single_thread_executor.rb
89
+ - lib/concurrent/executor/ruby_thread_pool_executor.rb
90
+ - lib/concurrent/executor/ruby_thread_pool_worker.rb
91
+ - lib/concurrent/executor/safe_task_executor.rb
92
+ - lib/concurrent/executor/serialized_execution.rb
93
+ - lib/concurrent/executor/single_thread_executor.rb
94
+ - lib/concurrent/executor/thread_pool_executor.rb
95
+ - lib/concurrent/executor/timer_set.rb
96
+ - lib/concurrent/executors.rb
97
+ - lib/concurrent/future.rb
98
+ - lib/concurrent/ivar.rb
99
+ - lib/concurrent/logging.rb
100
+ - lib/concurrent/mvar.rb
101
+ - lib/concurrent/obligation.rb
102
+ - lib/concurrent/observable.rb
103
+ - lib/concurrent/options_parser.rb
104
+ - lib/concurrent/promise.rb
105
+ - lib/concurrent/scheduled_task.rb
106
+ - lib/concurrent/supervisor.rb
107
+ - lib/concurrent/timer_task.rb
108
+ - lib/concurrent/tvar.rb
109
+ - lib/concurrent/utilities.rb
110
+ - lib/concurrent/utility/processor_count.rb
111
+ - lib/concurrent/utility/timeout.rb
112
+ - lib/concurrent/utility/timer.rb
113
+ - lib/concurrent/version.rb
114
+ - lib/concurrent_ruby.rb
115
+ - lib/concurrent_ruby_ext.so
116
+ - lib/extension_helper.rb
117
+ homepage: http://www.concurrent-ruby.com
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: 1.9.3
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>'
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.1
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell,
141
+ F#, C#, Java, and classic concurrency patterns.
142
+ test_files: []