Beispiel #1
0
// Allocate a int from a MemoryPool.
// @in pool: The MemoryPool.
// @in value: The value to initialize the int.
// @return: Pointer to the int. NULL if there is no enough memory.
int *memory_pool_alloc_int(MemoryPool *pool, int value) {
  int *result = (int *) memory_pool_alloc(pool, sizeof(int));
  if (NULL == result) return NULL;

  *result = value;
  return result;
}
Beispiel #2
0
void set_child_thread_id(thread_identifier *parent, const char * fmt, ...) {
  va_list args;
  thread_identifier *tid;

  assert(parent->pipeline);

  tid = (thread_identifier *) memory_pool_alloc(parent->pipeline->pool,
                                                sizeof(thread_identifier));
  tid->pipeline = parent->pipeline;
 
  va_start(args, fmt);
  vsnprintf(tid->name, THD_ID_NAME_LEN, fmt, args);
  va_end(args);
  
  set_thread_id(tid);
}
Beispiel #3
0
static void *thread_func(void *arg)
{
	memory_pool_t* pool = arg;
	while (!exit_all) {
		struct poolobj* e[5];
		bzero(e, sizeof(e)); assert(sizeof(e) == (sizeof(void*) * 5));
		int rand_n = rand() % 6;
		int i;
		for (i = 0; i < rand_n; i++) {
			e[i] = memory_pool_alloc(pool);
		}
		sleep(rand_t());
		for (i = 0; i < rand_n; i++) {
			memory_pool_free(pool, e[i]);
		}
		sleep(rand_t());
	}
	return 0;
}
Beispiel #4
0
static struct event_queue_entry* mempool_eqent_alloc() {
	return memory_pool_alloc(mempool_eqent);
}