|
| 1 | +// Copyright (c) 2017-2023 Intel Corporation |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in all |
| 11 | +// copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +// SOFTWARE. |
| 20 | + |
| 21 | +#include "mfx_c2_components_monitor.h" |
| 22 | +#include "mfx_c2_debug.h" |
| 23 | + |
| 24 | +#undef MFX_DEBUG_MODULE_NAME |
| 25 | +#define MFX_DEBUG_MODULE_NAME "mfx_c2_components_monitor" |
| 26 | + |
| 27 | +uint32_t MfxC2ComponentsMonitor::get(std::string name) |
| 28 | +{ |
| 29 | + MFX_DEBUG_TRACE_FUNC; |
| 30 | + |
| 31 | + std::unique_lock<std::mutex> lock(m_mutex); |
| 32 | + auto obj = m_monitor.find(name); |
| 33 | + if (m_monitor.end() != obj) |
| 34 | + { |
| 35 | + MFX_DEBUG_TRACE_I32(obj->second); |
| 36 | + return obj->second; |
| 37 | + } |
| 38 | + return 0; |
| 39 | +} |
| 40 | + |
| 41 | +void MfxC2ComponentsMonitor::increase(std::string name) |
| 42 | +{ |
| 43 | + MFX_DEBUG_TRACE_FUNC; |
| 44 | + |
| 45 | + std::unique_lock<std::mutex> lock(m_mutex); |
| 46 | + auto obj = m_monitor.find(name); |
| 47 | + if (m_monitor.end() == obj) |
| 48 | + { |
| 49 | + MFX_DEBUG_TRACE_STREAM("increase " << name << ", instances 0 + 1"); |
| 50 | + m_monitor.insert(std::pair<std::string, uint32_t>(name, 1)); |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + MFX_DEBUG_TRACE_STREAM("increase " << name << ", instances " << obj->second << " + 1"); |
| 55 | + obj->second++; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +void MfxC2ComponentsMonitor::decrease(std::string name) |
| 60 | +{ |
| 61 | + MFX_DEBUG_TRACE_FUNC; |
| 62 | + |
| 63 | + std::unique_lock<std::mutex> lock(m_mutex); |
| 64 | + auto obj = m_monitor.find(name); |
| 65 | + if (m_monitor.end() == obj) // impossible |
| 66 | + { |
| 67 | + MFX_DEBUG_TRACE_MSG("can't find the record!"); |
| 68 | + m_monitor.insert(std::pair<std::string, uint32_t>(name, 0)); |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + MFX_DEBUG_TRACE_STREAM("decrease " << name << ", instances " << obj->second << " - 1"); |
| 73 | + if (0 == obj->second) |
| 74 | + obj->second = 0; |
| 75 | + else |
| 76 | + obj->second--; |
| 77 | + } |
| 78 | +} |
0 commit comments