本文整理汇总了C++中CDirectory::TryLock方法的典型用法代码示例。如果您正苦于以下问题:C++ CDirectory::TryLock方法的具体用法?C++ CDirectory::TryLock怎么用?C++ CDirectory::TryLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDirectory
的用法示例。
在下文中一共展示了CDirectory::TryLock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Pop
CDirectory* CDirectoryQueue::Pop()
{
bool force_wait = false;
CDirectory* tmp;
CDirectory* tmpPrev;
EnterCriticalSection(&_cs);
tmpPrev = NULL;
tmp = _head;
while (tmp != NULL) {
if (tmp->TryLock()) {
if (tmp == _head)
_head = _head->_next;
if (tmpPrev != NULL)
tmpPrev->_next = tmp->_next; // unlink it
if (tmp == _tail)
_tail = tmpPrev;
--_length;
break;
}
Warning("Skipping locked directory %s (will return to it)",
tmp->GetDirectoryName());
tmpPrev = tmp;
tmp = tmp->_next;
}
if (tmp == NULL && _head != NULL) {
// There's at least one directory, but they're all in use by another
// copy of rl. Just grab the first one and wait on it.
tmp = _head;
_head = _head->_next;
if (tmp == _tail)
_tail = NULL;
--_length;
// wait until it's no longer in use..... However, don't wait inside the
// critical section.
force_wait = true;
}
ReleaseSemaphore(_hMaxWorkQueueSem, 1, NULL);
LeaveCriticalSection(&_cs);
if (tmp != NULL) // might be empty diff queue before masters are run
tmp->_next = NULL;
if (force_wait)
tmp->WaitLock();
return tmp;
}