bool FunctionScheduler::resetFunctionTimer(StringPiece nameID) { std::unique_lock<std::mutex> l(mutex_); if (currentFunction_ && currentFunction_->name == nameID) { RepeatFunc* funcPtrCopy = currentFunction_; // This function is currently being run. Clear currentFunction_ // to avoid rescheduling it, and add the function again to honor the // startDelay. currentFunction_ = nullptr; addFunctionToHeap(l, std::move(*funcPtrCopy)); return true; } // Since __adjust_heap() isn't a part of the standard API, there's no way to // fix the heap ordering if we adjust the key (nextRunTime) for the existing // RepeatFunc. Instead, we just cancel it and add an identical object. for (auto it = functions_.begin(); it != functions_.end(); ++it) { if (it->isValid() && it->name == nameID) { RepeatFunc funcCopy(std::move(*it)); cancelFunction(l, it); addFunctionToHeap(l, std::move(funcCopy)); return true; } } return false; }
/*** * PURPOSE: Copy entire BST to same another one * RETURN: Copied BST pointer * PARAM: [IN] tree - pointer to original BST * PARAM: [IN] funcCopy - function, that will be applied to each item at current list to copy item * PARAM: [IN] parent - pointer to parent * AUTHOR: Eliseev Dmitry ***/ VETREEBST *VETreeBSTCopyInternal( const VETREEBST *tree, const VEFUNCPTRPTR funcCopy, const VETREEBST *parent ) { VETREEBST *copiedBST = NULL; if (!(tree&&funcCopy)) return NULL; copiedBST = VETreeBSTCreateInternal(tree->m_ID, funcCopy(tree->m_Data)); copiedBST->m_Parent = (VETREEBST*)tree; copiedBST->m_Left = VETreeBSTCopyInternal(tree->m_Left, funcCopy, tree); copiedBST->m_Right = VETreeBSTCopyInternal(tree->m_Right, funcCopy, tree); /* List was copied */ return copiedBST; } /* End of 'VETreeBSTCopyInternal' function */
/*** * PURPOSE: Copy entire list to same another one * RETURN: Copied list pointer * PARAM: [IN] list - pointer to original list * PARAM: [IN] funcCopy - function, that will be applied to each item at current list to copy item * AUTHOR: Eliseev Dmitry ***/ VELIST *VEListCopyInternal( const VELIST *list, const VEFUNCPTRPTR funcCopy ) { VELIST *copiedList = NULL, *currentNodeOrig = NULL, *currentNodeDest = NULL; if (!(list&&funcCopy)) return NULL; copiedList = VEListCreateInternal(0, NULL); currentNodeOrig = list->m_Next; currentNodeDest = copiedList; /* Copy list */ while (currentNodeOrig) { currentNodeDest->m_Next = VEListCreateInternal(currentNodeOrig->m_ID, funcCopy(currentNodeOrig->m_Data)); currentNodeOrig = currentNodeOrig->m_Next; currentNodeDest = currentNodeDest->m_Next; } /* List was copied */ return copiedList; } /* End of 'VEListCopyInternal' function */