Beispiel #1
0
/*!
 * @brief Remove a given data item from the list.
 * @param pList Pointer to the \c LIST to remove the item from.
 * @param data The data that is to be removed from the list.
 * @remark Assumes data items are unqique as only the first occurrence is removed. 
 * @returns Indication of success or failure.
 * @sa list_remove_node
 */
BOOL list_remove(PLIST pList, LPVOID data)
{
	BOOL result = FALSE;
	PNODE current_node = NULL;

	if (pList == NULL || data == NULL)
	{
		return FALSE;
	}

	lock_acquire(pList->lock);

	current_node = pList->start;

	while (current_node != NULL)
	{
		if (current_node->data == data)
		{
			break;
		}

		current_node = current_node->next;
	}

	result = list_remove_node(pList, current_node);

	lock_release(pList->lock);

	return result;
}
Beispiel #2
0
void list_remove_tail (tListNode * listHead, tListNode ** node )
{
	*node = listHead->prev;
	list_remove_node (listHead->prev);
	(*node)->next = NULL;
	(*node)->prev = NULL;
}
Beispiel #3
0
/*
 * Remove a given data item from the list. Assumes data items are unqique as only the first occurrence is removed. 
 */
BOOL list_remove( LIST * list, LPVOID data )
{
	BOOL result         = FALSE;
	NODE * current_node = NULL;

	if( list == NULL || data == NULL )
		return FALSE;

	lock_acquire( list->lock );

	current_node = list->start;

	while( current_node != NULL )
	{
		if( current_node->data == data )
			break;

		current_node = current_node->next;
	}

	result = list_remove_node( list, current_node );

	lock_release( list->lock );
	
	return result;
}
void task_signal(Task *task, Signal signal)
{
    /* Set destionation signal. Unblock the task if the target
    signal is in mask. */
    interrupts_disable();

    task_line("");
    log_hex(signal);
    log_string(" --> ");
    log_string(task->name);
    log_string(" {mask=");
    log_hex(task->sig_mask);
    log_string(", rec=");
    log_hex(task->sig_rec);
    log_string("} ==> rec=");

    task->sig_rec |= signal;
    log_hex(task->sig_rec);
    if (task->sig_mask & signal) {
        log_string(", unblock, prio:");
        list_remove_node((Node *) task); 
        list_enqueue(&ready_tasks, (Node *) task);
        if (running_task->node.ln_pri < task->node.ln_pri) {
            log_string("hi");
            port_reschedule();
        } else {
            /* An unneeded context switch is optimized away. */
            log_string("lo");
            interrupts_enable();
        }
    } else {
        log_string(", no unblock.");
        interrupts_enable();
    }
}
Beispiel #5
0
/*
 * Remove a list item at the specified index. 
 */
BOOL list_delete( LIST * list, DWORD index )
{
	BOOL result         = FALSE;
	LPVOID data         = NULL;
	NODE * current_node = NULL;

	if( list == NULL )
		return FALSE;

	lock_acquire( list->lock );

	if( list->count > index )
	{
		current_node = list->start;

		while( current_node != NULL )
		{
			if( index == 0 )
			{
				result = list_remove_node( list, current_node );
				break;
			}

			current_node = current_node->next;

			index--;
		}
	}

	lock_release( list->lock );
	
	return result;
}
Beispiel #6
0
void list_remove_head (tListNode * listHead, tListNode ** node )
{
	*node = listHead->next;
	list_remove_node (listHead->next);
	(*node)->next = NULL;
	(*node)->prev = NULL;
}
Beispiel #7
0
void
list_remove(list_t *list, void *object)
{
	list_node_t *lold = list_d2l(list, object);
	ASSERT(!list_empty(list));
	ASSERT(lold->list_next != NULL);
	list_remove_node(lold);
}
void
list_clear (linked_list_t list)
{
    while (list->data != list->data->next)
    {
	list_remove_node (list, list->data->next);
    }
}
Beispiel #9
0
void *
list_remove_tail(list_t *list)
{
	list_node_t *tail = list->list_head.list_prev;
	if (tail == &list->list_head)
		return (NULL);
	list_remove_node(tail);
	return (list_object(list, tail));
}
Beispiel #10
0
void del(Hash *h, List *l, char *key)
{
    Node *n = NULL;
    if(NULL != (n = hash_get(h, key)))
    {
        list_remove_node(l, n);
    }
    hash_del(h, key);
}
Beispiel #11
0
void *
list_remove_head(list_t *list)
{
	list_node_t *head = list->list_head.list_next;
	if (head == &list->list_head)
		return (NULL);
	list_remove_node(head);
	return (list_object(list, head));
}
Beispiel #12
0
void *malloc(size_t size) {

	if (0 == size) {
		return NULL;
	}

	size += sizeof(block_meta_t); // size requested + size of block_meta_t is total size required
	block_meta_t *ret = NULL;

	init_heap();

	// check for a block on the free_list of sufficient size
	ret = (block_meta_t *)list_find_node_with_data(&free_list, &is_enough_room, (void *)size);

	// found room on free_list
	if (NULL != ret) {
		list_remove_node(&free_list, ret);

	// no room on free_list
	} else {
		// is there room on the last partially-used page?
		if (size <= remaining) {
			ret = last;
			remaining -= size;
		} else { // no room anywhere, get new page(s)

			// Allocate creates new page(s), so the memory from a prevoius page where 
			// last and remaining refer should be saved to the free_list.
			//
			// Only save if that space can fit a block_meta_t + some bytes
			// else let it become dangling/unusable memory.
			if (remaining > sizeof(block_meta_t)) {
				set_block_size(last, remaining);
				list_insert_node_at_end(&free_list, last);
				last = NULL;
				remaining = 0;
			}

			if (0 != allocate(size, 0, (void **)&ret)) {
				return NULL;
			}

			remaining = PAGE_SZ - (size % PAGE_SZ);
		}

		set_block_size(ret, size);

		last = (block_meta_t *)((unsigned char *)ret + size);

	}

	// add block to allocated_list
	list_insert_node_at_end(&allocated_list, ret);

	// need casting to make the math work correctly.
	return (void *)((unsigned char*)ret + sizeof(block_meta_t));
}
Beispiel #13
0
void free(void *ptr) {
	// get block_meta for this memory
	ptr -= sizeof(block_meta_t);

	// rm block from allocated_list
	list_remove_node(&allocated_list, (block_meta_t *)ptr);

	// add block to free_list
	list_insert_node_at_end(&free_list, (block_meta_t *)ptr);
}
Beispiel #14
0
void set(Hash *h, List *l, char *key, int value)
{
    Node *n = NULL;
    if(NULL != (n = hash_get(h, key)))
    {
        list_remove_node(l, n);
    }
    list_push(l, key, value, NULL);
    hash_add(h, key, value, l->root);
}
Beispiel #15
0
/*@null@*/ void* list_remove_by_value(list_t inst, void* val) {
	void* rval = NULL;

	node_t n = list_get_node_by_value(inst, val);
	if (n != NULL) {
		rval = list_remove_node(inst, n);
	}

	return rval;
}
//free the list
void list_delete(linked_list_t *list)
{
	for(node_t *i = list->head->next; i != list->tail; i = i->next){
		node_t *previous = i->previous;
		list_remove_node(i, list);
		i = previous;
	}
	free(list->head);
	free(list->tail);
}
void kick_players(linked_list_t *player_list)
{
    for (node_t *i = player_list->head->next; i != player_list->tail; i = i->next){
        player_info_t *player_info = (player_info_t*)i->data;
        node_t *previous = i->previous;
        if (player_info->chat_descriptor > 0){
            close(player_info->chat_descriptor);
        }
        list_remove_node(i, player_list);
        i = previous;
    }
}
Beispiel #18
0
int get(Hash *h, List *l, char *key)
{
    int value = 0;
    Node *n = NULL;
    if(NULL != (n = hash_get(h, key)))
    {
        value = n->value;
        list_remove_node(l, n);
        list_push(l, key, value, NULL);
        hash_add(h, key, value, l->root); 
    }
    return value;
}
Beispiel #19
0
void
cs_del(changeset * cs, node *elm, int flag)
{
	if (flag == TR_NEW) {	/* remove just added */
		if (cs->nelm == elm)
			cs->nelm = elm->next;
		list_remove_node(cs->set, elm);
	} else {
		if (!cs->dset) 
			cs->dset = list_new(cs->sa, cs->destroy);
		list_move_data(cs->set, cs->dset, elm->data);
	}
}
Beispiel #20
0
static struct lnode *liberar_no_atual(struct lnode *no)
{
	struct token *tk;

	if (list_node_old == NULL)
		tk = list_remove_front(*tokens);
	else
		tk = list_remove_node(*tokens, no, list_node_old);
	free_token(tk);
	if (list_node_old == NULL)
		return (*tokens)->front;
	else
		return list_node_old->next;
}
ISR(TIMER0_COMP_vect, ISR_NAKED) {
    SAVE_CONTEXT();
    /* Decide if a task change shall occur. We know that
    running_task is in the ready list. */
    if (0 == timer_tick) {
        list_remove_node((Node *) running_task);
        list_enqueue(&ready_tasks, (Node *) running_task);
        reschedule();
        timer_tick = RR_TIMEOUT_MS;
    } else {
        timer_tick--;
    }
    RESTORE_CONTEXT();
    __asm__ __volatile__ ("reti \n\t");
}
Beispiel #22
0
void* DLLCALL listRemoveNode(link_list_t* list, list_node_t* node, BOOL free_data)
{
    void*	data;

    if(list==NULL)
        return(NULL);

    listLock(list);

    data = list_remove_node(list, node, free_data);

    listUnlock(list);

    return(data);
}
Beispiel #23
0
void* DLLCALL listRemoveTaggedNode(link_list_t* list, list_node_tag_t tag, BOOL free_data)
{
    void*			data=NULL;
    list_node_t*	node;

    if(list==NULL)
        return(NULL);

    listLock(list);

    if((node=listFindTaggedNode(list, tag)) != NULL)
        data = list_remove_node(list, node, free_data);

    listUnlock(list);

    return(data);
}
Beispiel #24
0
void			list_remove_node(t_lst **node, char *varname)
{
	t_lst *tmp;

	tmp = *node;
	if (*node)
	{
		if (!ft_strcmp((*node)->name, varname))
		{
			tmp = *node;
			*node = (*(node))->next;
			ft_strdel(&(tmp->name));
			ft_strdel(&(tmp->content));
			free(tmp);
		}
		list_remove_node(&(*node)->next, varname);
	}
}
Beispiel #25
0
void
list_move_data(list *s, list *d, void *data)
{
	node *n;

	for (n = s->h; n; n = n->next) {
		if (n->data == data) {
			MT_lock_set(&s->ht_lock, "list_move_data");
			if (s->ht && n->data)
				hash_delete(s->ht, n->data);
			MT_lock_unset(&s->ht_lock, "list_move_data");
			n->data = NULL;	/* make sure data isn't destroyed */
			list_remove_node(s, n);
			break;
		}
	}
	list_append(d, data);
}
Beispiel #26
0
void
list_remove_data(list *s, void *data)
{
	node *n;

	/* maybe use compare func */
	for (n = s->h; n; n = n->next) {
		if (n->data == data) {
			MT_lock_set(&s->ht_lock, "list_remove_data");
			if (s->ht && n->data)
				hash_delete(s->ht, n->data);
			MT_lock_unset(&s->ht_lock, "list_remove_data");
			n->data = NULL;
			list_remove_node(s, n);
			break;
		}
	}
}
void
list_remove_value (linked_list_t list , void* val, linked_list_comparator_t cmp)
{
    node_t curr;
    node_t head;
    head = list->data;
    curr = head->next;
    while (curr != head)
    {
	if (cmp (curr->data, val) == 0)
	{
	    // backtrack to avoid corruption
	    curr = curr->prev;
	    list_remove_node (list, curr->next);
	}
	curr = curr->next;
    }
}
/* Why are satisfied signal bits cleared? Because there is no
need to clear it manually afterwards then. */
Signal task_wait(Signal mask)
{
    Signal ret;

    interrupts_disable();

    task_line("{mask=");
    log_hex(mask);
    log_string(", rec=");
    log_hex(running_task->sig_rec);
    log_string("} ==> ");

    if (!(mask & running_task->sig_rec)) {
        running_task->sig_mask = mask;
        list_remove_node((Node *) running_task);
        list_enqueue(&waiting_tasks, (Node *) running_task);

        log_string("blocked...");
        port_reschedule();
        /* Interrupts may occur here. */
        interrupts_disable();

        task_line("...unblocked ");
        log_string("{mask=");
        log_hex(mask);
        log_string("(");
        log_hex(running_task->sig_mask);
        log_string(")");
        log_string(", rec=");
        log_hex(running_task->sig_rec);
        log_string("} ==> ");
    }
    ret = running_task->sig_rec & mask;
    running_task->sig_rec &= ~mask;
    running_task->sig_mask = 0;

    log_string("{rec=");
    log_hex(running_task->sig_rec);
    log_string("}, return ");
    log_hex(ret);

    interrupts_enable();
    return ret;
}
Beispiel #29
0
void			do_unsetenv(t_lst *list, char **cmd)
{
	int		len;
	int		i;

	i = 0;
	len = ft_tablen(cmd);
	if (len == 1)
		ft_putendl_fd("unsetenv: Too few arguments.", 2);
	else if (len > 1)
	{
		while (cmd[++i])
		{
			if (ft_strcmp(cmd[i], "="))
				cmd[i] = ft_strcat(cmd[i], "=");
			list_remove_node(&list, cmd[i]);
		}
	}
}
Beispiel #30
0
/*
 * Pop a data value off the end of the list.
 */
LPVOID list_pop( LIST * list )
{
	LPVOID data = NULL;

	if( list == NULL )
		return NULL;

	lock_acquire( list->lock );

	if( list->end != NULL )
	{
		data = list->end->data;

		list_remove_node( list, list->end );
	}

	lock_release( list->lock );

	return data;
}