| 1 |
/* |
| 2 |
* Copyright (c) 2025, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
#ifndef __MOS_HYBRID_CMD_MANAGER_H__ |
| 23 |
#define __MOS_HYBRID_CMD_MANAGER_H__ |
| 24 |
#include "mos_defs.h" |
| 25 |
#include "media_class_trace.h" |
| 26 |
#include <mutex> |
| 27 |
#include <queue> |
| 28 |
#include <thread> |
| 29 |
#include <condition_variable> |
| 30 |
|
| 31 |
class CmdPackage |
| 32 |
{ |
| 33 |
public: |
| 34 |
virtual ~CmdPackage() = default; |
| 35 |
virtual MOS_STATUS Submit() = 0; |
| 36 |
virtual MOS_STATUS Wait() = 0; |
| 37 |
virtual std::unique_ptr<CmdPackage> Clone() const = 0; |
| 38 |
virtual bool Releaseable() { return true; }; |
| 39 |
virtual bool IsAsyncExecute() { return false; }; |
| 40 |
}; |
| 41 |
|
| 42 |
enum class HYBRID_MGR_SUBMIT_MODE |
| 43 |
{ |
| 44 |
ASYNC = 0, |
| 45 |
SYNC = 1 |
| 46 |
}; |
| 47 |
|
| 48 |
class HybridCmdMgr |
| 49 |
{ |
| 50 |
public: |
| 51 |
HybridCmdMgr() {}; |
| 52 |
virtual ~HybridCmdMgr(); |
| 53 |
|
| 54 |
MOS_STATUS SubmitPackage(CmdPackage &cmdPackage); |
| 55 |
MOS_STATUS StartThread(); |
| 56 |
MOS_STATUS StopThread(); |
| 57 |
bool Enabled(); |
| 58 |
MOS_STATUS SetSubmitMode(HYBRID_MGR_SUBMIT_MODE submitMode); |
| 59 |
|
| 60 |
private: |
| 61 |
void Consumer(); |
| 62 |
MOS_STATUS SubmitPackageInAsync(std::unique_ptr<CmdPackage> cmdPackage); |
| 63 |
MOS_STATUS SubmitPackageInSync(std::unique_ptr<CmdPackage> cmdPackage); |
| 64 |
|
| 65 |
private: |
| 66 |
HYBRID_MGR_SUBMIT_MODE m_submitMode = HYBRID_MGR_SUBMIT_MODE::ASYNC; |
| 67 |
|
| 68 |
std::queue<std::unique_ptr<CmdPackage>> m_queue; |
| 69 |
std::unique_ptr<CmdPackage> m_lastCmdPackage = nullptr; |
| 70 |
std::mutex m_queueMutex = {}; |
| 71 |
std::vector<std::unique_ptr<CmdPackage>> m_deferReleaseList = {}; |
| 72 |
std::condition_variable m_wakeCondition = {}; |
| 73 |
bool m_stopFlag = false; |
| 74 |
std::thread m_consumerThread; |
| 75 |
std::mutex m_threadMutex = {}; |
| 76 |
|
| 77 |
MEDIA_CLASS_DEFINE_END(HybridCmdMgr) |
| 78 |
}; |
| 79 |
|
| 80 |
#endif |