// Path: src/main/java/com/lmax/disruptor/util/MutableLong.java
// public class MutableLong
// {
//     private long value = 0L;
// 
//     /**
//      * Default constructor
//      */
//     public MutableLong()
//     {
//     }
// 
//     /**
//      * Construct the holder with initial value.
//      *
//      * @param initialValue to be initially set.
//      */
//     public MutableLong(final long initialValue)
//     {
//         this.value = initialValue;
//     }
// 
//     /**
//      * Get the long value.
//      *
//      * @return the long value.
//      */
//     public long get()
//     {
//         return value;
//     }
// 
//     /**
//      * Set the long value.
//      *
//      * @param value to set.
//      */
//     public void set(final long value)
//     {
//         this.value = value;
//     }
// }
// 
// Path: src/main/java/com/lmax/disruptor/util/PaddedAtomicLong.java
// public class PaddedAtomicLong extends AtomicLong
// {
//     public volatile long p1, p2, p3, p4, p5, p6 = 7L;
// 
//     /**
//      * Default constructor
//      */
//     public PaddedAtomicLong()
//     {
//     }
// 
//     /**
//      * Construct with an initial value.
//      *
//      * @param initialValue for initialisation
//      */
//     public PaddedAtomicLong(final long initialValue)
//     {
//         super(initialValue);
//     }
// 
//     public long sumPaddingToPreventOptimisation()
//     {
//         return p1 + p2 + p3 + p4 + p5 + p6;
//     }
// }
// 
// Path: src/main/java/com/lmax/disruptor/util/Util.java
// public static long getMinimumSequence(final Sequence[] sequences)
// {
//     long minimum = Long.MAX_VALUE;
// 
//     for (Sequence sequence : sequences)
//     {
//         long value = sequence.get();
//         minimum = minimum < value ? minimum : value;
//     }
// 
//     return minimum;
// }


import com.lmax.disruptor.util.MutableLong;
import com.lmax.disruptor.util.PaddedAtomicLong;
import java.util.concurrent.locks.LockSupport;
import static com.lmax.disruptor.util.Util.getMinimumSequence;
/*
 * 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;




/**
 * Strategy to be used when there are multiple publisher threads claiming sequences.
 *
 * This strategy requires sufficient cores to allow multiple publishers to be concurrently claiming sequences.
 */
public final class MultiThreadedClaimStrategy
    implements ClaimStrategy
{
    private final int bufferSize;
    private final PaddedAtomicLong claimSequence = new PaddedAtomicLong(Sequencer.INITIAL_CURSOR_VALUE);

// Path: src/main/java/com/lmax/disruptor/util/MutableLong.java
// public class MutableLong
// {
//     private long value = 0L;
// 
//     /**
//      * Default constructor
//      */
//     public MutableLong()
//     {
//     }
// 
//     /**
//      * Construct the holder with initial value.
//      *
//      * @param initialValue to be initially set.
//      */
//     public MutableLong(final long initialValue)
//     {
//         this.value = initialValue;
//     }
// 
//     /**
//      * Get the long value.
//      *
//      * @return the long value.
//      */
//     public long get()
//     {
//         return value;
//     }
// 
//     /**
//      * Set the long value.
//      *
//      * @param value to set.
//      */
//     public void set(final long value)
//     {
//         this.value = value;
//     }
// }
// 
// Path: src/main/java/com/lmax/disruptor/util/PaddedAtomicLong.java
// public class PaddedAtomicLong extends AtomicLong
// {
//     public volatile long p1, p2, p3, p4, p5, p6 = 7L;
// 
//     /**
//      * Default constructor
//      */
//     public PaddedAtomicLong()
//     {
//     }
// 
//     /**
//      * Construct with an initial value.
//      *
//      * @param initialValue for initialisation
//      */
//     public PaddedAtomicLong(final long initialValue)
//     {
//         super(initialValue);
//     }
// 
//     public long sumPaddingToPreventOptimisation()
//     {
//         return p1 + p2 + p3 + p4 + p5 + p6;
//     }
// }
// 
// Path: src/main/java/com/lmax/disruptor/util/Util.java
// public static long getMinimumSequence(final Sequence[] sequences)
// {
//     long minimum = Long.MAX_VALUE;
// 
//     for (Sequence sequence : sequences)
//     {
//         long value = sequence.get();
//         minimum = minimum < value ? minimum : value;
//     }
// 
//     return minimum;
// }


// Path: src/main/java/com/lmax/disruptor/MultiThreadedClaimStrategy.java
import com.lmax.disruptor.util.MutableLong;
import com.lmax.disruptor.util.PaddedAtomicLong;
import java.util.concurrent.locks.LockSupport;
import static com.lmax.disruptor.util.Util.getMinimumSequence;

/*
 * 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;




/**
 * Strategy to be used when there are multiple publisher threads claiming sequences.
 *
 * This strategy requires sufficient cores to allow multiple publishers to be concurrently claiming sequences.
 */
public final class MultiThreadedClaimStrategy
    implements ClaimStrategy
{
    private final int bufferSize;
    private final PaddedAtomicLong claimSequence = new PaddedAtomicLong(Sequencer.INITIAL_CURSOR_VALUE);

    private final ThreadLocal<MutableLong> minGatingSequenceThreadLocal = new ThreadLocal<MutableLong>()