atomic 1.0.1-java → 1.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ lib/atomic_reference.jar
data/LICENSE ADDED
@@ -0,0 +1,144 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as
12
+ defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that
15
+ is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities that
18
+ control, are controlled by, or are under common control with that entity. For the purposes
19
+ of this definition, "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or otherwise, or (ii) ownership
21
+ of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of
22
+ such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by
25
+ this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications, including but not
28
+ limited to software source code, documentation source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or translation of
31
+ a Source form, including but not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available
35
+ under the License, as indicated by a copyright notice that is included in or attached to the
36
+ work (an example is provided in the Appendix below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on
39
+ (or derived from) the Work and for which the editorial revisions, annotations, elaborations,
40
+ or other modifications represent, as a whole, an original work of authorship. For the
41
+ purposes of this License, Derivative Works shall not include works that remain separable
42
+ from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works
43
+ thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original version of the Work
46
+ and any modifications or additions to that Work or Derivative Works thereof, that is
47
+ intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by
48
+ an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the
49
+ purposes of this definition, "submitted" means any form of electronic, verbal, or written
50
+ communication sent to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and issue tracking
52
+ systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and
53
+ improving the Work, but excluding communication that is conspicuously marked or otherwise
54
+ designated in writing by the copyright owner as "Not a Contribution."
55
+
56
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
57
+ Contribution has been received by Licensor and subsequently incorporated within the Work.
58
+
59
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each
60
+ Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
61
+ royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of,
62
+ publicly display, publicly perform, sublicense, and distribute the Work and such Derivative
63
+ Works in Source or Object form.
64
+
65
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each
66
+ Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
67
+ royalty-free, irrevocable (except as stated in this section) patent license to make, have
68
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license
69
+ applies only to those patent claims licensable by such Contributor that are necessarily
70
+ infringed by their Contribution(s) alone or by combination of their Contribution(s) with the
71
+ Work to which such Contribution(s) was submitted. If You institute patent litigation against
72
+ any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or
73
+ a Contribution incorporated within the Work constitutes direct or contributory patent
74
+ infringement, then any patent licenses granted to You under this License for that Work shall
75
+ terminate as of the date such litigation is filed.
76
+
77
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works
78
+ thereof in any medium, with or without modifications, and in Source or Object form, provided
79
+ that You meet the following conditions:
80
+
81
+ You must give any other recipients of the Work or Derivative Works a copy of this License;
82
+ and
83
+
84
+ You must cause any modified files to carry prominent notices stating that You changed the
85
+ files; and
86
+
87
+ You must retain, in the Source form of any Derivative Works that You distribute, all
88
+ copyright, patent, trademark, and attribution notices from the Source form of the Work,
89
+ excluding those notices that do not pertain to any part of the Derivative Works; and
90
+
91
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative
92
+ Works that You distribute must include a readable copy of the attribution notices contained
93
+ within such NOTICE file, excluding those notices that do not pertain to any part of the
94
+ Derivative Works, in at least one of the following places: within a NOTICE text file
95
+ distributed as part of the Derivative Works; within the Source form or documentation, if
96
+ provided along with the Derivative Works; or, within a display generated by the Derivative
97
+ Works, if and wherever such third-party notices normally appear. The contents of the NOTICE
98
+ file are for informational purposes only and do not modify the License. You may add Your own
99
+ attribution notices within Derivative Works that You distribute, alongside or as an addendum
100
+ to the NOTICE text from the Work, provided that such additional attribution notices cannot
101
+ be construed as modifying the License. You may add Your own copyright statement to Your
102
+ modifications and may provide additional or different license terms and conditions for use,
103
+ reproduction, or distribution of Your modifications, or for any such Derivative Works as a
104
+ whole, provided Your use, reproduction, and distribution of the Work otherwise complies with
105
+ the conditions stated in this License.
106
+
107
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution
108
+ intentionally submitted for inclusion in the Work by You to the Licensor shall be under the
109
+ terms and conditions of this License, without any additional terms or conditions.
110
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of any
111
+ separate license agreement you may have executed with Licensor regarding such Contributions.
112
+
113
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks,
114
+ service marks, or product names of the Licensor, except as required for reasonable and
115
+ customary use in describing the origin of the Work and reproducing the content of the NOTICE
116
+ file.
117
+
118
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing,
119
+ Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS"
120
+ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including,
121
+ without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
122
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
123
+ determining the appropriateness of using or redistributing the Work and assume any risks
124
+ associated with Your exercise of permissions under this License.
125
+
126
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort
127
+ (including negligence), contract, or otherwise, unless required by applicable law (such as
128
+ deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be
129
+ liable to You for damages, including any direct, indirect, special, incidental, or
130
+ consequential damages of any character arising as a result of this License or out of the use
131
+ or inability to use the Work (including but not limited to damages for loss of goodwill,
132
+ work stoppage, computer failure or malfunction, or any and all other commercial damages or
133
+ losses), even if such Contributor has been advised of the possibility of such damages.
134
+
135
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative
136
+ Works thereof, You may choose to offer, and charge a fee for, acceptance of support,
137
+ warranty, indemnity, or other liability obligations and/or rights consistent with this
138
+ License. However, in accepting such obligations, You may act only on Your own behalf and on
139
+ Your sole responsibility, not on behalf of any other Contributor, and only if You agree to
140
+ indemnify, defend, and hold each Contributor harmless for any liability incurred by, or
141
+ claims asserted against, such Contributor by reason of your accepting any such warranty or
142
+ additional liability.
143
+
144
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,59 @@
1
+ atomic: An atomic reference implementation for JRuby and green or GIL-threaded
2
+ Ruby implementations (MRI 1.8/1.9, Rubinius)
3
+
4
+ Summary
5
+ =======
6
+
7
+ This library provides:
8
+
9
+ * an Atomic class that guarantees atomic updates to its contained value
10
+
11
+ The Atomic class provides accessors for the contained "value" plus two update
12
+ methods:
13
+
14
+ * update will run the provided block, passing the current value and replacing
15
+ it with the block result iff the value has not been changed in the mean time.
16
+ It may run the block repeatedly if there are other concurrent updates in
17
+ progress.
18
+ * try_update will run the provided block, passing the current value and
19
+ replacing it with the block result. If the value changes before the update
20
+ can happen, it will throw Atomic::ConcurrentUpdateError.
21
+
22
+ The atomic repository is at http://github.com/headius/ruby-atomic.
23
+
24
+ Usage
25
+ =====
26
+
27
+ The simplest way to use "atomic" is to call the "update" or "try_update"
28
+ methods.
29
+
30
+ "try_update" and "update" both call the given block, passing the current
31
+ value and using the block's result as the new value. If the value is updated
32
+ by another thread before the block completes, "try update" raises a
33
+ ConcurrentUpdateError and "update" retries the block. Because "update" may call
34
+ the block several times when multiple threads are all updating the same value,
35
+ the block's logic should be kept as simple as possible.
36
+
37
+ ````ruby
38
+ require 'atomic'
39
+
40
+ my_atomic = Atomic.new(0)
41
+ my_atomic.update {|v| v + 1}
42
+ begin
43
+ my_atomic.try_update {|v| v + 1}
44
+ rescue Atomic::ConcurrentUpdateError => cue
45
+ # deal with it (retry, propagate, etc)
46
+ end
47
+ ````
48
+
49
+ It's also possible to use the regular get/set operations on the Atomic, if you
50
+ want to avoid the exception and respond to contended changes in some other way.
51
+
52
+ ````ruby
53
+ my_atomic = Atomic.new(0)
54
+ my_atomic.value # => 0
55
+ my_atomic.value = 1
56
+ my_atomic.swap(2) # => 1
57
+ my_atomic.compare_and_swap(2, 3) # => true, updated to 3
58
+ my_atomic.compare_and_swap(2, 3) # => false, current is not 2
59
+ ````
data/Rakefile CHANGED
@@ -1,3 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http:#www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
1
13
  require 'rake'
2
14
  require 'rake/testtask'
3
15
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{atomic}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
  s.authors = ["Charles Oliver Nutter", "MenTaLguY"]
7
7
  s.date = Time.now.strftime('%Y-%m-%d')
8
8
  s.description = "An atomic reference implementation for JRuby, Rubinius, and MRI"
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.summary = "An atomic reference implementation for JRuby, Rubinius, and MRI"
13
13
  s.test_files = Dir["test/test*.rb"]
14
14
  if defined?(JRUBY_VERSION)
15
- s.files = Dir['{lib,examples,test}/**/*'] + Dir['{*.txt,*.gemspec,Rakefile}']
15
+ s.files = Dir['lib/atomic_reference.jar']
16
16
  s.platform = 'java'
17
17
  else
18
- s.files = Dir['{lib,examples,test,ext}/**/*'] + Dir['{*.txt,*.gemspec,Rakefile}']
19
18
  s.extensions = 'ext/extconf.rb'
20
19
  end
20
+ s.files += `git ls-files`.lines.map(&:chomp)
21
21
  end
@@ -1,3 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
1
13
  require 'atomic'
2
14
 
3
15
  my_atomic = Atomic.new(0)
@@ -1,3 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
1
13
  require 'benchmark'
2
14
  require 'atomic'
3
15
  require 'thread'
@@ -1,5 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
3
14
  $: << File.expand_path('../../lib', __FILE__)
4
15
 
5
16
  require 'optparse'
@@ -1,4 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
2
15
  require 'optparse'
3
16
 
4
17
  conf = {
@@ -0,0 +1,24 @@
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
4
+ //
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+
13
+ import java.io.IOException;
14
+
15
+ import org.jruby.Ruby;
16
+ import org.jruby.runtime.load.BasicLibraryService;
17
+
18
+ public class AtomicReferenceService implements BasicLibraryService {
19
+ public boolean basicLoad(final Ruby runtime) throws IOException {
20
+ new org.jruby.ext.atomic.AtomicReferenceLibrary().load(runtime, false);
21
+ return true;
22
+ }
23
+ }
24
+
@@ -0,0 +1,74 @@
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
4
+ //
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+
13
+ #include <ruby.h>
14
+
15
+ static void ir_mark(void *value) {
16
+ rb_gc_mark_maybe((VALUE)value);
17
+ }
18
+
19
+ static VALUE ir_alloc(VALUE klass) {
20
+ return rb_data_object_alloc(klass, (void *)Qnil, ir_mark, NULL);
21
+ }
22
+
23
+ static VALUE ir_initialize(VALUE self, VALUE value) {
24
+ DATA_PTR(self) = (void *)value;
25
+ return Qnil;
26
+ }
27
+
28
+ static VALUE ir_get(VALUE self) {
29
+ return (VALUE)DATA_PTR(self);
30
+ }
31
+
32
+ static VALUE ir_set(VALUE self, VALUE new_value) {
33
+ DATA_PTR(self) = (void *)new_value;
34
+ return new_value;
35
+ }
36
+
37
+ static VALUE ir_get_and_set(VALUE self, VALUE new_value) {
38
+ VALUE old_value;
39
+ old_value = (VALUE)DATA_PTR(self);
40
+ DATA_PTR(self) = (void *)new_value;
41
+ return old_value;
42
+ }
43
+
44
+ static VALUE ir_compare_and_set(volatile VALUE self, VALUE expect_value, VALUE new_value) {
45
+ #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
46
+ if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) {
47
+ return Qtrue;
48
+ }
49
+ #elif (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
50
+ if (__sync_bool_compare_and_swap(&DATA_PTR(self), expect_value, new_value)) {
51
+ return Qtrue;
52
+ }
53
+ #else
54
+ # error No CAS operation available for this platform
55
+ #endif
56
+ return Qfalse;
57
+ }
58
+
59
+ void Init_atomic_reference() {
60
+ VALUE cAtomic;
61
+ VALUE cInternalReference;
62
+
63
+ cAtomic = rb_const_get(rb_cObject, rb_intern("Atomic"));
64
+ cInternalReference = rb_define_class_under(cAtomic, "InternalReference",
65
+ rb_cObject);
66
+
67
+ rb_define_alloc_func(cInternalReference, ir_alloc);
68
+
69
+ rb_define_method(cInternalReference, "initialize", ir_initialize, 1);
70
+ rb_define_method(cInternalReference, "get", ir_get, 0);
71
+ rb_define_method(cInternalReference, "set", ir_set, 1);
72
+ rb_define_method(cInternalReference, "get_and_set", ir_get_and_set, 1);
73
+ rb_define_method(cInternalReference, "compare_and_set", ir_compare_and_set, 2);
74
+ }
@@ -0,0 +1,22 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'mkmf'
14
+ extension_name = 'atomic_reference'
15
+ dir_config(extension_name)
16
+
17
+ case CONFIG["arch"]
18
+ when /mswin32|mingw/
19
+ $CFLAGS += " -march=i686"
20
+ end
21
+
22
+ create_makefile(extension_name)
@@ -0,0 +1,95 @@
1
+ // Licensed under the Apache License, Version 2.0 (the "License");
2
+ // you may not use this file except in compliance with the License.
3
+ // You may obtain a copy of the License at
4
+ //
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+
13
+ package org.jruby.ext.atomic;
14
+
15
+ import java.io.IOException;
16
+ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
17
+ import org.jruby.Ruby;
18
+ import org.jruby.RubyClass;
19
+ import org.jruby.RubyModule;
20
+ import org.jruby.RubyObject;
21
+ import org.jruby.anno.JRubyClass;
22
+ import org.jruby.anno.JRubyMethod;
23
+ import org.jruby.runtime.ObjectAllocator;
24
+ import org.jruby.runtime.ThreadContext;
25
+ import org.jruby.runtime.builtin.IRubyObject;
26
+ import org.jruby.runtime.load.Library;
27
+
28
+ /**
29
+ * This library adds an atomic reference type to JRuby for use in the atomic
30
+ * library. We do a native version to avoid the implicit value coercion that
31
+ * normally happens through JI.
32
+ *
33
+ * @author headius
34
+ */
35
+ public class AtomicReferenceLibrary implements Library {
36
+ public void load(Ruby runtime, boolean wrap) throws IOException {
37
+ RubyModule atomicCls = runtime.getClass("Atomic");
38
+ RubyClass jrubyRefClass = runtime.defineClassUnder("InternalReference", runtime.getObject(), JRUBYREFERENCE_ALLOCATOR, atomicCls);
39
+ jrubyRefClass.setAllocator(JRUBYREFERENCE_ALLOCATOR);
40
+ jrubyRefClass.defineAnnotatedMethods(JRubyReference.class);
41
+ }
42
+
43
+ private static final ObjectAllocator JRUBYREFERENCE_ALLOCATOR = new ObjectAllocator() {
44
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
45
+ return new JRubyReference(runtime, klazz);
46
+ }
47
+ };
48
+
49
+ @JRubyClass(name="JRubyReference", parent="Object")
50
+ public static class JRubyReference extends RubyObject {
51
+ private volatile IRubyObject reference;
52
+ private final static AtomicReferenceFieldUpdater<JRubyReference, IRubyObject> UPDATER =
53
+ AtomicReferenceFieldUpdater.newUpdater(JRubyReference.class, IRubyObject.class, "reference");
54
+
55
+ public JRubyReference(Ruby runtime, RubyClass klass) {
56
+ super(runtime, klass);
57
+ reference = runtime.getNil();
58
+ }
59
+
60
+ @JRubyMethod
61
+ public IRubyObject initialize(ThreadContext context) {
62
+ Ruby runtime = context.getRuntime();
63
+ UPDATER.set(this, runtime.getNil());
64
+ return runtime.getNil();
65
+ }
66
+
67
+ @JRubyMethod
68
+ public IRubyObject initialize(ThreadContext context, IRubyObject value) {
69
+ Ruby runtime = context.getRuntime();
70
+ UPDATER.set(this, value);
71
+ return runtime.getNil();
72
+ }
73
+
74
+ @JRubyMethod(name = {"get", "value"})
75
+ public IRubyObject get() {
76
+ return UPDATER.get(this);
77
+ }
78
+
79
+ @JRubyMethod(name = {"set", "value="})
80
+ public IRubyObject set(IRubyObject newValue) {
81
+ UPDATER.set(this, newValue);
82
+ return newValue;
83
+ }
84
+
85
+ @JRubyMethod
86
+ public IRubyObject compare_and_set(ThreadContext context, IRubyObject oldValue, IRubyObject newValue) {
87
+ return context.getRuntime().newBoolean(UPDATER.compareAndSet(this, oldValue, newValue));
88
+ }
89
+
90
+ @JRubyMethod
91
+ public IRubyObject get_and_set(ThreadContext context, IRubyObject newValue) {
92
+ return UPDATER.getAndSet(this, newValue);
93
+ }
94
+ }
95
+ }
@@ -1,3 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
1
13
  require 'thread'
2
14
 
3
15
  class Atomic
Binary file
@@ -1,3 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http:#www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
1
13
  require 'test/unit'
2
14
  require 'atomic'
3
15
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic
3
3
  version: !ruby/object:Gem::Version
4
+ version: 1.0.2
4
5
  prerelease:
5
- version: 1.0.1
6
6
  platform: java
7
7
  authors:
8
8
  - Charles Oliver Nutter
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-26 00:00:00.000000000 Z
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: An atomic reference implementation for JRuby, Rubinius, and MRI
16
16
  email:
@@ -20,24 +20,22 @@ executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
- - !binary |-
24
- bGliL2F0b21pYy5yYg==
25
- - !binary |-
26
- bGliL2F0b21pY19yZWZlcmVuY2UuamFy
27
- - !binary |-
28
- ZXhhbXBsZXMvYXRvbWljX2V4YW1wbGUucmI=
29
- - !binary |-
30
- ZXhhbXBsZXMvYmVuY2hfYXRvbWljLnJi
31
- - !binary |-
32
- ZXhhbXBsZXMvYmVuY2hfYXRvbWljXzEucmI=
33
- - !binary |-
34
- ZXhhbXBsZXMvZ3JhcGhfYXRvbWljX2JlbmNoLnJi
35
- - !binary |-
36
- dGVzdC90ZXN0X2F0b21pYy5yYg==
37
- - !binary |-
38
- YXRvbWljLmdlbXNwZWM=
39
- - !binary |-
40
- UmFrZWZpbGU=
23
+ - lib/atomic_reference.jar
24
+ - test/test_atomic.rb
25
+ - ".gitignore"
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - atomic.gemspec
30
+ - examples/atomic_example.rb
31
+ - examples/bench_atomic.rb
32
+ - examples/bench_atomic_1.rb
33
+ - examples/graph_atomic_bench.rb
34
+ - ext/AtomicReferenceService.java
35
+ - ext/atomic_reference.c
36
+ - ext/extconf.rb
37
+ - ext/org/jruby/ext/atomic/AtomicReferenceLibrary.java
38
+ - lib/atomic.rb
41
39
  homepage: http://github.com/headius/ruby-atomic
42
40
  licenses: []
43
41
  post_install_message:
@@ -46,25 +44,23 @@ require_paths:
46
44
  - lib
47
45
  required_ruby_version: !ruby/object:Gem::Requirement
48
46
  requirements:
49
- - - ! '>='
47
+ - - ">="
50
48
  - !ruby/object:Gem::Version
51
49
  version: !binary |-
52
50
  MA==
53
51
  none: false
54
52
  required_rubygems_version: !ruby/object:Gem::Requirement
55
53
  requirements:
56
- - - ! '>='
54
+ - - ">="
57
55
  - !ruby/object:Gem::Version
58
56
  version: !binary |-
59
57
  MA==
60
58
  none: false
61
59
  requirements: []
62
60
  rubyforge_project:
63
- rubygems_version: 1.8.23
61
+ rubygems_version: 1.8.24
64
62
  signing_key:
65
63
  specification_version: 3
66
64
  summary: An atomic reference implementation for JRuby, Rubinius, and MRI
67
65
  test_files:
68
- - !binary |-
69
- dGVzdC90ZXN0X2F0b21pYy5yYg==
70
- ...
66
+ - test/test_atomic.rb