<commit_before>require "thread"

module Bunny
  module Concurrent
    # Akin to java.util.concurrent.Condition and intrinsic object monitors (Object#wait, Object#notify, Object#notifyAll) in Java:
    # threads can wait (block until notified) on a condition other threads notify them about.
    # Unlike the j.u.c. version, this one has a single waiting set.
    #
    # Conditions can optionally be annotated with a description string for ease of debugging.
    class Condition
      attr_reader :waiting_threads, :description


      def initialize(description = nil)
        @mutex           = Mutex.new
        @waiting_threads = []
        @description     = description
      end

      def wait
        @mutex.synchronize do
          t = Thread.current
          @waiting_threads.push(t)
        end

        Thread.stop
      end

      def notify
        @mutex.synchronize do
          t = @waiting_threads.delete_at(0)
          t.run if t
        end
      end

      def notify_all
        @mutex.synchronize do
          @waiting_threads.each do |t|
            t.run
          end

          @waiting_threads = []
        end
      end

      def waiting_set_size
        @mutex.synchronize { @waiting_threads.size }
      end
    end
  end
end<commit_msg>Two more B::C::Condition methods<commit_after>require "thread"

module Bunny
  module Concurrent
    # Akin to java.util.concurrent.Condition and intrinsic object monitors (Object#wait, Object#notify, Object#notifyAll) in Java:
    # threads can wait (block until notified) on a condition other threads notify them about.
    # Unlike the j.u.c. version, this one has a single waiting set.
    #
    # Conditions can optionally be annotated with a description string for ease of debugging.
    class Condition
      attr_reader :waiting_threads, :description


      def initialize(description = nil)
        @mutex           = Mutex.new
        @waiting_threads = []
        @description     = description
      end

      def wait
        @mutex.synchronize do
          t = Thread.current
          @waiting_threads.push(t)
        end

        Thread.stop
      end

      def notify
        @mutex.synchronize do
          t = @waiting_threads.delete_at(0)
          t.run if t
        end
      end

      def notify_all
        @mutex.synchronize do
          @waiting_threads.each do |t|
            t.run
          end

          @waiting_threads = []
        end
      end

      def waiting_set_size
        @mutex.synchronize { @waiting_threads.size }
      end

      def any_threads_waiting?
        @mutex.synchronize { !@waiting_threads.empty? }
      end

      def none_threads_waiting?
        @mutex.synchronize { @waiting_threads.empty? }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06487857919536064, 'fraction_numerical': 0.0007249003262051468, 'mean_word_length': 1.929936305732484, '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': '3847362', 'n_tokens_mistral': 793, 'n_tokens_neox': 758, 'n_words': 234}