void peano::applications::poisson::jacobitutorial::mappings::RegularGrid2PlotSolution::handleCell( peano::applications::poisson::jacobitutorial::RegularGridVertex* const vertices, peano::applications::poisson::jacobitutorial::RegularGridCell& cell, const peano::kernel::gridinterface::VertexEnumerator& enumerator ) { logTraceInWith2Arguments( "handleCell()", enumerator.toString(), cell ); /** * --- inserted manually --- * * This is just cell plot mechanics. As the cells have no properties, it is * exactly the same what the grid plotter which is generated does. */ tarch::multicore::Lock localLock( _outputStreamSemaphore ); assertion( DIMENSIONS==2 || DIMENSIONS==3 ); int vertexIndex[TWO_POWER_D]; dfor2(i) tarch::la::Vector<DIMENSIONS,double> currentVertexPosition = enumerator.getVertexPosition(i); assertion1 ( _vertex2IndexMap.find(currentVertexPosition) != _vertex2IndexMap.end(), currentVertexPosition ); vertexIndex[iScalar] = _vertex2IndexMap[currentVertexPosition]; enddforx if (DIMENSIONS==2) { _cellWriter->plotQuadrangle(vertexIndex); } if (DIMENSIONS==3) { _cellWriter->plotHexahedron(vertexIndex); } logTraceOut( "handleCell()" ); }
void peano::applications::poisson::multigrid::mappings::SpacetreeGrid2PlotSolution::enterCell( peano::applications::poisson::multigrid::SpacetreeGridCell& fineGridCell, peano::applications::poisson::multigrid::SpacetreeGridVertex * const fineGridVertices, const peano::kernel::gridinterface::VertexEnumerator& fineGridVerticesEnumerator, peano::applications::poisson::multigrid::SpacetreeGridVertex const * const coarseGridVertices, const peano::kernel::gridinterface::VertexEnumerator& coarseGridVerticesEnumerator, const peano::applications::poisson::multigrid::SpacetreeGridCell& coarseGridCell, const tarch::la::Vector<DIMENSIONS,int>& fineGridPositionOfCell ) { logTraceInWith4Arguments( "enterCell(...)", fineGridCell, fineGridVerticesEnumerator.toString(), coarseGridCell, fineGridPositionOfCell ); if (!fineGridCell.isRefined()) { #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP assertionMsg( false, "here should be a critical section, but I don't know how to implement this. If you implement it, please add it to the templates, too." ); #endif assertion( DIMENSIONS==2 || DIMENSIONS==3 ); int vertexIndex[TWO_POWER_D]; dfor2(i) tarch::la::Vector<DIMENSIONS,double> currentVertexPosition = fineGridVerticesEnumerator.getVertexPosition(i); assertion2 ( _vertex2IndexMap.find(currentVertexPosition) != _vertex2IndexMap.end(), currentVertexPosition, fineGridVertices[fineGridVerticesEnumerator(i)].toString() ); vertexIndex[iScalar] = _vertex2IndexMap[currentVertexPosition]; enddforx if (DIMENSIONS==2) { _cellWriter->plotQuadrangle(vertexIndex); } if (DIMENSIONS==3) { _cellWriter->plotHexahedron(vertexIndex); } }
void peano::applications::faxen::adapters::SpacetreeGrid2PlotGrid::plotVertex( const peano::applications::faxen::SpacetreeGridVertex& fineGridVertex, const tarch::la::Vector<DIMENSIONS,double>& fineGridX ) { #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP assertionMsg( false, "here should be a critical section, but I don't know how to implement this. If you implement it, please add it to the templates, too." ); #endif if ( fineGridVertex.getRefinementControl() != peano::applications::faxen::SpacetreeGridVertex::Records::Refined && fineGridVertex.getRefinementControl() != peano::applications::faxen::SpacetreeGridVertex::Records::Refining && _vertex2IndexMap.find(fineGridX) == _vertex2IndexMap.end() ) { #if defined(Dim2) || defined(Dim3) _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(fineGridX); #else _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(tarch::la::Vector<3,double>(fineGridX.data())); #endif _vertexTypeWriter->plotVertex (_vertex2IndexMap[fineGridX],fineGridVertex.isBoundary() ); _vertexRefinementControlWriter->plotVertex(_vertex2IndexMap[fineGridX],fineGridVertex.getRefinementControl() ); _vertexMaximumSubtreeWriter->plotVertex (_vertex2IndexMap[fineGridX],fineGridVertex.getMaximumSubtreeHeight() ); } }
void peano::applications::heatequation::timestepping::adapters::SpacetreeGrid2PlotGrid::beginIteration( peano::applications::heatequation::timestepping::SpacetreeGridState& solverState ) { logTraceInWith1Argument( "beginIteration(...)", solverState ); #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP #pragma omp critical #endif _vtkWriter.clear(); _vertexWriter = _vtkWriter.createVertexWriter(); _cellWriter = _vtkWriter.createCellWriter(); #ifdef Parallel _cellDeltaWriter = _vtkWriter.createCellDataWriter( "delta" ,1); _cellWeightWriter = _vtkWriter.createCellDataWriter( "weight" ,1); #endif _vertexTypeWriter = _vtkWriter.createVertexDataWriter(peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex::Records::getInsideOutsideDomainMapping() ,1); _vertexRefinementControlWriter = _vtkWriter.createVertexDataWriter(peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex::Records::getRefinementControlMapping() ,1); _vertexMaximumSubtreeWriter = _vtkWriter.createVertexDataWriter("max-subtree" ,1); logTraceOut( "beginIteration(...)" ); }
void peano::applications::heatequation::timestepping::adapters::SpacetreeGrid2PlotGrid::plotVertex( const peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex& fineGridVertex, const tarch::la::Vector<DIMENSIONS,double>& fineGridX ) { #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP #pragma omp critical #endif if ( fineGridVertex.getRefinementControl() != peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex::Records::Refined && fineGridVertex.getRefinementControl() != peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex::Records::Refining && _vertex2IndexMap.find(fineGridX) == _vertex2IndexMap.end() ) { #if defined(Dim2) || defined(Dim3) _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(fineGridX); #else _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(tarch::la::Vector<3,double>(fineGridX.data())); #endif _vertexTypeWriter->plotVertex (_vertex2IndexMap[fineGridX],fineGridVertex.isBoundary() ); _vertexRefinementControlWriter->plotVertex(_vertex2IndexMap[fineGridX],fineGridVertex.getRefinementControl() ); _vertexMaximumSubtreeWriter->plotVertex (_vertex2IndexMap[fineGridX],fineGridVertex.getMaximumSubtreeHeight() ); } }
void peano::applications::heatequation::timestepping::adapters::SpacetreeGrid2PlotGrid::endIteration( peano::applications::heatequation::timestepping::SpacetreeGridState& solverState ) { logTraceInWith1Argument( "endIteration(...)", solverState ); #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP #pragma omp critical #endif _vertexWriter->close(); _cellWriter->close(); _vertexTypeWriter->close(); _vertexRefinementControlWriter->close(); _vertexMaximumSubtreeWriter->close(); #ifdef Parallel _cellDeltaWriter->close(); _cellWeightWriter->close(); #endif delete _vertexWriter; delete _cellWriter; delete _vertexTypeWriter; delete _vertexRefinementControlWriter; delete _vertexMaximumSubtreeWriter; #ifdef Parallel delete _cellDeltaWriter; delete _cellWeightWriter; #endif _vertexWriter = 0; _cellWriter = 0; _vertexTypeWriter = 0; _vertexRefinementControlWriter = 0; _vertexMaximumSubtreeWriter = 0; #ifdef Parallel _cellDeltaWriter = 0; _cellWeightWriter = 0; #endif std::ostringstream snapshotFileName; snapshotFileName << "vtk-grid-snapshot-SpacetreeGrid2PlotGrid-" << _snapshotCounter #ifdef Parallel << "-rank" << tarch::parallel::Node::getInstance().getRank() #endif << ".vtk"; _vtkWriter.writeToFile( snapshotFileName.str() ); _snapshotCounter++; _vertex2IndexMap.clear(); logTraceOut( "endIteration(...)" ); }
void peano::applications::poisson::jacobitutorial::mappings::RegularGrid2PlotSolution::touchVertexFirstTime( peano::applications::poisson::jacobitutorial::RegularGridVertex& vertex, const tarch::la::Vector<DIMENSIONS,double>& x ) { logTraceInWith2Arguments( "touchVertexFirstTime()", x, vertex ); /** * --- inserted manually --- * * This is now the interesting part. The first few lines in the block resemble * the one inserted by the generated grid plotter. It brings the vertex to * your screen (or vtk file respectively. The lines afterwards then set */ tarch::multicore::Lock localLock( _outputStreamSemaphore ); if ( _vertex2IndexMap.find(x) == _vertex2IndexMap.end() ) { #if defined(Dim2) || defined(Dim3) _vertex2IndexMap[x] = _vertexWriter->plotVertex(x); #else _vertex2IndexMap[x] = _vertexWriter->plotVertex(tarch::la::Vector<3,double>(x.data())); #endif _vertexResidualWriter->plotVertex(_vertex2IndexMap[x],vertex.getResidual()); _vertexValueWriter->plotVertex(_vertex2IndexMap[x],vertex.getU()); _vertexRhsWriter->plotVertex(_vertex2IndexMap[x],vertex.getRhs()); } logTraceOutWith1Argument( "touchVertexFirstTime()", vertex ); }
void peano::applications::poisson::multigrid::mappings::SpacetreeGrid2PlotSolution::plotVertex( peano::applications::poisson::multigrid::SpacetreeGridVertex& fineGridVertex, const tarch::la::Vector<DIMENSIONS,double>& fineGridX ) { if ( fineGridVertex.getRefinementControl() == SpacetreeGridVertex::Records::Unrefined ) { #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP assertionMsg( false, "here should be a critical section, but I don't know how to implement this. If you implement it, please add it to the templates, too." ); #endif if ( _vertex2IndexMap.find(fineGridX) == _vertex2IndexMap.end() ) { #if defined(Dim2) || defined(Dim3) _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(fineGridX); #else _vertex2IndexMap[fineGridX] = _vertexWriter->plotVertex(tarch::la::Vector<3,double>(fineGridX.data())); #endif if (fineGridVertex.isHangingNode()) { _vertexResidualWriter->plotVertex(_vertex2IndexMap[fineGridX],0.0); _vertexValueWriter->plotVertex(_vertex2IndexMap[fineGridX],0.0); // @todo For a smooth plot, it might make sense to set the 'right' rhs, i.e. // the rhs belonging to a persistent vertex at this very position. _vertexRhsWriter->plotVertex(_vertex2IndexMap[fineGridX],0.0); } else { _vertexResidualWriter->plotVertex(_vertex2IndexMap[fineGridX],fineGridVertex.getResidual()); _vertexValueWriter->plotVertex(_vertex2IndexMap[fineGridX],fineGridVertex.getU()); _vertexRhsWriter->plotVertex(_vertex2IndexMap[fineGridX],fineGridVertex.getRhs()); } } } }
///////////////////////////////////////////////////////////////////////////////// // Returns the Local IP ///////////////////////////////////////////////////////////////////////////////// DWORD CUPnpMgr::GetLocalIP() { CSingleLock localLock(&m_cs, TRUE); if(m_uLocalIP == 0) InitLocalIP(); return m_uLocalIP; }
///////////////////////////////////////////////////////////////////////////////// // Returns a CString with the local IP in format xxx.xxx.xxx.xxx ///////////////////////////////////////////////////////////////////////////////// CString CUPnpMgr::GetLocalIPStr() { CSingleLock localLock(&m_cs, TRUE); if(m_slocalIP.IsEmpty()) InitLocalIP(); return m_slocalIP; }
void OsLockingList::push(void* element) { assert(element); UtlVoidPtr* elementContainer = new UtlVoidPtr(element); // Lock before accessing the list OsLock localLock(listMutex); list.append(elementContainer); }
void CUPnpMgr::ReadAddedMappingFromFile(void) { CSingleLock localLock(&m_cs, TRUE); CleanupMappingArr(); CString strDatFile; strDatFile.Format(_T("%sUPnp.dat"), thePrefs.GetMuleDirectory(EMULE_CONFIGDIR)); CFile file; try { if (!file.Open(strDatFile, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite)) return; if (0 == file.GetLength()) { file.Close(); return; } } catch (CFileException *e) { e->Delete(); e = NULL; file.Close(); return; } try { CArchive ar(&file, CArchive::load); int iCount; ar >> iCount; int i; CUPnpNatMappingKey key; for (i = 0; i < iCount; i++) { key.Serialize(ar); m_setAddedMapping.insert(key); } ar.Close(); } catch (CArchiveException *e) { e->Delete(); e = NULL; } file.Close(); }
// -------------------------------------------------------------------------- // QueueMsgBuf // /// Push the provided MsgBuf onto the received message queue. /// /// @param pMsgBuf - the MsgBuf to be added to the queue. // -------------------------------------------------------------------------- void MessageManager::QueueMsgBuf(MsgBuf* pMsgBuf) { // lock the queue during this block of code TSQCriticalSection<MsgBuf*> localLock(m_rspQueue); // push the message buffer on the response queue m_rspQueue.push(pMsgBuf); // signal that a message has arrived ::SetEvent(m_hMsgEvent); }
void* XMLPlatformUtils::compareAndSwap ( void** toFill, const void* const newValue, const void* const toCompare) { XMLMutexLock localLock(atomicOpsMutex); void *retVal = *toFill; if (*toFill == toCompare) { *toFill = (void *)newValue; } return retVal; }
void* OsLockingList::pop() { void* element = NULL; // Lock before accessing the list OsLock localLock(listMutex); if (list.entries()) { UtlVoidPtr* elementContainer = dynamic_cast<UtlVoidPtr*>(list.last()); list.removeReference(elementContainer); element = (void*) elementContainer->getValue(); delete elementContainer; } return(element); }
void CUPnpMgr::RemoveNATPortMapping(const CUPnpNatMappingKey &mappingKey) { CSingleLock localLock(&m_cs, TRUE); if (FAILED(m_nat.SearchDevice())) return; HRESULT hr; hr = m_nat.DeletePortMapping(mappingKey.m_strRemoteHost, mappingKey.m_usExternalPort, mappingKey.m_strProtocol); if (SUCCEEDED(hr) || 714 == GetLastActionErrorCode()) // No such entry in array { m_setAddedMapping.erase(mappingKey); WriteAddedMappingToFile(); } }
///////////////////////////////////////////////////////////////////////////////// // Initializes m_localIP variable, for future access to GetLocalIP() ///////////////////////////////////////////////////////////////////////////////// void CUPnpMgr::InitLocalIP() { CSingleLock localLock(&m_cs, TRUE); #ifndef _DEBUG try #endif { PIP_ADAPTER_INFO pAdapterInfo = NULL, pCurAdapterInfo; ULONG ulOutBufLen = 0; DWORD dwRetVal = 0; pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) ); ulOutBufLen = sizeof(IP_ADAPTER_INFO); dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); if (ERROR_BUFFER_OVERFLOW == dwRetVal) { free(pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); } if (ERROR_SUCCESS == dwRetVal) { pCurAdapterInfo = pAdapterInfo; UINT32 ip; do { ip = inet_addr(pCurAdapterInfo->GatewayList.IpAddress.String); m_slocalIP = pCurAdapterInfo->IpAddressList.IpAddress.String; m_uLocalIP = inet_addr(pCurAdapterInfo->IpAddressList.IpAddress.String); } while(ip == 0 && (pCurAdapterInfo = pCurAdapterInfo->Next) != NULL); } free(pAdapterInfo); pAdapterInfo = NULL; } #ifndef _DEBUG catch(...){ m_slocalIP = _T(""); m_uLocalIP = 0; } #endif }
void peano::applications::heatequation::timestepping::adapters::SpacetreeGrid2PlotGrid::enterCell( peano::applications::heatequation::timestepping::SpacetreeGridCell& fineGridCell, peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex * const fineGridVertices, const peano::kernel::gridinterface::VertexEnumerator& fineGridVerticesEnumerator, peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex const * const coarseGridVertices, const peano::kernel::gridinterface::VertexEnumerator& coarseGridVerticesEnumerator, const peano::applications::heatequation::timestepping::SpacetreeGridCell& coarseGridCell, const tarch::la::Vector<DIMENSIONS,int>& fineGridPositionOfCell ) { logTraceInWith5Arguments( "enterCell(...)", fineGridCell, fineGridVerticesEnumerator.toString(), coarseGridVerticesEnumerator.toString(), coarseGridCell, fineGridPositionOfCell ); #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP #pragma omp critical #endif if ( fineGridCell.isLeaf() ) { assertion( DIMENSIONS==2 || DIMENSIONS==3 ); int vertexIndex[TWO_POWER_D]; dfor2(i) tarch::la::Vector<DIMENSIONS,double> currentVertexPosition = fineGridVerticesEnumerator.getVertexPosition(i); assertion1 ( _vertex2IndexMap.find(currentVertexPosition) != _vertex2IndexMap.end(), currentVertexPosition ); vertexIndex[iScalar] = _vertex2IndexMap[currentVertexPosition]; enddforx int cellIndex; if (DIMENSIONS==2) { cellIndex = _cellWriter->plotQuadrangle(vertexIndex); } if (DIMENSIONS==3) { cellIndex = _cellWriter->plotHexahedron(vertexIndex); } #ifdef Parallel _cellDeltaWriter->plotCell( cellIndex,fineGridCell.getDelta() ); _cellWeightWriter->plotCell( cellIndex,fineGridCell.getWeight() ); #endif } logTraceOut( "enterCell(...)" ); }
void peano::applications::faxen::adapters::SpacetreeGrid2PlotGrid::enterCell( peano::applications::faxen::SpacetreeGridCell& fineGridCell, peano::applications::faxen::SpacetreeGridVertex * const fineGridVertices, const peano::kernel::gridinterface::VertexEnumerator& fineGridVerticesEnumerator, peano::applications::faxen::SpacetreeGridVertex const * const coarseGridVertices, const peano::kernel::gridinterface::VertexEnumerator& coarseGridVerticesEnumerator, const peano::applications::faxen::SpacetreeGridCell& coarseGridCell, const tarch::la::Vector<DIMENSIONS,int>& fineGridPositionOfCell ) { logTraceInWith5Arguments( "enterCell(...)", fineGridCell, fineGridVerticesEnumerator.toString(), coarseGridVerticesEnumerator.toString(), coarseGridCell, fineGridPositionOfCell ); #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP assertionMsg( false, "here should be a critical section, but I don't know how to implement this. If you implement it, please add it to the templates, too." ); #endif if ( fineGridCell.isLeaf() ) { assertion( DIMENSIONS==2 || DIMENSIONS==3 ); int vertexIndex[TWO_POWER_D]; dfor2(i) tarch::la::Vector<DIMENSIONS,double> currentVertexPosition = fineGridVerticesEnumerator.getVertexPosition(i); assertion1 ( _vertex2IndexMap.find(currentVertexPosition) != _vertex2IndexMap.end(), currentVertexPosition ); vertexIndex[iScalar] = _vertex2IndexMap[currentVertexPosition]; enddforx int cellIndex; if (DIMENSIONS==2) { cellIndex = _cellWriter->plotQuadrangle(vertexIndex); } if (DIMENSIONS==3) { cellIndex = _cellWriter->plotHexahedron(vertexIndex); } #ifdef Parallel _cellDeltaWriter->plotCell( cellIndex,fineGridCell.getDelta() ); _cellWeightWriter->plotCell( cellIndex,fineGridCell.getWeight() ); #endif } logTraceOut( "enterCell(...)" ); }
double peano::applications::diffusionequation::Solver::getNewTemperatureForExplicitEulerStep( const tarch::la::Vector<DIMENSIONS,double>& h, double residual, const double & oldTemperature ) { const double cellVolume = tarch::la::volume(h); assertion1( _timeStepSize>0.0, _timeStepSize ); assertion1( cellVolume>0.0, cellVolume ); residual *= _timeStepSize / cellVolume; const double diagonalValue = 1.0; assertion1( _smoother.getOmega(), 1.0 ); tarch::multicore::Lock localLock(_normSemaphore); return _smoother.getNewValueOfJacobiStep(oldTemperature,residual,diagonalValue,cellVolume); }
void CUPnpMgr::CleanupAllEverMapping(void) { CSingleLock localLock(&m_cs, TRUE); //ADDED by VC-fengwen 2007/08/23 <begin> : 没有映射项的话则不用执行下去。 if (0 == m_setAddedMapping.size()) return; //ADDED by VC-fengwen 2007/08/23 <end> : 没有映射项的话则不用执行下去。 if (FAILED(m_nat.SearchDevice())) return; HRESULT hr; set<CUPnpNatMappingKey>::iterator it; set<CUPnpNatMappingKey>::iterator itNext; int iOpCount; iOpCount = 0; it = m_setAddedMapping.begin(); while (it != m_setAddedMapping.end()) { itNext = it; itNext++; hr = m_nat.DeletePortMapping(it->m_strRemoteHost, it->m_usExternalPort, it->m_strProtocol); if (SUCCEEDED(hr) || 714 == GetLastActionErrorCode() // No such entry in array || 402 == GetLastActionErrorCode()) // Some router will return 402 for some reason. Delete it as well anyway. { m_setAddedMapping.erase(it); } iOpCount++; if (iOpCount >= 10) // 防止一些路由器不能一次处理太多请求,删除操作最多不大于10次,由于一般启动eMule只会开2个端口,这个数值应该是够的。 break; it = itNext; } WriteAddedMappingToFile(); }
void peano::applications::heatequation::timestepping::adapters::SpacetreeGrid2PlotGrid::createHangingVertex( peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex& fineGridVertex, const tarch::la::Vector<DIMENSIONS,double>& fineGridX, const tarch::la::Vector<DIMENSIONS,double>& fineGridH, peano::applications::heatequation::timestepping::SpacetreeGridSingleStepVertex const * const coarseGridVertices, const peano::kernel::gridinterface::VertexEnumerator& coarseGridVerticesEnumerator, const peano::applications::heatequation::timestepping::SpacetreeGridCell& coarseGridCell, const tarch::la::Vector<DIMENSIONS,int>& fineGridPositionOfVertex ) { #ifdef SharedTBB Vertex2IndexMapSemaphore::scoped_lock localLock(_vertex2IndexMapSemaphore); #elif SharedOMP #pragma omp critical #endif plotVertex( fineGridVertex, fineGridX ); }
double peano::applications::diffusionequation::Solver::getNewTemperatureForImplicitEulerStep( const tarch::la::Vector<DIMENSIONS,double>& h, double residual, const peano::toolbox::stencil::Stencil& stencil, const double & newTemperatureSoFar ) { assertion1( _timeStepSize>0.0, _timeStepSize ); assertion1( tarch::la::volume(h)>0.0, h ); double diagonalElement = tarch::la::volume(h) * _elementMatrix.getDiagonalElement(_massMatrixWithoutHScaling) + _timeStepSize * _elementMatrix.getDiagonalElement(stencil); assertion( diagonalElement>0.0 ); tarch::multicore::Lock localLock(_normSemaphore); return _smoother.getNewValueOfJacobiStep( newTemperatureSoFar, residual, diagonalElement, tarch::la::volume(h) ); }
// -------------------------------------------------------------------------- // ProcessThread // /// The process thread repeatedly takes a buffer from the received queue, /// creates the appropriate Message and broadcasts the Message to all objects /// that have regestered to be notified. // -------------------------------------------------------------------------- void MessageManager::ProcessThread() { HANDLE waitHandles[2] = {m_hProcessExitEvent,m_hMsgEvent}; // process messages when available until exit is triggered while (::WaitForMultipleObjects(2,waitHandles,FALSE,INFINITE) != WAIT_OBJECT_0) { // get a message off the queue m_rspQueue.lock(); MsgBuf* pMsgBuf = m_rspQueue.front(); m_rspQueue.pop(); m_rspQueue.unlock(); // build a message reference counted pointer from the message buffer MessageRCP msgRCP = MessageFactory::GetInstance().CreateMessage(*pMsgBuf); if (!msgRCP.IsNull()) { // notify subscribers message received NoticeRCP noticeRCP = THeapObject<MsgNotice>::Create(msgRCP); NotifySubscribers(noticeRCP); } // delete the used message buffer delete pMsgBuf; // if no more messages to process, reset msg event TSQCriticalSection<MsgBuf*> localLock(m_rspQueue); if (m_rspQueue.empty()) { ::ResetEvent(m_hMsgEvent); } } }
/////////////////////////////////////////////////////////////////////////////// // // 函数功能描述:简单日志打印 // 输入:日志级别,格式字串 // 输出:向窗口或文件写日志,不含日期、时间、类型、文件名、代码行信息 // 返回值: // 其它说明: // /////////////////////////////////////////////////////////////////////////////// void CLogTrace::TraceSim(BYTE cLevel, LPCTSTR lpszFormat, ...) { if(IsLogFileEnable()==FALSE)return; //LOGLEVEL_HIGH级别以下的日志打印在Release版中直接返回 #ifndef _DEBUG if (cLevel > LOGL_LOW) { return; } #endif //合法性检测 if (!lpszFormat) { OutputDebugString(_T("Error: lpszFormat is NULL\r\n")); return; } //读取参数 va_list args; va_start(args, lpszFormat); CLocalLock localLock(&m_lock); //锁 //打入字串 m_szBuffer[1][0] = 0; int nBuf = _sntprintf(m_szBuffer[1], MAX_LEN_OF_LOG_LINE, lpszFormat, args); va_end(args); if (nBuf < 0) //出错 { //有可能是字符串太长 m_szBuffer[1][MAX_LEN_OF_LOG_LINE - 1] = 0; } //打印 TraceColor(cLevel, LOGC_PROMPT); }
void CUPnpMgr::WriteAddedMappingToFile(void) { CSingleLock localLock(&m_cs, TRUE); CString strDatFile; strDatFile.Format(_T("%sUPnp.dat"), thePrefs.GetMuleDirectory(EMULE_CONFIGDIR)); CFile file; if (!file.Open(strDatFile, CFile::modeCreate | CFile::modeReadWrite)) return; try { CArchive ar(&file, CArchive::store); int iCount; iCount = m_setAddedMapping.size(); ar << iCount; set<CUPnpNatMappingKey>::iterator it; for (it = m_setAddedMapping.begin(); it != m_setAddedMapping.end(); it++) { //it->Serialize(ar); CUPnpNatMappingKey key(*it); key.Serialize(ar); } ar.Close(); } catch (CArchiveException *e) { e->Delete(); e = NULL; } file.Close(); }
int XMLPlatformUtils::atomicDecrement(int &location) { XMLMutexLock localLock(atomicOpsMutex); return --location; }
/* ============================ ACCESSORS ================================= */ int OsLockingList::getCount() { OsLock localLock(listMutex); return(list.entries()); }
/* ----------------------------------------------------------- bus_config --- */ double RTcmix::bus_config(float p[], int n_args, double pp[]) { ErrCode err; int i, j, k, startchan, endchan; char *str, *instname, *busname; BusType type; BusSlot *bus_slot; char inbusses[80], outbusses[80]; // for verbose message if (n_args < 2) die("bus_config", "Wrong number of args."); bus_slot = new BusSlot; if (bus_slot == NULL) return -1.0; inbusses[0] = outbusses[0] = '\0'; Lock localLock(&bus_slot_lock); // This will unlock when going out of scope. /* do the old Minc casting rigamarole to get string pointers from a double */ str = DOUBLE_TO_STRING(pp[0]); instname = strdup(str); // Note: If we exit nonfatally, we have to free. for (i = 1; i < n_args; i++) { busname = DOUBLE_TO_STRING(pp[i]); err = parse_bus_name(busname, &type, &startchan, &endchan); if (err) goto error; switch (type) { case BUS_IN: if (bus_slot->in_count > 0) strcat(inbusses, ", "); strcat(inbusses, busname); if (bus_slot->auxin_count > 0) { die("bus_config", "Can't have 'in' and 'aux-in' buses in same bus_config."); } j = bus_slot->in_count; for (k = startchan; k <= endchan; k++) bus_slot->in[j++] = k; bus_slot->in_count += (endchan - startchan) + 1; /* Make sure max channel count set in rtsetparams can accommodate the highest input chan number in this bus config. */ if (endchan >= NCHANS) { die("bus_config", "You specified %d channels in rtsetparams,\n" "but this bus_config requires %d channels.", NCHANS, endchan + 1); } break; case BUS_OUT: if (bus_slot->out_count > 0) strcat(outbusses, ", "); strcat(outbusses, busname); if (bus_slot->auxout_count > 0) { die("bus_config", "Can't have 'out' and 'aux-out' buses in same bus_config."); } j = bus_slot->out_count; for (k = startchan; k <= endchan; k++) { bus_slot->out[j++] = k; pthread_mutex_lock(&out_in_use_lock); OutInUse[k] = YES; // DJT added pthread_mutex_unlock(&out_in_use_lock); } bus_slot->out_count += (endchan - startchan) + 1; /* Make sure max output chans set in rtsetparams can accommodate the highest output chan number in this bus config. */ if (endchan >= NCHANS) { die("bus_config", "You specified %d output channels in rtsetparams,\n" "but this bus_config requires %d channels.", NCHANS, endchan + 1); } break; case BUS_AUX_IN: if (bus_slot->auxin_count > 0) strcat(inbusses, ", "); strcat(inbusses, busname); if (bus_slot->in_count > 0) { die("bus_config", "Can't have 'in' and 'aux-in' buses in same bus_config."); } j = bus_slot->auxin_count; for (k = startchan; k <= endchan; k++) bus_slot->auxin[j++] = k; bus_slot->auxin_count += (endchan - startchan) + 1; break; case BUS_AUX_OUT: if (bus_slot->auxout_count > 0) strcat(outbusses, ", "); strcat(outbusses, busname); if (bus_slot->out_count > 0) { die("bus_config", "Can't have 'out' and 'aux-out' buses in same bus_config."); } j = bus_slot->auxout_count; for (k = startchan; k <= endchan; k++) { bus_slot->auxout[j++] = k; pthread_mutex_lock(&aux_out_in_use_lock); AuxOutInUse[k] = YES; pthread_mutex_unlock(&aux_out_in_use_lock); } bus_slot->auxout_count += (endchan - startchan) + 1; break; default: break; } } err = check_bus_inst_config(bus_slot, YES); if (!err) { err = insert_bus_slot(instname, bus_slot); } if (err) // BGG mm -- print an error, don't exit die("bus_config", "couldn't configure the busses"); // exit(1); /* This is probably what user wants? */ /* Make sure specified aux buses have buffers allocated. */ for (i = 0; i < bus_slot->auxin_count; i++) allocate_aux_buffer(bus_slot->auxin[i], RTBUFSAMPS); for (i = 0; i < bus_slot->auxout_count; i++) allocate_aux_buffer(bus_slot->auxout[i], RTBUFSAMPS); #ifdef PRINTALL print_children(); print_parents(); #endif create_play_order(); #ifdef PRINTPLAY print_play_order(); #endif #ifdef DEBUG err = print_inst_bus_config(); #endif rtcmix_advise("bus_config", "(%s) => %s => (%s)", inbusses, instname, outbusses); free(instname); return 0.0; error: free(instname); die("bus_config", "Cannot parse arguments."); return -1.0; }
/////////////////////////////////////////////////////////////////////////////// // // 函数功能描述:标准日志打印 // 输入:日志级别、类型、源文件名、代码行,格式字串 // 输出:向窗口或文件写日志 // 返回值: // 其它说明: // /////////////////////////////////////////////////////////////////////////////// void CLogTrace::Trace(BYTE cLevel, BYTE cType, const TCHAR * pszSourceFile, DWORD dwLine, LPCTSTR lpszFormat, ...) { if (! IsLogFileEnable()) return; //指定类型级别以下的日志不打印; if ( m_nOutLogLevel < cType ) { return; } //合法性检测 if (!pszSourceFile || !lpszFormat) { OutputDebugString(_T("Error: pszSourceFile or lpszFormat is NULL\r\n")); return; } //读取参数 va_list args; va_start(args, lpszFormat); CLocalLock localLock(&m_lock); //锁 //打入字串 m_szBuffer[0][0] = 0; int nBuf = -1; if(cType == LOGT_COMPRESS) //对打印的日志进行压缩 { TCHAR *tmp = new TCHAR[200000]; memset(tmp,0,200000 * sizeof(TCHAR)); int nBuf = _vsntprintf(tmp,200000-1,lpszFormat,args); CString strSource,strZipData; strSource.Format(_T("%s"),tmp); if (strSource.GetLength() < 100) { strZipData = strSource; } else { ZipEecodeStdString(strSource,strZipData); } _tcsncpy(m_szBuffer[0],strZipData.GetBuffer(strZipData.GetLength()),MAX_LEN_OF_LOG_LINE-128); strZipData.ReleaseBuffer(); delete []tmp; } else { nBuf = _vsntprintf(m_szBuffer[0], MAX_LEN_OF_LOG_LINE - 128, lpszFormat, args); } va_end(args); if (nBuf < 0) //出错 { //有可能是字符串太长 m_szBuffer[0][MAX_LEN_OF_LOG_LINE - 128] = 0; } //取系统日期、时间 TCHAR szData[12], szTime[12]; _tstrdate(szData); _tstrtime(szTime); //类型字串及颜色 CString strType; DWORD dwColor = 0; //获取日志的类型文本及颜色 GetLogType(strType,dwColor,cType); //源文件名缩短处理 TCHAR * pszSourceShort = NULL; TCHAR szSourceShort[MAX_PATH]; WORD wSourceNameLen = lstrlen(pszSourceFile); if (wSourceNameLen > LEN_SHORT_SOURCEFILE_NAME) //太长 { wsprintf(szSourceShort, _T("...%s"), pszSourceFile + (wSourceNameLen - LEN_SHORT_SOURCEFILE_NAME)); pszSourceShort = szSourceShort; } else { pszSourceShort = (TCHAR *)pszSourceFile; } //形成结果字串 nBuf = _sntprintf(m_szBuffer[1], MAX_LEN_OF_LOG_LINE, _T("%s %s [%d]%s: %s at %d in %s\r\n"), szData, szTime, GetCurrentThreadId(), strType.GetBuffer(), m_szBuffer[0], dwLine, pszSourceShort); if (nBuf < 0) //出错 { //有可能是字符串太长 m_szBuffer[1][MAX_LEN_OF_LOG_LINE - 1] = 0; } strType.ReleaseBuffer(); //打印 TraceColor(cLevel, dwColor); }