Example #1
0
File: test.c Project: bcho/homework
static char *test_purge()
{
    LinkList l;
    char *ans;

    l = create_link_list_from_string("abc");
    Purge(&l);
    ans = link_list_to_string(l);
    mu_assert("purege 1", strcmp(ans, "abc") == 0);

    free(ans);
    destory_link_list(l);
    
    l = create_link_list_from_string("aaabbbcccc");
    Purge(&l);
    ans = link_list_to_string(l);
    mu_assert("purege 2", strcmp(ans, "abc") == 0);

    free(ans);
    destory_link_list(l);
    
    l = create_link_list_from_string("abcabc");
    Purge(&l);
    ans = link_list_to_string(l);
    mu_assert("purege 3", strcmp(ans, "abc") == 0);

    free(ans);
    destory_link_list(l);

    return 0;
}
Example #2
0
void freettcn::TM::CTestManagement::Clear()
{
    Purge(_modParList);
    Purge(_tcList);

    _status = NOT_RUNNING;
}
bool
PacketQueue::Enqueue (QueueEntry & entry)
{
  NS_LOG_FUNCTION ("Enqueing packet destined for" << entry.GetIpv4Header ().GetDestination ());
  Purge ();
  uint32_t numPacketswithdst;
  for (std::vector<QueueEntry>::const_iterator i = m_queue.begin (); i
       != m_queue.end (); ++i)
    {
      if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ())
          && (i->GetIpv4Header ().GetDestination ()
              == entry.GetIpv4Header ().GetDestination ()))
        {
          return false;
        }
    }
  numPacketswithdst = GetCountForPacketsWithDst (entry.GetIpv4Header ().GetDestination ());
  NS_LOG_DEBUG ("Number of packets with this destination: " << numPacketswithdst);
  /** For Brock Paper comparision*/
  if (numPacketswithdst >= m_maxLenPerDst || m_queue.size () >= m_maxLen)
    {
      NS_LOG_DEBUG ("Max packets reached for this destination. Not queuing any further packets");
      return false;
    }
  else
    {
      // NS_LOG_DEBUG("Packet size while enqueing "<<entry.GetPacket()->GetSize());
      entry.SetExpireTime (m_queueTimeout);
      m_queue.push_back (entry);
      return true;
    }
}
Example #4
0
void Controller::GetUpdate()
{
	MMThreadGuard myLock(lock_);
	{
		string propName;

		Purge();
		Send("CSS?");
		do {
			ReceiveOneLine();
		} while (0 != buf_string_.compare(0, 3, "CSS", 0, 3));

		globalState_ = false;

		//Record intensities and first LED on
		for (unsigned int i = 0; i < 3; i++) {
			//Read the intensity
			channelIntensities_[i] = atol(buf_string_.substr(6 + i * 6, 3).c_str());
			string t = buf_string_.substr(4 + i * 6, 1);
			channelSelection_[i] = buf_string_.substr(4 + i * 6, 1) == "S" ? 1 : 0;
			propName = g_Keyword_Intensity;
			propName.push_back('A' + (char)i);
			intensityUpdated_[i] = true;;
			UpdateProperty(propName.c_str());

			propName = g_Keyword_Selection;
			propName.push_back('A' + (char)i);
			selectionUpdated_[i] = true;
			UpdateProperty(propName.c_str());

			globalState_ |= buf_string_.substr(5 + i * 6, 1) == "N";
			globalStateUpdated_ = true;
		}
	}
}
void Chunk::Free(void* ptr) {
  assert(is_chunk(ptr));
  assert(ptr_to_chunk(ptr) == this);

  unsigned int n = ptr_to_n(ptr);
  unsigned int i = n / 32;
  unsigned int bit = n % 32;

  assert(i < arraysize(free_bitmap_));
  assert(!(free_bitmap_[i] & (1U << bit)));
  free_bitmap_[i] |= 1U << bit;
  free_count_++;

  if (i < first_free_bitmap_) {
    first_free_bitmap_ = i;
  }

  if (free_count_ == 1) {
    heap_->MoveToFreeList(this, bucket_);
  } else {
    // TODO(ccross): move down free list if necessary
  }

  if (frees_since_purge_++ * allocation_size_ > 16 * kPageSize) {
    Purge();
  }
}
Example #6
0
inline void CUtlVector<T, A>::PurgeAndDeleteElements()
{
    for(int i = 0; i < m_Size; i++) {
        delete Element(i);
    }
    Purge();
}
Example #7
0
Texture*									ImageManager::LoadImage								(const std::string& aName, const std::string& aPath)
{
    if(!Utility::FileExists(aPath))
    {
        return 0;
    }

//HACK: Don't allow more than 100 images, make a less nuclear pruning routine!
    if(Images.size() >= 100)
    {
        Purge();
    }

    if(Images.find(aName) == Images.end())
    {
        Texture* output;

        ESSUB_LoadPNG(aPath, &output);

        if(output)
        {
            output->SetFilter(true);
            Images[aName] = output;
        }
    }

    return Images[aName];
}
Example #8
0
int Controller::ReadChannelLabels()
{
   buf_tokens_.clear();
   string label;

   Purge();
   Send("LAMS");
   do {
      ReceiveOneLine();
      buf_tokens_.push_back(buf_string_);
   }
      while(! buf_string_.empty());
   
   
   for (unsigned int i=0;i<buf_tokens_.size();i++)
   {
      if (buf_tokens_[i].substr(0,3).compare("LAM")==0) {
         channelLetters_.push_back(buf_tokens_[i][4]); // Read 4th character
         string label = buf_tokens_[i].substr(6);
         StripString(label);
         channelLabels_.push_back(label);
      }
   }

   if (channelLabels_.size() == 0)
	   return DEVICE_ERR;
   else
	   return DEVICE_OK;
}
SmartPointer<RegistryObject> RegistryObjectReferenceMap::Get(int key) const
{
  Purge();
  ReferenceMapType::const_iterator entry = references.find(key);
  if (entry != references.end()) return entry.value()->GetValue();
  return RegistryObject::Pointer();
}
Example #10
0
int Controller::OnChannelWave(MM::PropertyBase* pProp, MM::ActionType eAct, long channel)
{
	string wavelength;

	if (eAct == MM::BeforeGet && waveUpdated_[channel]) {
		pProp->Set(channelWave_[channel].c_str());
		waveUpdated_[channel] = false;
	}
	else if (eAct == MM::AfterSet)
	{
		pProp->Get(wavelength);
		//LOAD:<wavelength> loads that particular wavelength in the channel
		stringstream msg;
		msg << "LOAD:" << wavelength;

		MMThreadGuard myLock(lock_);
		Purge();
		Send(msg.str());
		do {
			ReceiveOneLine();
		} while (buf_string_.size() == 0);
	}

	return HandleErrors();
}
Example #11
0
//============================================================================
//		NCache::SetValue : Set a value.
//----------------------------------------------------------------------------
void NCache::SetValue(const NCacheKey &theKey, NCacheValue *theValue)
{


	// Validate our parameters
	NN_ASSERT(theValue->GetCost() >= 0);



	// Prepare to set
	if (HasKey(theKey))
		RemoveKey(theKey);

	if (NeedsPurge())
		Purge();



	// Set the value
	mCache[theKey] = theValue;
	mCacheCost    += theValue->GetCost();

	theValue->SetAccessTime();
	theValue->Retain();
}
Example #12
0
void freettcn::TE::CModule::Cleanup()
{
  Purge(_parameterArray);
  Purge(_allEntityStates);
  Purge(_behaviorList);
  Purge(_testCaseArray);
  Purge(_portTypeArray);
  
  if (_ctrlSrcData)
    delete _ctrlSrcData;
  
  // delete temporary variables
  if (__modParList)
    delete[] __modParList;
  if (__testCaseIdList)
    delete[] __testCaseIdList;
}
SmartPointer<RegistryObject> RegistryObjectReferenceMap::Remove(int key)
{
  Purge();
  IEntry* entry = references.take(key);
  RegistryObject::Pointer obj = entry->GetValue();
  delete entry;
  return obj;
}
Example #14
0
void Controller::SetIntensity(long intensity, long index)
{
   stringstream msg;
   msg << "C" << channelLetters_[index] << "I" << intensity;
   Purge();
   Send(msg.str());
   ReceiveOneLine();

}
Example #15
0
	void Texture::SetExternalMemory( void* pMemory )
	{
		Assert( pMemory && "nullptr external memory" );

		Purge();

		AddFlags( FL_EXTERNAL_MEMORY );
		m_pMemory = pMemory;
	}
Example #16
0
BabelGlue::~BabelGlue()
{
	if(m_thread.GetActive()==true)
		m_thread.Close(false);
	
	/* might take a while to shutdown */
	while(m_asyncactive)
		kGUI::Sleep(1);
	Purge();
}
void CUtlMemoryBase::Purge( int numElements, bool bRealloc )
{
	Assert( numElements >= 0 );

	if( numElements > m_nAllocationCount )
	{
		// Ensure this isn't a grow request in disguise.
		Assert( numElements <= m_nAllocationCount );
		return;
	}

	// If we have zero elements, simply do a purge:
	if( numElements == 0 )
	{
		Purge();
		return;
	}

	if ( IsExternallyAllocated() )
	{
		// Can't shrink a buffer whose memory was externally allocated, fail silently like purge 
		return;
	}

	// If the number of elements is the same as the allocation count, we are done.
	if( numElements == m_nAllocationCount )
	{
		return;
	}

	if( !m_pMemory )
	{
		// Allocation count is non zero, but memory is null.
		Assert( m_pMemory );
		return;
	}

	if ( bRealloc )
	{
		UTLMEMORY_TRACK_FREE();

		m_nAllocationCount = numElements;

		UTLMEMORY_TRACK_ALLOC();

		// Allocation count > 0, shrink it down.
		MEM_ALLOC_CREDIT_CLASS();
		m_pMemory = PvRealloc( m_pMemory, m_nAllocationCount * m_unSizeOfElements );
	}
	else
	{
		// Some of the tracking may be wrong as we are changing the size but are not reallocating.
		m_nAllocationCount = numElements;
	}
}
void CUtlMemoryBase::SetExternalBuffer( const void* pMemory, int numElements )
{
	// Blow away any existing allocated memory
	Purge();

	m_pMemory = const_cast<void*>( pMemory );
	m_nAllocationCount = numElements;

	// Indicate that we don't own the memory
	m_nGrowSize = EXTERNAL_CONST_BUFFER_MARKER;
}
DisplayError ResourceDefault::UnregisterDisplay(Handle display_ctx) {
  DisplayResourceContext *display_resource_ctx =
                          reinterpret_cast<DisplayResourceContext *>(display_ctx);
  Purge(display_ctx);

  hw_block_ctx_[display_resource_ctx->hw_block_id].is_in_use = false;

  delete display_resource_ctx;

  return kErrorNone;
}
Example #20
0
// CommandDialog
// Prompts user for device commands and returns reply from device
int CommandDialog(ComPortHandle comPort, unsigned int command){

//  unsigned int command;
  unsigned char ccommand;
  int i=0;
  int size;
  Byte response[4096] = {0};

//  printf("\nEnter command in hexadecimal format, valid commands range from c1 to fe (00 to EXIT)\n");
//  printf("(SEE: 3DM-GX3® Data Communications Protocol Manual for more information):\n");

//  scanf("%x", &command);//takes 1 byte command in hexadecimal format
//  printf("%x 1\n", command);

//  command = 0xdf;
//  printf("%x 2\n", command);
  ccommand=(char)command;
  if(command==0x00)//command to exit program
    return FALSE;
  else
    writeComPort(comPort, &ccommand, 1);//write command to port
  //getchar();//flush keyboard buffer
  Purge(comPort);//flush port

  size = readComPort(comPort, &response[0], 4096);

  if(size<=0){
    printf("No data read from previous command.\n");
    return TRUE;
  }
  else{
//    printf("Data returned from device:\n");
    while(size>0){//loop to read until no more bytes in read buffer
      if(size<0){
       printf("BAD READ\n");
       return TRUE;
      }
      else{
        for(i=0;i<size;i++){
          if(response[i]<0x10){//keeps output bytes listed as two char hex format
            printf("0%x ",response[i]|0x00);
          }
          else{
            printf("%x ",response[i]|0x00);
          }
        }
        printf("\n");
        return TRUE;
      }
      size = readComPort(comPort, &response[0], 4096);
    }
  }
}
Example #21
0
TriStatus freettcn::PA::CPlatformAdaptor::Reset()
{
  // stop all timers
  for(CTimerList::const_iterator it=_timerList.begin(); it!=_timerList.end(); ++it)
    if ((*it)->Running())
      (*it)->Stop();
  
  // clear timers list
  Purge(_timerList);
  
  return TRI_OK;
}
Example #22
0
void Controller::SetIntensity(long intensity, long index)
{
	stringstream msg;
	msg << "C" << string(1, 'A' + (char)index) << "I" << intensity;

	{
		MMThreadGuard myLock(lock_);
		Purge();
		Send(msg.str());
		ReceiveOneLine();
	}
}
Example #23
0
/////////////////////////////////////////////
// Property Generators
/////////////////////////////////////////////
void Controller::GeneratePropertyLockPod()
{
	CPropertyAction* pAct = new CPropertyAction(this, &Controller::OnLockPod);
	CreateProperty(g_Keyword_PodLock, "0", MM::Integer, false, pAct);
	AddAllowedValue(g_Keyword_PodLock, "0");
	AddAllowedValue(g_Keyword_PodLock, "1");

	MMThreadGuard myLock(lock_);
	Purge();
	Send("PORT:P=ON");
	ReceiveOneLine();
}
Example #24
0
void FileDataCache::Save() const
{
   if ( IsEnabled() )
   {
      Purge();
      int index = 0;
      for ( cache_index::const_iterator i = m_cache.Begin(); i != m_cache.End(); ++i )
         (*i)->Save( m_keyPrefix, index++ );
   }

   // Make sure this is done after Purge()
   Settings::Write( m_keyPrefix + "Duration", Duration() );
   Settings::Write( m_keyPrefix + "Enabled", IsEnabled() );
}
void RegistryObjectReferenceMap::Put(int key, const SmartPointer<RegistryObject>& value)
{
  if (value.IsNull())
    throw ctkInvalidArgumentException("null values not allowed");

  Purge();

  ReferenceMapType::Iterator i = references.find(key);
  if (i != references.end())
  {
    delete *i;
  }
  references.insert(key, NewEntry(value));
}
Example #26
0
void Controller::GenerateDescription()
{
	string str = "CoolLED pE300.";

	Purge();
	Send("XVER");
	ReceiveOneLine();//Mainboard version returned
	str += " Mainboard: v" + buf_string_.substr(8);
	ReceiveOneLine();//Skip hardware version
	ReceiveOneLine();//Skip data version
	ReceiveOneLine();//Pod version returned
	str += " Pod: v" + buf_string_.substr(8);

	CreateProperty(MM::g_Keyword_Description, str.c_str(), MM::String, true);
}
Example #27
0
DoubleLinkedList<T> & DoubleLinkedList<T>::operator=(const DoubleLinkedList<T> & rhs)
{
    if(this != &rhs)
    {
        Purge();
        LLNode<T> * travel = rhs._head;
        while(travel != nullptr)
        {
            Append(travel->_data);
            travel = travel->_next;
        }

    }
    return *this;
}
Example #28
0
int Controller::OnLockPod(MM::PropertyBase* pProp, MM::ActionType eAct)
{
	if (eAct == MM::AfterSet)
	{
		long lockPod;

		pProp->Get(lockPod);

		MMThreadGuard myLock(lock_);
		Purge();
		Send(lockPod == 1 ? "PORT:P=OFF" : "PORT:P=ON");
		ReceiveOneLine();
	}

	return HandleErrors();
}
bool
PacketQueue::Dequeue (Ipv4Address dst, QueueEntry & entry)
{
  NS_LOG_FUNCTION ("Dequeueing packet destined for" << dst);
  Purge ();
  for (std::vector<QueueEntry>::iterator i = m_queue.begin (); i != m_queue.end (); ++i)
    {
      if (i->GetIpv4Header ().GetDestination () == dst)
        {
          entry = *i;
          m_queue.erase (i);
          return true;
        }
    }
  return false;
}
Example #30
0
void Controller::GetIntensity(long& intensity, long index)
{
   stringstream msg;
   string ans;
   msg << "C" << channelLetters_[index] << "?";
   Purge();
   Send(msg.str());
   ReceiveOneLine();

   if (! buf_string_.empty())
      if (0 == buf_string_.compare(0,2,msg.str(),0,2))
      {
         intensity = atol(buf_string_.substr(2,3).c_str());
      }

}