Esempio n. 1
0
int main(int argc, char ** argv)
{

   /* The stack */
   chunk_addr stack[STACK_SIZE];

   /* Iterative variables */
   int i, j;

   /* The memory manager */
   memory_manager mem;

   /* Create the stack */

   /* Create a new memory manager that should not have to grow. */
   mem = new_memory_manager(STACK_SIZE * chunk_size(CHUNK_SIZE));

   /* For ever:
      Loop throught the stack.  
      Allocate a new piece of data to stack. */
   for (j = 0; j < ITERATIONS; j++)
   { 
      for (i = 0; i < STACK_SIZE; i++)
      {
         stack[i] = allocate(stack, stack + 1, CHUNK_SIZE, mem); 
      }
   }   

   /* Shutdown the memory manager. */
   shutdown_memory_manager(mem);

   return EXIT_SUCCESS;
}
Esempio n. 2
0
int iforward_write( iforward_t *file, forward_t *forward ) {
	uint8_t *cbuff = chunk_compress( &forward->chunk, &forward->h.bcount );
	forward->h.N = chunk_size( &forward->chunk );
	fwrite( &forward->h, sizeof(forward->h), 1, file->in );
	fwrite( cbuff, forward->h.bcount, 1, file->in );
	free(cbuff);
	return 0;
}
Esempio n. 3
0
void SessionData::SendBytesToProcess (vector<string>* packets, vector<aux::output_packet>* out_packets,
									  bool split_packets)
{
	//чтобы порции трафика не ограничивались рамками одного пакета, но и можно было сделать закрытие соединения	
	string prev_packet_chunk;
	vector<string>::const_iterator it;
	vector<aux::output_packet>::iterator it2;
	for (it = packets->begin(), it2 = out_packets->begin(); it != packets->end(); ++it, ++it2)
	{
		Sleep (Configure::GetConfiguration().TimeoutBetweenChunks());

		string pckt = *it;
		if (prev_packet_chunk.size()) 
		{
			pckt = prev_packet_chunk;
			string pckt2 (*it);
			pckt.append (pckt2.c_str());
			prev_packet_chunk.clear();
		}

		const char* begin = pckt.c_str();
		const char* end = begin + pckt.size();
		char* start = const_cast<char*>(begin);
		while (start != end)
		{
			size_t chunk_size (aux::rnd_chunk_size(Configure::GetConfiguration().MaximumChunkSize()));
			if (chunk_size >= static_cast<size_t>(end - start))
			{
				if (split_packets ||
					it2->dsDataTarget != ((it+1 != packets->end())?(it2+1)->dsDataTarget : it2->dsDataTarget))
				{
					chunk_size = static_cast<size_t>(end - start);
					_ASSERTE (TranslateData(start, start + chunk_size, it2->dsDataTarget));
					start += chunk_size;
				}
				else
				{	
					prev_packet_chunk.assign (start, end);
					break;
				}
			}
			else
			{
				_ASSERTE(TranslateData(start, start + chunk_size, it2->dsDataTarget));
				start += chunk_size;
			}
			Sleep (Configure::GetConfiguration().TimeoutBetweenChunks());
		}

	}
	if (prev_packet_chunk.size())
	{
		_ASSERTE(TranslateData (prev_packet_chunk.c_str(), prev_packet_chunk.c_str() + prev_packet_chunk.size(),
					out_packets->rbegin()->dsDataTarget));
	}

}
Esempio n. 4
0
    __AGENCY_ANNOTATION
    value_type operator*() const
    {
      auto end_of_current_chunk = base();
      ++end_of_current_chunk;

      if(end_of_current_chunk == end())
      {
        auto size_of_last_chunk = end().base() - base().base();
        return value_type(base().base(), size_of_last_chunk);
      }

      return value_type(base().base(), chunk_size());
    }
Esempio n. 5
0
void *
realloc(void *ptr, size_t size)
{
  void *ret;
  size_t as;

  if (!size)
    {
      free(ptr);
      return (NULL);
    }
  as = chunk_size(ptr);
  if (size <= as)
    return (ptr);
  ret = malloc(size);
  if (ret)
    {
      memcpy(ret, ptr, MIN(as, size));
      free(ptr);
    }
  return (ret);
}
Esempio n. 6
0
    // https://wiki.libsdl.org/SDL_RWops?highlight=%28%5CbCategoryStruct%5Cb%29%7C%28CategoryIO%29
    // https://wiki.libsdl.org/SDL_RWwrite?highlight=%28%5CbCategoryIO%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29
    void hex_grid_t::save_to_file(std::string const& filepath)
    {
        WARN_IF(!chunks.empty(), "Saving an empty map");

        SDL_RWops* io = SDL_RWFromFile(filepath.c_str(), "wb");

        if(!io)
        {
            EXPLODE("hex_grid_t::save_to_file() error");  //todo: handle errors better
        }

        hxm_header_t header;
        header.version = 0;
        header.chunk_size = chunk_size();
        header.map_size = size;

        size_t num_written = SDL_RWwrite(io, (void*)&header, sizeof(hxm_header_t), 1);

        if(num_written != 1)
        {
            EXPLODE("error writing hxm header");
        }


        for_each_chunk([&](hex_grid_chunk_t const& chunk)
        {
            SDL_RWwrite(io, (void*)&chunk.size, sizeof(glm::uvec2), 1);
            for(auto column : chunk.cells)
            {
                size_t num_w = SDL_RWwrite(io, column.data(), sizeof(hex_grid_cell_t), column.size());
                ASSERT(num_w == column.size(), "chunk save error");
                LOG("wrote %d cells", num_w);
            }
        });
        

        SDL_RWclose(io);
    }
Esempio n. 7
0
 __AGENCY_ANNOTATION
 difference_type size() const
 {
   return (end().base().base() - begin().base().base() + chunk_size() - 1) / (chunk_size());
 }
Esempio n. 8
0
static int __init l4ser_shm_init_port(int num, const char *name)
{
	int irq;
	struct chunk_head *ch;
	struct l4ser_shm_uart_port *p = &l4ser_shm_port[num];
	L4XV_V(f);

	if (p->inited)
		return 0;
	p->inited = 1;

	if (shmsize < PAGE_SIZE)
		shmsize = PAGE_SIZE;

	pr_info("l4ser_shm: Requesting, role %s, Shmsize %d Kbytes\n",
	        p->create ? "Creator" : "User", shmsize >> 10);

	L4XV_L(f);
	if (p->create) {
		if (l4shmc_create(name, shmsize)) {
			L4XV_U(f);
			pr_err("l4ser_shm/%s: Failed to create shm\n",
			       p->name);
			return -ENOMEM;
		}
	}

	if (l4shmc_attach_to(name, WAIT_TIMEOUT,
	                     &p->shmcarea)) {
		L4XV_U(f);
		pr_err("l4ser_shm/%s: Failed to attach to shm\n", p->name);
		return -ENOMEM;
	}

	if (l4shmc_add_chunk(&p->shmcarea, p->create ? "joe" : "bob",
	                     chunk_size(&p->shmcarea),
	                     &p->tx_chunk))
		goto unlock;

	if (l4shmc_add_signal(&p->shmcarea, p->create ? "joe" : "bob",
	                      &p->tx_sig))
		goto unlock;

	if (l4shmc_connect_chunk_signal(&p->tx_chunk,
	                                &p->tx_sig))
		goto unlock;

	/* Now get the receiving side */
	if (l4shmc_get_chunk_to(&p->shmcarea, p->create ? "bob" : "joe",
	                        WAIT_TIMEOUT, &p->rx_chunk))
		goto unlock;

	if (l4shmc_get_signal_to(&p->shmcarea, p->create ? "bob" : "joe",
	                         WAIT_TIMEOUT, &p->rx_sig))
		goto unlock;

	if (l4shmc_connect_chunk_signal(&p->rx_chunk,
	                                &p->rx_sig))
		goto unlock;
	L4XV_U(f);

	if ((irq = l4x_register_irq(l4shmc_signal_cap(&p->rx_sig))) < 0)
		return -ENOMEM;

	ch = (struct chunk_head *)l4shmc_chunk_ptr(&p->tx_chunk);
	ch->next_offs_to_write = 0;
	ch->next_offs_to_read  = 0;
	ch->writer_blocked     = 0;

	p->tx_ring_size = l4shmc_chunk_capacity(&p->tx_chunk)
	                       - sizeof(struct chunk_head);
        p->rx_ring_size = l4shmc_chunk_capacity(&p->rx_chunk)
                               - sizeof(struct chunk_head);

        p->tx_ring_start = (char *)l4shmc_chunk_ptr(&p->tx_chunk)
                               + sizeof(struct chunk_head);
        p->rx_ring_start = (char *)l4shmc_chunk_ptr(&p->rx_chunk)
                               + sizeof(struct chunk_head);


	p->port.uartclk   = 3686400;
	p->port.ops       = &l4ser_shm_pops;
	p->port.fifosize  = 8;
	p->port.line      = num;
	p->port.iotype    = UPIO_MEM;
	p->port.membase   = (void *)1;
	p->port.mapbase   = 1;
	p->port.flags     = UPF_BOOT_AUTOCONF;
	p->port.irq       = irq;

	return 0;

unlock:
	L4XV_U(f);
	return -ENOMEM;
}
Esempio n. 9
0
// chunk_head_t, followed by a varint compressed chunk of data.
int ifile_real_read( ifile_t *file ) {
	size_t rc = fread( &file->h, sizeof(file->h), 1, file->in );
	if( rc == 0 )  {
		// Nothering read, EOF
		return -1;
	}

	return read_block( file->in, file->h.N, file->h.bcount, &file->chunk );
}


// Write's a chunk to disk.  Format is chunk_head_t followed by varint compressed buffer
void ifile_real_write( ifile_t *file ) {
	// Create the chunk_heaad_t object and compress body
	chunk_head_t h = { .N = chunk_size(&file->chunk), .term = file->h.term, .doc = file->h.doc };
	uint8_t *cbuff = chunk_compress( &file->chunk, &h.bcount );

	fwrite( &h, sizeof(h), 1, file->in );
	fwrite( cbuff, h.bcount, 1, file->in );
	free(cbuff);
}

// Read next tuple (term, doc) from the index.
int ifile_read( ifile_t *file ) {

	// Get the next doc from the buffer
	if( chunk_get(&file->chunk, &file->roff, &file->tupe.doc ) == 0 )  {
		return 0;
	} else if( ifile_real_read( file ) ) { // Try reading a chunk of buffer is empty or we drained it
		return -1;