* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
* 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.
*/
#include <mutex>
#include "cpu_data_plugin.h"
namespace {
constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
std::unique_ptr<CpuDataPlugin> g_plugin = nullptr;
std::mutex g_taskMutex;
}
static int CpuDataPluginSessionStart(const uint8_t* configData, uint32_t configSize)
{
std::lock_guard<std::mutex> guard(g_taskMutex);
g_plugin = std::make_unique<CpuDataPlugin>();
return g_plugin->Start(configData, configSize);
}
static int CpuPluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
{
std::lock_guard<std::mutex> guard(g_taskMutex);
CHECK_NOTNULL(g_plugin, -1, "g_plugin is nullptr");
return g_plugin->Report(bufferData, bufferSize);
}
static int CpuPluginReportResultOptimize(RandomWriteCtx* randomWrite)
{
std::lock_guard<std::mutex> guard(g_taskMutex);
if (g_plugin == nullptr) {
return -1;
}
return g_plugin->ReportOptimize(randomWrite);
}
static int CpuPluginSessionStop()
{
std::lock_guard<std::mutex> guard(g_taskMutex);
CHECK_NOTNULL(g_plugin, -1, "g_plugin is nullptr");
g_plugin->Stop();
g_plugin = nullptr;
return 0;
}
static PluginModuleCallbacks g_callbacks = {
.onPluginSessionStart = CpuDataPluginSessionStart,
.onPluginReportResult = CpuPluginReportResult,
.onPluginSessionStop = CpuPluginSessionStop,
.onPluginReportResultOptimize = CpuPluginReportResultOptimize,
};
EXPORT_API PluginModuleStruct g_pluginModule = {
.callbacks = &g_callbacks,
.name = "cpu-plugin",
.version = "1.02",
.resultBufferSizeHint = MAX_BUFFER_SIZE,
};