<commit_before>module Rubinius
  class AtomicReference
    def initialize(val=nil)
      @value = val
    end

    attr_accessor :value

    alias_method :get, :value
    alias_method :set, :value=

    def compare_and_set(old, new)
      Rubinius.primitive :atomic_compare_and_set
      raise PrimitiveFailure, "compare_and_set failed"
    end

    def get_and_set(new)
      val = @value
      @value = new
      val
    end
  end
end<commit_msg>Make get_and_set atomic in the same way JDK does.<commit_after>module Rubinius
  class AtomicReference
    def initialize(val=nil)
      @value = val
    end

    attr_accessor :value

    alias_method :get, :value
    alias_method :set, :value=

    def compare_and_set(old, new)
      Rubinius.primitive :atomic_compare_and_set
      raise PrimitiveFailure, "compare_and_set failed"
    end

    def get_and_set(new)
      while true
        val = get
        return val if compare_and_set(val, new)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.062436028659160696, 'fraction_numerical': 0.0, 'mean_word_length': 2.7045454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4861761', 'n_tokens_mistral': 327, 'n_tokens_neox': 315, 'n_words': 86}