* 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_THREADMANAGER_H
#define CORE_FRAMEWORK_THREADMANAGER_H
#include <string>
#include <memory>
#include <unordered_map>
#include <thread>
#include "cross_npu_checker.h"
#include "config.h"
#include "utility/log.h"
#include "checker.h"
#include "protocol.h"
namespace Sanitizer {
class ThreadManager {
public:
ThreadManager(Config const &config, const LogLv &lv, const std::string &logFile)
: config_{config}, loglv_(lv), logFd_(GetLogFd(logFile)), crossNpuChecker_(config) {}
void PostLog() const;
Checker& GetChecker(std::thread::id threadId);
Checker& GetChecker();
CrossNpuChecker &GetCrossNpuChecker() { return crossNpuChecker_; }
Protocol &GetProtocol();
void ThreadFinish();
int32_t GetCheckersNum() const { return checkers_.size(); }
int32_t GetProtocolsNum() const { return protocols_.size(); }
private:
std::ostream &GetLogFd(const std::string &filename);
std::unordered_map<std::thread::id, std::unique_ptr<Checker>> checkers_;
std::unordered_map<std::thread::id, std::unique_ptr<Protocol>> protocols_;
Config config_;
LogLv loglv_;
std::ostream& logFd_;
static std::mutex mutex_;
CrossNpuChecker crossNpuChecker_;
};
}
#endif