Beispiel #1
0
void ObjectMemory::deallocate(OTE* ote)
{
	#ifdef _DEBUG
		ASSERT(!ote->isFree());
		if (Interpreter::executionTrace)
		{
			tracelock lock(TRACESTREAM);
			TRACESTREAM << ote << " (" << hex << (UINT)ote << "), refs " << dec << (int)ote->m_count << ", is being deallocated" << endl;
		}
	#endif

	ASSERT(!isPermanent(ote));
	// We can have up to 256 different destructors (8 bits)
	switch (ote->heapSpace())
	{
		case OTEFlags::NormalSpace:
			freeChunk(ote->m_location);
 			releasePointer(ote);
			break;

		case OTEFlags::VirtualSpace:
			::VirtualFree(static_cast<VirtualObject*>(ote->m_location)->getHeader(), 0, MEM_RELEASE);
 			releasePointer(ote);
			break;

		case OTEFlags::BlockSpace:
			Interpreter::m_otePools[Interpreter::BLOCKPOOL].deallocate(ote);
			break;

		case OTEFlags::ContextSpace:
			// Return it to the interpreter's free list of contexts
			Interpreter::m_otePools[Interpreter::CONTEXTPOOL].deallocate(ote);
			break;

		case OTEFlags::DWORDSpace:
			Interpreter::m_otePools[Interpreter::DWORDPOOL].deallocate(ote);
			break;

		case OTEFlags::HeapSpace:
			//_asm int 3;
			HARDASSERT(FALSE);
			break;
		
		case OTEFlags::FloatSpace:
			Interpreter::m_otePools[Interpreter::FLOATPOOL].deallocate(ote);
			break;

		case OTEFlags::PoolSpace:
		{
			MWORD size = ote->sizeOf();
			HARDASSERT(size <= MaxSmallObjectSize);
			freeSmallChunk(ote->m_location, size);
			releasePointer(ote);
		}
		break;

		default:
			ASSERT(false);
	}
}
Beispiel #2
0
void UserAf::v_action( Action & i_action)
{
    bool was_permanent = isPermanent();

    const JSON & operation = (*i_action.data)["operation"];
    if( operation.IsObject())
    {
        std::string type;
        af::jr_string("type", type, operation);
        if( type.find("move_jobs_") == 0 )
        {
            std::vector<int32_t> jids;
            af::jr_int32vec("jids", jids, operation);
            if( type == "move_jobs_up" )
                m_jobslist.moveNodes( jids, AfList::MoveUp);
            else if( type == "move_jobs_down" )
                m_jobslist.moveNodes( jids, AfList::MoveDown);
            else if( type == "move_jobs_top" )
                m_jobslist.moveNodes( jids, AfList::MoveTop);
            else if( type == "move_jobs_bottom" )
                m_jobslist.moveNodes( jids, AfList::MoveBottom);
            updateJobsOrder();
            i_action.monitors->addUser( this);
        }
    }

    const JSON & params = (*i_action.data)["params"];
    if( params.IsObject())
        jsonRead( params, &i_action.log);

    if( was_permanent != isPermanent())
    {
        if( isPermanent())
            AFCommon::QueueDBAddItem( this);
        else
            AFCommon::QueueDBDelItem( this);
    }

    if( i_action.log.size() )
    {
        // Update database only is permanent parameter was not changed.
        // If it was, user is just added to or deleted from database.
        if( was_permanent == isPermanent())
            AFCommon::QueueDBUpdateItem( this);
        i_action.monitors->addEvent( af::Msg::TMonitorUsersChanged, m_id);
    }
}
Beispiel #3
0
void UserAf::v_refresh( time_t currentTime, AfContainer * pointer, MonitorContainer * monitoring)
{
    /*    if( isLocked() )
    	 {
    		  return;
    	 }*/
//printf("UserAf::refresh: \"%s\"\n", getName().toUtf8().data());
    int _numjobs = m_jobslist.getCount();
    if(( _numjobs == 0) && ( false == isPermanent()))
    {
        if( m_zombietime )
        {
            if( (currentTime-m_zombietime) > af::Environment::getUserZombieTime() )
            {
                appendLog( std::string("ZOMBIETIME: " + af::itos( af::Environment::getUserZombieTime()) + " seconds with no job."));
                v_setZombie( monitoring);
                return;
            }
        }
        else
        {
            m_zombietime = currentTime;
        }
        return;
    }
    else m_zombietime = 0;

    int _numrunningjobs = 0;
    int _runningtasksnumber = 0;
    {
        AfListIt jobsListIt( &m_jobslist);
        for( AfNodeSrv *job = jobsListIt.node(); job != NULL; jobsListIt.next(), job = jobsListIt.node())
        {
            if( ((JobAf*)job)->isRunning())
            {
                _numrunningjobs++;
                _runningtasksnumber += ((JobAf*)job)->getRunningTasksNumber();
            }
        }
    }

    if((( _numrunningjobs      != m_running_jobs_num       ) ||
            ( _numjobs             != m_jobs_num              ) ||
            ( _runningtasksnumber  != m_running_tasks_num   )) &&
            monitoring )
        monitoring->addEvent( af::Msg::TMonitorUsersChanged, m_id);

    m_jobs_num = _numjobs;
    m_running_jobs_num = _numrunningjobs;
    m_running_tasks_num = _runningtasksnumber;

    // Update solving parameters:
    v_calcNeed();
}
Beispiel #4
0
/*!
  Remove a read-only object. Only the base should  make use of this function.
  @see removeObject()
  @return True if the object was deleted as requested. False otherwise.
 */
bool rtObjectManager::removeReadOnly(int objID) {
  rtRenderObject* temp;

  // Lock this function
  QMutexLocker locker(&m_objectLock);

  if (m_objectHash.contains(objID)) {
    temp = m_objectHash.value(objID);
    if (!temp || isPermanent(objID)) return false;
    m_objectHash.remove(objID);
    if (m_list2DHash.remove(objID)>0 && rtApplication::instance().getMainWinHandle()) {
      rtApplication::instance().getMainWinHandle()->update2DWindowLists(&m_list2DHash);
    }
    delete temp;
    emit objectRemoved(objID);
    return true;
  }
  return false;
}
Beispiel #5
0
OTE* __fastcall ObjectMemory::recursiveFree(OTE* rootOTE)
{
	HARDASSERT(!isIntegerObject(rootOTE));
	HARDASSERT(!isPermanent(rootOTE));
	HARDASSERT(!rootOTE->isFree());
	HARDASSERT(rootOTE->m_flags.m_count == 0);

#ifndef _AFX
	if (rootOTE->isFinalizable())
	{
		finalize(rootOTE);
		rootOTE->beUnfinalizable();
	}
	else
#endif
	{
		// Deal with the class first, as this is now held in the OTE
		recursiveCountDown(reinterpret_cast<POTE>(rootOTE->m_oteClass));

		if (rootOTE->isPointers())
		{
			// Recurse through referenced objects as necessary
			const MWORD lastPointer = rootOTE->getWordSize();
			Oop* pFields = reinterpret_cast<Oop*>(rootOTE->m_location);
			// Start after the header (only includes size now, which is not an Oop)
			for (MWORD i = ObjectHeaderSize; i < lastPointer; i++)
			{
				Oop fieldPointer = pFields[i];
				if (!isIntegerObject(fieldPointer))
				{
					OTE* fieldOTE = reinterpret_cast<OTE*>(fieldPointer);
					recursiveCountDown(fieldOTE);
				}
			}
		}

		deallocate(rootOTE);
	}

	return rootOTE;		// Important for some assembler routines - will be non-zero, so can act as TRUE
}
Beispiel #6
0
void TendonInsertionPoint::createInsertionGeometry()
{
	SoTransform *linkIVTran;

	IVInsertion = new SoSeparator;
	IVInsertionMaterial = new SoMaterial;
	IVInsertionTran = new SoTransform;
	IVInsertionGeom = new SoSphere;

	/*insert a pointer to the transform of the link this insertion point is attached to
	like this, we don't have to worry about updating anything.
	One problem: cleanup. This reference might prevent link's tranform IV node from being deleted when it should be
	*/
	linkIVTran = getAttachedLink()->getIVTran();
	IVInsertion->addChild(linkIVTran);

	/* insertion point's location relative to link's origin*/
	IVInsertionTran->translation.setValue(attachPoint.x() , attachPoint.y() , attachPoint.z() );
	IVInsertion->addChild(IVInsertionTran);

	if ( isPermanent() )
	{
		IVInsertionMaterial->diffuseColor.setValue( (float)0.7 , (float)0.2 , (float)0.2);
		IVInsertionGeom->radius=(float)1.5;
	}
	else
	{
		if (owner->isSelected())
			IVInsertionMaterial->diffuseColor.setValue( (float)1.0 , (float)0.5 , (float)0.5);
		else
			IVInsertionMaterial->diffuseColor.setValue( (float)0.5 , (float)0.5 , (float)0.5);
		IVInsertionGeom->radius=(float)0.8;
	}
	IVInsertion->addChild(IVInsertionMaterial);
	IVInsertion->addChild(IVInsertionGeom);
}
Beispiel #7
0
bool Condition::isRemovable(){
	return (!isActive() && !isPermanent());
}
Packet*
PacketReceiver::receiveAndCreatePacket(int32 micros,
                                       TCPSocket** tcpReceiverSock) 
{
   // Variables that must be set before creating the packet
   byte* buffer = NULL;
   /*ssize_t*/uint32 bufferLength = 0;
   int packetLength = 0;
   
   // Used to get the correct socket to read from
   TCPSocket* tcpSock;
   DatagramReceiver* datagramSock;

   // Reset tcpReceiverSock
   if ( tcpReceiverSock != NULL ) {
      *tcpReceiverSock = NULL;
   }
   
   if ( m_receiver.select( micros, tcpSock, datagramSock ) ) {
      if ( tcpSock != NULL ) {
         // Set the socket to read from depending on the state
         TCPSocket* readSocket = tcpSock;
         bool deleteReadSocket = false;
         bool keepSocket = false; // Override on deleteReadSocket

         if (tcpSock->getState() == TCPSocket::LISTEN) {
            uint32 acceptStartTime = TimeUtility::getCurrentTime();
            readSocket = tcpSock->accept();
            uint32 acceptTime = TimeUtility::getCurrentTime() - acceptStartTime;
            if ( acceptTime > 1000 ) {
               mc2dbg << "[PR]: Took " << acceptTime
                      << " to accept which is unacceptable" << endl;
            }
            // Check if the socket should be permanently added.
            if ( isPermanent( tcpSock ) ) {
               mc2dbg8 << "[PR]: Socket is permanent" << endl;
               // Yes - add the child socket too.
               addPermanentTCPSocket( readSocket );
            } else {
               PacketReceiveSocket* prs =  
                  dynamic_cast< PacketReceiveSocket* > ( readSocket );
               if ( prs == NULL ) {
                  mc2dbg8 << "[PR]: New socket is not PacketReceiveSocket"
                          << endl;
                  // No - disconnect after reading a packet.
                  deleteReadSocket = true;
               } else {
                  // Continue reading next time.
                  mc2dbg8 << "[PR]: I will read during the next round"
                          << endl;
                  // Add the socket, but don't restart the selector.
                  m_receiver.addTCPSocket( readSocket, true );
                  readSocket = NULL;
                  keepSocket = true;
               }
            }            
         }
            
         if (readSocket != NULL) {
            if ( dynamic_cast< PacketReceiveSocket* > ( readSocket ) ) {
               PacketReceiveSocket* prs =  
                  static_cast< PacketReceiveSocket* > ( readSocket );
               prs->readBytes();
               if ( prs->getReadState() == PacketReceiveSocket::done ) {
                  buffer = prs->getBuffer( true );
                  bufferLength = prs->getSize();
                  packetLength = prs->getSize();
                  if ( !isPermanent( readSocket ) ) {
                     deleteReadSocket = true;
                     removeTCPSocket ( readSocket );
                  }
               } else if ( prs->getReadState() == 
                           PacketReceiveSocket::reading_size ||
                           prs->getReadState() == 
                           PacketReceiveSocket::reading_packet )
               {
                  // This shouldn't happen anymore since it has been
                  // done above.
                  if ( readSocket != tcpSock && !isPermanent( tcpSock ) ) {
                     // Add new socket
                     MC2_ASSERT( false );
                     m_receiver.addTCPSocket( readSocket );
                  }
                  keepSocket = true;
               } else {
                  // Else error
                  if ( !isPermanent( readSocket ) ) {
                     deleteReadSocket = true;
                  }
               }
            } else if ( ! isPermanent( readSocket ) ) {
               // Should not hang forever if someone connects without
               // sending
               buffer = readPacket( readSocket, bufferLength, packetLength,
                                    10*1000*1000);
            } else {
               // Maybe timeout here too?
               buffer = readPacket( readSocket, bufferLength, packetLength);
            }
            if ( buffer == NULL && !keepSocket ) {
               if ( isPermanent(readSocket) ) {
                  // We do not want to receive more stuff on this one.
                  removeTCPSocket ( readSocket );
                  mc2dbg << "[PacketReceiver] Permanent socket closed"
                     " no need to crash" << endl;
               } else {
                  mc2log << warn << "PacketReceiver::receiveAndCreatePacket "
                         << "failed to read packet from socket." << endl;
                  if ( readSocket == tcpSock &&
                       tcpSock->getState() == TCPSocket::LISTEN ) {
                     mc2log << "PacketReceiver::receiveAndCreatePacket "
                            << "Failed to read from main socket: " 
                            << "Error: exiting with exit(2) instead of "
                            << "trying to fix the situation." << endl;
                     exit( 2 );
                  }
               } 
            }
         }
         // Check if the read-socket should be deleted or not.
         if ( keepSocket ) {
            // Keep it to read more later
         } else if (deleteReadSocket) {
            delete readSocket;
         } else if ( tcpReceiverSock != NULL ) {
            *tcpReceiverSock = readSocket;
         }
         
      } else if ( datagramSock != NULL ) {
         // Create buffer.
         bufferLength = Packet::MAX_UDP_PACKET_SIZE;
         buffer = new byte[bufferLength];
         packetLength = datagramSock->receive(buffer, bufferLength);
         if (packetLength < 0) {
            delete [] buffer;
            buffer = NULL;
         }
      }
   }

   // Return
   if (buffer != NULL) {
      Packet* returnPacket = Packet::makePacket(buffer, 
                                                bufferLength);
      returnPacket->setLength(packetLength);
      return returnPacket;
   } else {
      return NULL;
   }
}