Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/radeon_list.c
4574 views
/*1* Copyright 2011 Tom Stellard <[email protected]>2*3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial15* portions of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,18* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE21* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION22* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION23* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25*/2627#include "radeon_list.h"2829#include <stdlib.h>30#include <stdio.h>3132#include "memory_pool.h"3334struct rc_list * rc_list(struct memory_pool * pool, void * item)35{36struct rc_list * new = memory_pool_malloc(pool, sizeof(struct rc_list));37new->Item = item;38new->Next = NULL;39new->Prev = NULL;4041return new;42}4344void rc_list_add(struct rc_list ** list, struct rc_list * new_value)45{46struct rc_list * temp;4748if (*list == NULL) {49*list = new_value;50return;51}5253for (temp = *list; temp->Next; temp = temp->Next);5455temp->Next = new_value;56new_value->Prev = temp;57}5859void rc_list_remove(struct rc_list ** list, struct rc_list * rm_value)60{61if (*list == rm_value) {62*list = rm_value->Next;63return;64}6566rm_value->Prev->Next = rm_value->Next;67if (rm_value->Next) {68rm_value->Next->Prev = rm_value->Prev;69}70}7172unsigned int rc_list_count(struct rc_list * list)73{74unsigned int count = 0;75while (list) {76count++;77list = list->Next;78}79return count;80}8182void rc_list_print(struct rc_list * list)83{84while(list) {85fprintf(stderr, "%p->", list->Item);86list = list->Next;87}88fprintf(stderr, "\n");89}909192