* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ------------------------------------------------------------------------- */
#ifndef CORE_FRAMEWORK_EVENT_CONTAINER_H
#define CORE_FRAMEWORK_EVENT_CONTAINER_H
#include <queue>
#include <memory>
#include <functional>
#include "core/framework/event_def.h"
namespace Sanitizer {
class EventContainer {
public:
void Init(uint32_t blockNum, uint32_t deviceNum = 1);
void Push(const SanEvent &e, PipeType pipe, uint32_t blockIdx, uint32_t deviceIdx = 0);
SanEvent Front() const;
void Pop();
bool IsCurQueEmpty() const;
bool IsNeedSwitchNextBlock() const;
bool IsNeedSwitchNextDevice() const;
bool IsEmpty() const;
void CheckCurDeviceStuck();
bool IsAllDeviceStuck() const;
void PrintStuckSerialNo() const;
void ForEachFrontEvent(const std::function<void(const SanEvent &)> &func) const;
void SwitchToNextDevice();
void SwitchToNextBlock();
void SwitchToNextPipe();
PipeType GetPipeIndex() const;
uint32_t GetQueIndex() const;
uint32_t GetBlockIndex() const;
uint32_t FlattenPipeIdx(uint32_t pipeIdx, uint32_t blockIdx, uint32_t deviceIdx) const;
uint32_t GetCurQueSize() const;
uint32_t GetAllQueSize() const;
void SetQueIndex(PipeType pipe);
private:
bool IsCurBlockEmpty() const;
bool IsCurDeviceEmpty() const;
private:
std::vector<std::queue<SanEvent>> ques_;
uint32_t deviceNum_ = 0;
uint32_t maxBlockNum_ = 0;
uint32_t blockPopCount_ = 0U;
uint32_t devicePopCount_ = 0U;
bool isBlockStuck_ = false;
bool isDeviceStuck_ = false;
uint32_t stuckDeviceNum_ = 0;
uint32_t pipeIndex_ = 0U;
uint32_t blockIndex_ = 0U;
uint32_t deviceIndex_ = 0U;
};
}
#endif