void ReplSetDistLockManager::doTask() { LOG(0) << "creating distributed lock ping thread for process " << _processID << " (sleeping for " << _pingInterval << ")"; Timer elapsedSincelastPing(_serviceContext->getTickSource()); Client::initThread("replSetDistLockPinger"); while (!isShutDown()) { { auto txn = cc().makeOperationContext(); auto pingStatus = _catalog->ping(txn.get(), _processID, Date_t::now()); if (!pingStatus.isOK()) { warning() << "pinging failed for distributed lock pinger" << causedBy(pingStatus); } const milliseconds elapsed(elapsedSincelastPing.millis()); if (elapsed > 10 * _pingInterval) { warning() << "Lock pinger for proc: " << _processID << " was inactive for " << elapsed << " ms"; } elapsedSincelastPing.reset(); std::deque<DistLockHandle> toUnlockBatch; { stdx::unique_lock<stdx::mutex> lk(_mutex); toUnlockBatch.swap(_unlockList); } for (const auto& toUnlock : toUnlockBatch) { auto unlockStatus = _catalog->unlock(txn.get(), toUnlock); if (!unlockStatus.isOK()) { warning() << "Failed to unlock lock with " << LocksType::lockID() << ": " << toUnlock << causedBy(unlockStatus); queueUnlock(toUnlock); } else { LOG(0) << "distributed lock with " << LocksType::lockID() << ": " << toUnlock << "' unlocked."; } if (isShutDown()) { return; } } } stdx::unique_lock<stdx::mutex> lk(_mutex); _shutDownCV.wait_for(lk, _pingInterval); } }
// Wait until the task is shut down and the run method has exited. // Most sub classes of OsTask should call this method in // the destructor before deleting any members which are // accessed by the run method. UtlBoolean OsTaskBase::waitUntilShutDown(int milliSecToWait) { // If task is already shut down, just return. if (isShutDown()) return TRUE; UtlString taskName = getName(); if (isStarted() || isUnInitialized()) { requestShutdown(); // ask the task to shut itself down yield(); // yield the CPU so the target task can terminate } // wait up to another nineteen seconds (20 total) for the task to terminate // printing out a console complaint every second if (isShuttingDown()) { int i; // wait up to a second for the task to terminate. for (i = 0; (i < 10) && isShuttingDown(); i++) delay(milliSecToWait/200); // wait 1/10 second for (i = 1; (i < 20) && isShuttingDown(); i++) { OsSysLog::add(FAC_KERNEL, PRI_WARNING, "Task: %s failed to terminate after %f seconds", taskName.data(), (milliSecToWait * i) / 20000.0); delay(milliSecToWait/20); } // if still no response from the task, assume it is unresponsive and // destroy the object if (isShuttingDown()) { OsSysLog::add(FAC_KERNEL, PRI_ERR, "Task: %s failed to terminate after %f seconds", taskName.data(), milliSecToWait / 1000.0); } } // Do not exit if not shut down while (isShuttingDown()) { OsSysLog::add(FAC_KERNEL, PRI_ERR, "Task: %s failed to terminate, waiting...", taskName.data()); delay(300000); } return(isShutDown()); }
// Acknowledge a shutdown request // The platform specific entry point which calls the run // method should call this method immediately after run exits. // to indicate that it is now shut down. void OsTaskBase::ackShutdown(void) { OsLock lock(mDataGuard); assert(isStarted() || isShuttingDown() || isShutDown()); mState = SHUT_DOWN; }
bool FB::BrowserHost::ScheduleAsyncCall( void (*func)(void *), void *userData ) const { if (isShutDown()) { return false; } else { _asyncCallData* data = _asyncManager->makeCallback(func, userData); return _scheduleAsyncCall(&asyncCallWrapper, data); } }
OsStatus XCpCall::extractConnection(XSipConnection **pSipConnection) { if (isShutDown()) { OsLock lock(m_memberMutex); if (m_pSipConnection && pSipConnection) { UtlString sSipCallId; m_pSipConnection->getSipCallId(sSipCallId); onConnectionRemoved(sSipCallId); *pSipConnection = m_pSipConnection; m_pSipConnection = NULL; return OS_SUCCESS; } } return OS_FAILED; }
OsStatus XCpCall::setConnection(XSipConnection *pSipConnection) { if (isShutDown()) { OsLock lock(m_memberMutex); if (!m_pSipConnection) { m_pSipConnection = pSipConnection; m_pSipConnection->setAbstractCallId(m_sId); m_pSipConnection->setMediaInterfaceProvider(this); m_pSipConnection->setMessageQueueProvider(this); UtlString sSipCallId; m_pSipConnection->getSipCallId(sSipCallId); onConnectionAddded(sSipCallId); return OS_SUCCESS; } } return OS_FAILED; }