// Path: src/main/java/com/lmax/disruptor/EventProcessor.java
// public interface EventProcessor extends Runnable
// {
//     /**
//      * Get a reference to the {@link Sequence} being used by this {@link EventProcessor}.
//      *
//      * @return reference to the {@link Sequence} for this {@link EventProcessor}
//      */
//     Sequence getSequence();
// 
//     /**
//      * Signal that this EventProcessor should stop when it has finished consuming at the next clean break.
//      * It will call {@link SequenceBarrier#alert()} to notify the thread to check status.
//      */
//     void halt();
// }
// 
// Path: src/main/java/com/lmax/disruptor/Sequence.java
// public class Sequence
// {
//     private static final AtomicLongFieldUpdater<Sequence> updater = AtomicLongFieldUpdater.newUpdater(Sequence.class, "value");
// 
//     private volatile long p1 = 7L, p2 = 7L, p3 = 7L, p4 = 7L, p5 = 7L, p6 = 7L, p7 = 7L,
//                           value = Sequencer.INITIAL_CURSOR_VALUE,
//                           q1 = 7L, q2 = 7L, q3 = 7L, q4 = 7L, q5 = 7L, q6 = 7L, q7 = 7L;
// 
//     /**
//      * Default Constructor that uses an initial value of {@link Sequencer#INITIAL_CURSOR_VALUE}.
//      */
//     public Sequence()
//     {
//     }
// 
//     /**
//      * Construct a sequence counter that can be tracked across threads.
//      *
//      * @param initialValue for the counter.
//      */
//     public Sequence(final long initialValue)
//     {
//         set(initialValue);
//     }
// 
//     /**
//      * Get the current value of the {@link Sequence}
//      *
//      * @return the current value.
//      */
//     public long get()
//     {
//         return value;
//     }
// 
//     /**
//      * Set the {@link Sequence} to a value.
//      *
//      * @param value to which the {@link Sequence} will be set.
//      */
//     public void set(final long value)
//     {
//         updater.lazySet(this, value);
//     }
// 
//     /**
//      * Value of the {@link Sequence} as a String.
//      *
//      * @return String representation of the sequence.
//      */
//     public String toString()
//     {
//         return Long.toString(value);
//     }
// 
//     /**
//      * Here to help make sure false sharing prevention padding is not optimised away.
//      *
//      * @return sum of padding.
//      */
//     public long sumPaddingToPreventOptimisation()
//     {
//         return  p1 + p2 + p3 + p4 + p5 + p6 + p7 + value + q1 + q2 + q3 + q4 + q5 + q6 + q7;
//     }
// 
//     public void setPaddingValue(final long value)
//     {
//        p1 = p2 = p3 = p4 = p5 = p6 = p7 = q1 = q2 = q3 = q4 = q5 = q6 = q7 = value;
//     }
// 
//     public boolean compareAndSet(long expectedSequence, long nextSequence)
//     {
//         return updater.compareAndSet(this, expectedSequence, nextSequence);
//     }
// }


import com.lmax.disruptor.EventProcessor;
import com.lmax.disruptor.Sequence;
/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor.util;


/**
 * Set of common functions used by the Disruptor
 */
public final class Util
{
    /**
     * Calculate the next power of 2, greater than or equal to x.<p>
     * From Hacker's Delight, Chapter 3, Harry S. Warren Jr.
     *
     * @param x Value to round up
     * @return The next power of 2 from x inclusive
     */
    public static int ceilingNextPowerOfTwo(final int x)
    {
        return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
    }

    /**
     * Get the minimum sequence from an array of {@link com.lmax.disruptor.Sequence}s.
     *
     * @param sequences to compare.
     * @return the minimum sequence found or Long.MAX_VALUE if the array is empty.
     */
    public static long getMinimumSequence(final Sequence[] sequences)
    {
        long minimum = Long.MAX_VALUE;

// Path: src/main/java/com/lmax/disruptor/EventProcessor.java
// public interface EventProcessor extends Runnable
// {
//     /**
//      * Get a reference to the {@link Sequence} being used by this {@link EventProcessor}.
//      *
//      * @return reference to the {@link Sequence} for this {@link EventProcessor}
//      */
//     Sequence getSequence();
// 
//     /**
//      * Signal that this EventProcessor should stop when it has finished consuming at the next clean break.
//      * It will call {@link SequenceBarrier#alert()} to notify the thread to check status.
//      */
//     void halt();
// }
// 
// Path: src/main/java/com/lmax/disruptor/Sequence.java
// public class Sequence
// {
//     private static final AtomicLongFieldUpdater<Sequence> updater = AtomicLongFieldUpdater.newUpdater(Sequence.class, "value");
// 
//     private volatile long p1 = 7L, p2 = 7L, p3 = 7L, p4 = 7L, p5 = 7L, p6 = 7L, p7 = 7L,
//                           value = Sequencer.INITIAL_CURSOR_VALUE,
//                           q1 = 7L, q2 = 7L, q3 = 7L, q4 = 7L, q5 = 7L, q6 = 7L, q7 = 7L;
// 
//     /**
//      * Default Constructor that uses an initial value of {@link Sequencer#INITIAL_CURSOR_VALUE}.
//      */
//     public Sequence()
//     {
//     }
// 
//     /**
//      * Construct a sequence counter that can be tracked across threads.
//      *
//      * @param initialValue for the counter.
//      */
//     public Sequence(final long initialValue)
//     {
//         set(initialValue);
//     }
// 
//     /**
//      * Get the current value of the {@link Sequence}
//      *
//      * @return the current value.
//      */
//     public long get()
//     {
//         return value;
//     }
// 
//     /**
//      * Set the {@link Sequence} to a value.
//      *
//      * @param value to which the {@link Sequence} will be set.
//      */
//     public void set(final long value)
//     {
//         updater.lazySet(this, value);
//     }
// 
//     /**
//      * Value of the {@link Sequence} as a String.
//      *
//      * @return String representation of the sequence.
//      */
//     public String toString()
//     {
//         return Long.toString(value);
//     }
// 
//     /**
//      * Here to help make sure false sharing prevention padding is not optimised away.
//      *
//      * @return sum of padding.
//      */
//     public long sumPaddingToPreventOptimisation()
//     {
//         return  p1 + p2 + p3 + p4 + p5 + p6 + p7 + value + q1 + q2 + q3 + q4 + q5 + q6 + q7;
//     }
// 
//     public void setPaddingValue(final long value)
//     {
//        p1 = p2 = p3 = p4 = p5 = p6 = p7 = q1 = q2 = q3 = q4 = q5 = q6 = q7 = value;
//     }
// 
//     public boolean compareAndSet(long expectedSequence, long nextSequence)
//     {
//         return updater.compareAndSet(this, expectedSequence, nextSequence);
//     }
// }


// Path: src/main/java/com/lmax/disruptor/util/Util.java
import com.lmax.disruptor.EventProcessor;
import com.lmax.disruptor.Sequence;

/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor.util;


/**
 * Set of common functions used by the Disruptor
 */
public final class Util
{
    /**
     * Calculate the next power of 2, greater than or equal to x.<p>
     * From Hacker's Delight, Chapter 3, Harry S. Warren Jr.
     *
     * @param x Value to round up
     * @return The next power of 2 from x inclusive
     */
    public static int ceilingNextPowerOfTwo(final int x)
    {
        return 1 << (32 - Integer.numberOfLeadingZeros(x - 1));
    }

    /**
     * Get the minimum sequence from an array of {@link com.lmax.disruptor.Sequence}s.
     *
     * @param sequences to compare.
     * @return the minimum sequence found or Long.MAX_VALUE if the array is empty.
     */
    public static long getMinimumSequence(final Sequence[] sequences)
    {
        long minimum = Long.MAX_VALUE;

        for (Sequence sequence : sequences)