Exemplo n.º 1
0
Arquivo: timer.c Projeto: AsamQi/LuaIO
void LuaIO_timer_free(uv_timer_t *timer) {
  if (timer != NULL) {
    LuaIO_timer_t *LuaIO_timer = LuaIO_list_entry(timer, LuaIO_timer_t, timer);

    if (LuaIO_timer_pool.free_timers < LuaIO_timer_pool.max_free_timers) {
      LuaIO_list_insert_head(&LuaIO_timer->list, &(LuaIO_timer_pool.free_list));
      LuaIO_timer_pool.free_timers++;
    } else {
      uv_close((uv_handle_t*)timer, LuaIO_timer_onclose);
    }
  }
}
Exemplo n.º 2
0
Arquivo: palloc.c Projeto: ifzz/LuaIO
void* LuaIO_pool_alloc(LuaIO_pool_t* pool, size_t size, size_t align, size_t slot) {
  LuaIO_list_t* free_list = &pool->free_list;
  LuaIO_pool_chunk_t* chunk;

  if (!LuaIO_list_is_empty(free_list)) {
    LuaIO_list_t* list = free_list->next;
    chunk = LuaIO_list_entry(list, LuaIO_pool_chunk_t, list);
    LuaIO_list_remove(list);
    pool->free_chunks--;  
  } else {
    chunk = LuaIO_memalign(align, size + sizeof(LuaIO_pool_chunk_t));
    if (chunk == NULL) return NULL;
  }

  chunk->magic = slot;
  return (void*)((char*)chunk + sizeof(LuaIO_pool_chunk_t));
}
Exemplo n.º 3
0
Arquivo: timer.c Projeto: AsamQi/LuaIO
uv_timer_t *LuaIO_timer_alloc() {
  LuaIO_list_t *free_list = &(LuaIO_timer_pool.free_list);
  LuaIO_timer_t *LuaIO_timer;
  uv_timer_t *timer;

  if (!LuaIO_list_is_empty(free_list)) {
    LuaIO_list_t *list = free_list->next;
    LuaIO_timer = LuaIO_list_entry(list, LuaIO_timer_t, list);
    timer = &LuaIO_timer->timer;
    LuaIO_list_remove(list);
    LuaIO_timer_pool.free_timers--;  
  } else {
    LuaIO_timer = LuaIO_memalign(LUAIO_TIMER_ALIGNMENT, sizeof(LuaIO_timer_t));
    if (LuaIO_timer == NULL) return NULL;

    timer = &LuaIO_timer->timer;
    uv_timer_init(uv_default_loop(), timer);
  }

  return timer;
}