static void touchAllocatedPages( void ) { MEM_INFO_HEADER *memHdrPtr; const int pageSize = getSysVar( SYSVAR_PAGESIZE ); /* Lock the allocation object to ensure that other threads don't try to access them */ MUTEX_LOCK( allocation ); /* Walk down the list (which implicitly touches each page). If the allocated region is larger than the page size, explicitly touch each additional page */ for( memHdrPtr = krnlData->allocatedListHead; memHdrPtr != NULL; memHdrPtr = memHdrPtr->next ) { /* If the allocated region has pages beyond the first one (which we've already touched by accessing the header), explicitly touch those pages as well */ if( memHdrPtr->size > pageSize ) { BYTE *memPtr = ( BYTE * ) memHdrPtr + pageSize; int memSize = memHdrPtr->size; /* Touch each page. The rather convoluted expression is to try and stop it from being optimised away - it always evaluates to true since we only get here if allocatedListHead != NULL, but hopefully the compiler won't be able to figure that out */ while( memSize > pageSize ) { if( *memPtr || krnlData->allocatedListHead != NULL ) memPtr += pageSize; memSize -= pageSize; } } } /* Unlock the allocation object to allow access by other threads */ MUTEX_UNLOCK( allocation ); }
ArxDbgUiPrBase::Status ArxDbgUiPrEntity::go() { CString prompt; int result; int errNum; ads_point adsPt; ads_name ent; AcDbObjectId tmpId; AcDbEntity* tmpEnt; Acad::ErrorStatus es; prompt.Format(_T("\n%s: "), message()); while (1) { acedInitGet(0, keyWords()); result = acedEntSel(prompt, ent, adsPt); if (result == RTNORM) { ArxDbgUtils::enameToObjId(ent, tmpId); es = acdbOpenAcDbEntity(tmpEnt, tmpId, AcDb::kForRead); if (es == Acad::eOk) { // if its correct class and we are not filtering locked layers its ok, // or if we are filtering locked layers and this one isn't on a locked layer if (correctClass(tmpEnt)) { // correctClass() will print error msg if ((!m_filterLockedLayers) || (ArxDbgUtils::isOnLockedLayer(tmpEnt, true) == false)) { // isOnLockedLayer() will print error msg tmpEnt->close(); m_pickPt = asPnt3d(adsPt); m_objId = tmpId; return ArxDbgUiPrBase::kOk; } } tmpEnt->close(); // close and loop again until they get it right! } else { ASSERT(0); ArxDbgUtils::rxErrorMsg(es); return ArxDbgUiPrBase::kCancel; } } else if (result == RTERROR) { getSysVar(AcadVar::adserr, errNum); if (errNum == OL_ENTSELPICK) // picked but didn't get anything acutPrintf(_T("\nNothing selected.")); else if (errNum == OL_ENTSELNULL) { // hit RETURN or SPACE if (m_allowNone) return ArxDbgUiPrBase::kNone; // prompt specifically wants to know about None else return ArxDbgUiPrBase::kCancel; // prompt wants to bail on None } else acutPrintf(_T("\nNothing selected.")); } else if (result == RTKWORD) { acedGetInput(m_keyWordPicked.GetBuffer(512)); m_keyWordPicked.ReleaseBuffer(); return ArxDbgUiPrBase::kKeyWord; } else if (result == RTNONE) { return ArxDbgUiPrBase::kNone; } else return ArxDbgUiPrBase::kCancel; } }
static void unlockMemory( INOUT MEM_INFO_HEADER *memHdrPtr ) { MEM_INFO_HEADER *currentBlockPtr; PTR_TYPE block1PageAddress, block2PageAddress; const int pageSize = getSysVar( SYSVAR_PAGESIZE ); assert( isWritePtr( memHdrPtr, sizeof( MEM_INFO_HEADER ) ) ); /* If the memory block isn't locked, there's nothing to do */ if( !( memHdrPtr->flags & MEM_FLAG_LOCKED ) ) return; /* Because VirtualLock() works on a per-page basis, we can't unlock a memory block if there's another locked block on the same page. The only way to manage this is to walk the block list checking to see whether there's another block allocated on the same page. Although in theory this could make freeing memory rather slow, in practice there are only a small number of allocated blocks to check so it's relatively quick, especially compared to the overhead imposed by the lethargic VC++ allocator. The only real disadvantage is that the allocation objects remain locked while we do the free, but this isn't any worse than the overhead of touchAllocatedPages(). Note that the following code assumes that an allocated block will never cover more than two pages, which is always the case. First we calculate the addresses of the page(s) in which the memory block resides */ block1PageAddress = getPageStartAddress( memHdrPtr ); block2PageAddress = getPageEndAddress( memHdrPtr, memHdrPtr->size ); if( block1PageAddress == block2PageAddress ) block2PageAddress = 0; /* Walk down the block list checking whether the page(s) contain another locked block */ for( currentBlockPtr = krnlData->allocatedListHead; \ currentBlockPtr != NULL; currentBlockPtr = currentBlockPtr->next ) { const PTR_TYPE currentPage1Address = \ getPageStartAddress( currentBlockPtr ); PTR_TYPE currentPage2Address = \ getPageEndAddress( currentBlockPtr, currentBlockPtr->size ); if( currentPage1Address == currentPage2Address ) currentPage2Address = 0; /* If there's another block allocated on either of the pages, don't unlock it */ if( block1PageAddress == currentPage1Address || \ block1PageAddress == currentPage2Address ) { block1PageAddress = 0; if( !block2PageAddress ) break; } if( block2PageAddress == currentPage1Address || \ block2PageAddress == currentPage2Address ) { block2PageAddress = 0; if( !block1PageAddress ) break; } } /* Finally, if either page needs unlocking, do so. The supplied size is irrelevant since the entire page the memory is on is unlocked */ if( block1PageAddress ) VirtualUnlock( ( void * ) block1PageAddress, 16 ); if( block2PageAddress ) VirtualUnlock( ( void * ) block2PageAddress, 16 ); }
void ArxDbgDbAdeskLogo::drawSingleCaliper(AcGiCommonDraw* drawContext, AcGePoint3d* pts, ArxDbgDbAdeskLogoStyle* lStyle) { AcGeVector3d viewDir; AcGiViewportDraw* vportDraw = AcGiViewportDraw::cast(drawContext); if (vportDraw) viewDir = vportDraw->viewport().viewDir(); else { // cheat and get viewdir for current viewport from the system variable AcGePoint3d tmpPt; getSysVar(_T("viewdir"), tmpPt); viewDir = tmpPt.asVector(); } if (viewDir == AcGeVector3d::kZAxis) { // if solid fill is on we have to save the current state // first and then restore it. If we don't, then if we // are drawn as part of some other entity, we'll mess it up // for them. if (lStyle && (lStyle->isSolidFill()) && (drawContext->isDragging() == Adesk::kFalse)) { AcGiFillType savedFillType = drawContext->subEntityTraits().fillType(); drawContext->subEntityTraits().setFillType(kAcGiFillAlways); drawContext->rawGeometry()->polygon(5, pts); drawContext->subEntityTraits().setFillType(savedFillType); } else { drawContext->rawGeometry()->polygon(5, pts); } } else { AcGePoint3d allPts[10]; allPts[0] = pts[0]; allPts[1] = pts[1]; allPts[2] = pts[2]; allPts[3] = pts[3]; allPts[4] = pts[4]; allPts[5].set(pts[0].x, pts[0].y, 1.0); allPts[6].set(pts[1].x, pts[1].y, 1.0); allPts[7].set(pts[2].x, pts[2].y, 1.0); allPts[8].set(pts[3].x, pts[3].y, 1.0); allPts[9].set(pts[4].x, pts[4].y, 1.0); Adesk::Int32 faceList[37]; // bottom face faceList[0] = 5; // number of vertices faceList[1] = 0; faceList[2] = 1; faceList[3] = 2; faceList[4] = 3; faceList[5] = 4; // top face faceList[6] = 5; // number of vertices faceList[7] = 5; faceList[8] = 6; faceList[9] = 7; faceList[10] = 8; faceList[11] = 9; // inside left face faceList[12] = 4; // number of vertices faceList[13] = 0; faceList[14] = 1; faceList[15] = 6; faceList[16] = 5; // inside right face faceList[17] = 4; // number of vertices faceList[18] = 1; faceList[19] = 2; faceList[20] = 7; faceList[21] = 6; // outside right face faceList[22] = 4; // number of vertices faceList[23] = 2; faceList[24] = 3; faceList[25] = 8; faceList[26] = 7; // outside top face faceList[27] = 4; // number of vertices faceList[28] = 3; faceList[29] = 4; faceList[30] = 9; faceList[31] = 8; // outside left face faceList[32] = 4; // number of vertices faceList[33] = 4; faceList[34] = 0; faceList[35] = 5; faceList[36] = 9; drawContext->rawGeometry()->shell(10, allPts, 37, faceList); } }
string envVar::getSysDesign() { string sysDesign = "design"; return (getSysVar(sysDesign)); }
string envVar::getSysName() { string sysName = "system"; return (getSysVar(sysName)); }