/********************************************************************
* This software is "commercial computer software" as defined in the *
* Federal Acquisition Regulations and is subject to BlackLynx       *
* Inc's standard End User License Agreement.                        *
*                                                                   *
* CONFIDENTIAL - All source code is the propriety and confidential  *
* information of BlackLynx Inc.                                     *
*                                                                   *
* Copyright 2022 BlackLynx Inc.                                     *
* Unpublished -- all rights reserved under the copyright laws       *
* of the United States.                                             *
********************************************************************/

#ifndef __BLACKLYNX_URING_EXECDRIVER_H__
#define __BLACKLYNX_URING_EXECDRIVER_H__

#include <atomic>
#include <cstdint>
#include <mutex>
#include <string>
#include <thread>
#include <vector>

#include "liburing.h"

#include "Chunk.h"
#include "ExecDriver.h"
#include "Utilities/ProtectedQueue.h"


namespace BlackLynx
{
namespace SearchLynx
{

class URingExecDriver : public ExecDriver
{
public:
    
    static const uint32_t QUEUE_DEPTH = 256;
    
    URingExecDriver(
        const std::string& inputFile,
        uint32_t numReaderThreads,
        uint32_t chunkSize);
    
    ~URingExecDriver() override;
    
    void start() override;
    
private:
    
    void readerThreadBody(
        chunk_queue_t* inQueue,
        chunk_queue_t* outQueue) override;
    
    
    void waitForCompletion(chunk_queue_t* outQueue);
    
    struct io_uring m_ring;
    
    std::atomic<uint32_t> m_ioCounter;
    
};

}
}

#endif // __BLACKLYNX_URING_EXECDRIVER_H__