// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java
// public static final int MAX_THREAD_COUNT = 4;
// 
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java
// public static final int RESPONSE_QUEUE_CAPACITY = 128;


import java.util.concurrent.atomic.AtomicInteger;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
import org.agrona.BitUtil;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.MessageHandler;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue;
import org.agrona.concurrent.UnsafeBuffer;
import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer;
import org.agrona.concurrent.ringbuffer.RingBuffer;
import org.agrona.concurrent.ringbuffer.RingBufferDescriptor;
import org.agrona.hints.ThreadHints;
import org.openjdk.jmh.annotations.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;
/*
 * Copyright 2015-2022 Real Logic Limited.
 *
 * 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
 *
 * https://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 uk.co.real_logic.benchmarks.aeron.ipc;




public class ManyToOneRingBufferBenchmark
{
    static final int MESSAGE_COUNT_LIMIT = 16;
    static final Integer SENTINEL = 0;
    static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH;

    @State(Scope.Benchmark)
    public static class SharedState
    {
        @Param({ "1", "100" })
        int burstLength;
        int[] values;

        final AtomicBoolean running = new AtomicBoolean(true);
        final AtomicInteger threadId = new AtomicInteger();

        RingBuffer ringBuffer;

        @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java
// public static final int MAX_THREAD_COUNT = 4;
// 
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java
// public static final int RESPONSE_QUEUE_CAPACITY = 128;


// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneRingBufferBenchmark.java
import java.util.concurrent.atomic.AtomicInteger;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
import org.agrona.BitUtil;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.MessageHandler;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue;
import org.agrona.concurrent.UnsafeBuffer;
import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer;
import org.agrona.concurrent.ringbuffer.RingBuffer;
import org.agrona.concurrent.ringbuffer.RingBufferDescriptor;
import org.agrona.hints.ThreadHints;
import org.openjdk.jmh.annotations.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;

/*
 * Copyright 2015-2022 Real Logic Limited.
 *
 * 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
 *
 * https://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 uk.co.real_logic.benchmarks.aeron.ipc;




public class ManyToOneRingBufferBenchmark
{
    static final int MESSAGE_COUNT_LIMIT = 16;
    static final Integer SENTINEL = 0;
    static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH;

    @State(Scope.Benchmark)
    public static class SharedState
    {
        @Param({ "1", "100" })
        int burstLength;
        int[] values;

        final AtomicBoolean running = new AtomicBoolean(true);
        final AtomicInteger threadId = new AtomicInteger();

        RingBuffer ringBuffer;

        @SuppressWarnings("unchecked")
        final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];