Ejemplo n.º 1
0
/*
 * Add a given buffer by copy to the end of a list
 * Careful buffer is passed by reference,
 * and must be free with list_free()
 */
void list_add_by_copy(list * l, buffer * value)
{
    list_node *ln;
    buffer *tmp;

    assert(l);
    assert(value);
    assert(l->size < UINT_MAX);

    ln = list_node_init();
    tmp = buffer_init();

    buffer_copy(tmp, value);
    ln->value = tmp;

    if (!l->first) {
        ln->prev = NULL;
        l->first = ln;
    } else {
        ln->prev = l->last;
        l->last->next = ln;
    }

    l->last = ln;
    l->last->next = NULL;
    l->size++;
}
Ejemplo n.º 2
0
/*
 * Add a given buffer to the end of a list
 * Careful buffer is passed by reference,
 * and must be free with list_free()
 */
void list_add_str(list * l, char *value)
{
    list_node *ln;

    assert(l);
    assert(value);
    assert(l->size < UINT_MAX);

    ln = list_node_init();

    ln->value = buffer_init();
    buffer_add_str(ln->value, value);

    if (!l->first) {
        ln->prev = NULL;
        l->first = ln;
    } else {
        ln->prev = l->last;
        l->last->next = ln;
    }

    l->last = ln;
    l->last->next = NULL;
    l->size++;
}
Ejemplo n.º 3
0
/*
 * Add a given list to the end of a list
 * Careful list is passed by reference,
 * and must be free with list_free()
 */
void list_add_list(list * l, list * l_to_add)
{
    list_node *ln, *ln_parse;

    assert(l);
    assert(l_to_add);

    for (ln_parse = l_to_add->first ; ln_parse ; ln_parse = ln_parse->next) {
        if (!in_list(l, ln_parse->value)) {
            ln = list_node_init();

            ln->value = buffer_init();
            buffer_copy(ln->value, ln_parse->value);

            if (!l->first) {
                ln->prev = NULL;
                l->first = ln;
            } else {
                ln->prev = l->last;
                l->last->next = ln;
            }

            l->last = ln;
            l->last->next = NULL;
            l->size++;
        }
    }
}
Ejemplo n.º 4
0
static int aio_schedule(struct tcmu_device *dev, struct tcmulib_cmd *cmd,
			tcmu_work_fn_t fn)
{
	struct tcmu_work *work;
	struct tcmur_device *rdev = tcmu_get_daemon_dev_private(dev);
	struct tcmu_io_queue *io_wq = &rdev->work_queue;

	work = malloc(sizeof(*work));
	if (!work)
		return SAM_STAT_TASK_SET_FULL;

	work->fn = fn;
	work->dev = dev;
	work->cmd = cmd;
	list_node_init(&work->entry);

	/* cleanup push/pop not _really_ required here atm */
	pthread_cleanup_push(_cleanup_mutex_lock, &io_wq->io_lock);
	pthread_mutex_lock(&io_wq->io_lock);

	list_add_tail(&io_wq->io_queue, &work->entry);
	pthread_cond_signal(&io_wq->io_cond); // TODO: conditional

	pthread_mutex_unlock(&io_wq->io_lock);
	pthread_cleanup_pop(0);

	return TCMU_ASYNC_HANDLED;
}
Ejemplo n.º 5
0
void list_remove(struct list_node *del_node)
{
  del_node->next->prev = del_node->prev;
  del_node->prev->next = del_node->next;

  list_node_init(del_node);
}
Ejemplo n.º 6
0
/**
 * @brief Initialise a new string container.
 * @param str String to initialise.
 */
void string_init(struct string *str)
{
	str->str = NULL;
	str->len = 0UL;
	xfiredb_spinlock_init(&str->lock);
	list_node_init(&str->entry);
}
Ejemplo n.º 7
0
Archivo: proc.c Proyecto: clarkok/CoS
static Process *
process_new(const char *p_name, Process *parent)
{
    Process *new_proc = kmalloc(sizeof(Process));
    new_proc->kernel_stack = kmalloc(PAGE_SIZE);
    new_proc->kernel_stack_top = new_proc->kernel_stack + PAGE_SIZE - sizeof(ProcScene);
    new_proc->current_scene = (volatile ProcScene*)new_proc->kernel_stack_top;
    new_proc->current_scene->last_scene = 0;
    list_node_init(&new_proc->_link);
    sb_node_init(&new_proc->_node);
    list_node_init(&new_proc->_child_link);
    new_proc->id = ++_proc_id;
    new_proc->state = PS_READY;
    new_proc->retval = 0;
    strncpy(new_proc->name, p_name, PROC_NAME_LENGTH);
    new_proc->priv_base = PRIV_NORMAL;
    new_proc->priv_offset = 0;
    new_proc->ticks = 0;
    new_proc->parent = parent;
    list_init(&new_proc->children);
    list_init(&new_proc->messages);
    new_proc->waiting_for = 0;

    if (parent) {
        list_append(&parent->children, &new_proc->_child_link);
        mm_duplicate(&new_proc->mm, &parent->mm);
        memcpy(proc_current_scene(new_proc), proc_current_scene(parent), sizeof(ProcScene) - 4);    // for last_scene
        proc_current_scene(new_proc)->regs[1] = 0;
    }
    else {
        mm_init_proc(&new_proc->mm);
        memset(proc_current_scene(new_proc), 0, sizeof(ProcScene));
    }

    _proc_insert(&proc_tree, new_proc);
    _proc_insert_into_queues(new_proc);

    return new_proc;
}
Ejemplo n.º 8
0
/*
 * Free a memory block owned by a given cookie.
 * Run some corruption checks.
 */
void
olsr_cookie_free(struct olsr_cookie_info *ci, void *ptr)
{
  struct olsr_cookie_mem_brand *branding;
  struct list_node *free_list_node;

#ifdef OLSR_COOKIE_DEBUG
  bool reuse = false;
#endif

  branding = (struct olsr_cookie_mem_brand *)ARM_NOWARN_ALIGN(((unsigned char *)ptr + ci->ci_size));

  /*
   * Verify if there has been a memory overrun, or
   * the wrong owner is trying to free this.
   */
  assert(!memcmp(&branding->cmb_sig, "cookie", 6) && branding->cmb_id == ci->ci_id);

  /* Kill the brand */
  memset(branding, 0, sizeof(*branding));

  /*
   * Rather than freeing the memory right away, try to reuse at a later
   * point. Keep at least ten percent of the active used blocks or at least
   * ten blocks on the free list.
   */
  if ((ci->ci_free_list_usage < COOKIE_FREE_LIST_THRESHOLD) || (ci->ci_free_list_usage < ci->ci_usage / COOKIE_FREE_LIST_THRESHOLD)) {

    free_list_node = (struct list_node *)ptr;
    list_node_init(free_list_node);
    list_add_before(&ci->ci_free_list, free_list_node);
    ci->ci_free_list_usage++;
#ifdef OLSR_COOKIE_DEBUG
    reuse = true;
#endif
  } else {

    /*
     * No interest in reusing memory.
     */
    free(ptr);
  }

  /* Stats keeping */
  olsr_cookie_usage_decr(ci->ci_id);

#ifdef OLSR_COOKIE_DEBUG
  OLSR_PRINTF(1, "MEMORY: free %s, %p, %u bytes%s\n", ci->ci_name, ptr, ci->ci_size, reuse ? ", reuse" : "");
#endif

}
Ejemplo n.º 9
0
void				list_insert(t_list *list, t_list_node *at, void *item)
{
	t_list_node	*next;
	t_list_node	*prev;
	t_list_node	*node;

	node = (t_list_node *)malloc(sizeof(*node));
	if (node == NULL)
		exit_errorc("list_insert", ERRC_NOT_ENOUGH_MEMORY, 1, NULL);
	list_node_init(node, item);
	next = at;
	prev = at->prev;
	list_node_set_next(node, next);
	list_node_set_prev(node, prev);
	if (at == list->first)
		list->first = node;
	if (at == list->last)
		list->last = node;
}
Ejemplo n.º 10
0
void addElement(list_t *list, void *element) {
  if (element==NULL) {  // non sono ammessi valori nulli come elementi
   perror("tentato di aggiungere un valore NULL");
    exit(-1);
  }

  //creo un nodo
  list_node_t* newNode=list_node_init(element);

  //lista vuota?
  if (list->head==NULL) {
    list->head=newNode;
    list->tail=newNode;
  } else {
    // lista non vuota
    list->tail->next=newNode;
    list->tail=newNode;
  }
}
Ejemplo n.º 11
0
Archivo: csv.c Proyecto: myaut/tsload
void* csv_entry_create(list_head_t* list, size_t entry_size) {
	csv_entry_chunk_t* entry_chunk;

	if(!list_empty(list)) {
		entry_chunk = list_last_entry(csv_entry_chunk_t, list, node);

		if(entry_chunk->count < csv_entries_per_chunk)
			return &entry_chunk->byte +
				   (entry_chunk->count++ * entry_size);
	}

	entry_chunk = mp_malloc(sizeof(csv_entry_chunk_t) +
							entry_size * csv_entries_per_chunk);

	list_node_init(&entry_chunk->node);
	entry_chunk->count = 1;

	list_add_tail(&entry_chunk->node, list);

	return &entry_chunk->byte;
}
Ejemplo n.º 12
0
/**
 * Add a socket and handler to the socketset
 * beeing used in the main select(2) loop
 * in listen_loop
 *
 *@param fd the socket
 *@param pf the processing function
 */
void
add_olsr_socket(int fd, socket_handler_func pf_pr, socket_handler_func pf_imm, void *data, unsigned int flags)
{
  struct olsr_socket_entry *new_entry;

  if (fd < 0 || (pf_pr == NULL && pf_imm == NULL)) {
    OLSR_PRINTF(1, "Bogus socket entry - not registering...");
    return;
  }
  OLSR_PRINTF(3, "Adding OLSR socket entry %d\n", fd);

  new_entry = olsr_malloc(sizeof(*new_entry), "Socket entry");

  new_entry->fd = fd;
  new_entry->process_immediate = pf_imm;
  new_entry->process_pollrate = pf_pr;
  new_entry->data = data;
  new_entry->flags = flags;

  /* Queue */
  list_node_init(&new_entry->socket_node);
  list_add_before(&socket_head, &new_entry->socket_node);
}