本文整理汇总了C++中std::recursive_mutex::try_lock方法的典型用法代码示例。如果您正苦于以下问题:C++ recursive_mutex::try_lock方法的具体用法?C++ recursive_mutex::try_lock怎么用?C++ recursive_mutex::try_lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::recursive_mutex
的用法示例。
在下文中一共展示了recursive_mutex::try_lock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processFdbEntriesForAging
void processFdbEntriesForAging()
{
SWSS_LOG_ENTER();
if (!g_recursive_mutex.try_lock())
{
return;
}
SWSS_LOG_INFO("fdb infos to process: %zu", g_fdb_info_set.size());
uint32_t current = (uint32_t)time(NULL);
// find aged fdb entries
for (auto it = g_fdb_info_set.begin(); it != g_fdb_info_set.end();)
{
sai_attribute_t attr;
attr.id = SAI_SWITCH_ATTR_FDB_AGING_TIME;
sai_status_t status = vs_generic_get(SAI_OBJECT_TYPE_SWITCH, it->fdb_entry.switch_id, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("failed to get FDB aging time for switch %s",
sai_serialize_object_id(it->fdb_entry.switch_id).c_str());
++it;
continue;
}
uint32_t aging_time = attr.value.u32;
if (aging_time == 0)
{
// aging is disabled
++it;
continue;
}
if ((current - it->timestamp) >= aging_time)
{
fdb_info_t fi = *it;
processFdbInfo(fi, SAI_FDB_EVENT_AGED);
it = g_fdb_info_set.erase(it);
}
else
{
++it;
}
}
g_recursive_mutex.unlock();
}
示例2: Update
// Read the Wiimote once
void Update(int _WiimoteNumber)
{
// Try to get a lock and return without doing anything if we fail
// This avoids deadlocks when adding a Wiimote during continuous scan
if(!g_refresh_lock.try_lock())
return;
if (g_wiimotes[_WiimoteNumber])
g_wiimotes[_WiimoteNumber]->Update();
// Wiimote::Update() may remove the Wiimote if it was disconnected.
if (!g_wiimotes[_WiimoteNumber])
{
Host_ConnectWiimote(_WiimoteNumber, false);
}
g_refresh_lock.unlock();
}