本文整理汇总了C++中mutex::Locker::TryLock方法的典型用法代码示例。如果您正苦于以下问题:C++ Locker::TryLock方法的具体用法?C++ Locker::TryLock怎么用?C++ Locker::TryLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutex::Locker
的用法示例。
在下文中一共展示了Locker::TryLock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
size_t
ModuleList::RemoveOrphans (bool mandatory)
{
Mutex::Locker locker;
if (mandatory)
{
locker.Lock (m_modules_mutex);
}
else
{
// Not mandatory, remove orphans if we can get the mutex
if (!locker.TryLock(m_modules_mutex))
return 0;
}
collection::iterator pos = m_modules.begin();
size_t remove_count = 0;
while (pos != m_modules.end())
{
if (pos->unique())
{
pos = RemoveImpl(pos);
++remove_count;
}
else
{
++pos;
}
}
return remove_count;
}
示例2: if
ConnectionStatus
ConnectionFileDescriptor::Disconnect (Error *error_ptr)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
log->Printf ("%p ConnectionFileDescriptor::Disconnect ()",
static_cast<void*>(this));
ConnectionStatus status = eConnectionStatusSuccess;
if (!IsConnected())
{
if (log)
log->Printf ("%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
static_cast<void*>(this));
return eConnectionStatusSuccess;
}
if (m_read_sp && m_read_sp->IsValid() && m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
static_cast<Socket&>(*m_read_sp).PreDisconnect();
// Try to get the ConnectionFileDescriptor's mutex. If we fail, that is quite likely
// because somebody is doing a blocking read on our file descriptor. If that's the case,
// then send the "q" char to the command file channel so the read will wake up and the connection
// will then know to shut down.
m_shutting_down = true;
Mutex::Locker locker;
bool got_lock = locker.TryLock (m_mutex);
if (!got_lock)
{
if (m_pipe.WriteDescriptorIsValid())
{
int result;
result = m_pipe.Write("q", 1) == 1;
if (log)
log->Printf ("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the lock, sent 'q' to %d, result = %d.",
static_cast<void*>(this), m_pipe.GetWriteFileDescriptor(), result);
}
else if (log)
{
log->Printf ("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the lock, but no command pipe is available.",
static_cast<void*>(this));
}
locker.Lock (m_mutex);
}
Error error = m_read_sp->Close();
Error error2 = m_write_sp->Close();
if (error.Fail() || error2.Fail())
status = eConnectionStatusError;
if (error_ptr)
*error_ptr = error.Fail() ? error : error2;
m_shutting_down = false;
return status;
}
示例3:
bool
GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker, const char *failure_message)
{
if (IsRunning())
return locker.TryLock (m_sequence_mutex, failure_message);
locker.Lock (m_sequence_mutex);
return true;
}