diff options
Diffstat (limited to 'xorg-server/hw/xquartz/xpr/x-list.c')
-rw-r--r-- | xorg-server/hw/xquartz/xpr/x-list.c | 164 |
1 files changed, 65 insertions, 99 deletions
diff --git a/xorg-server/hw/xquartz/xpr/x-list.c b/xorg-server/hw/xquartz/xpr/x-list.c index 77c9309aa..757ff4cb0 100644 --- a/xorg-server/hw/xquartz/xpr/x-list.c +++ b/xorg-server/hw/xquartz/xpr/x-list.c @@ -50,57 +50,51 @@ static x_list *freelist; static pthread_mutex_t freelist_lock = PTHREAD_MUTEX_INITIALIZER; static inline void -list_free_1 (x_list *node) +list_free_1(x_list * node) { node->next = freelist; freelist = node; } X_EXTERN void -X_PFX (list_free_1) (x_list *node) -{ - assert (node != NULL); + X_PFX(list_free_1) (x_list * node) { + assert(node != NULL); - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - list_free_1 (node); + list_free_1(node); - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); } X_EXTERN void -X_PFX (list_free) (x_list *lst) -{ + X_PFX(list_free) (x_list * lst) { x_list *next; - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - for (; lst != NULL; lst = next) - { + for (; lst != NULL; lst = next) { next = lst->next; - list_free_1 (lst); + list_free_1(lst); } - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); } -X_EXTERN x_list * -X_PFX (list_prepend) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_prepend) (x_list * lst, void *data) { x_list *node; - pthread_mutex_lock (&freelist_lock); + pthread_mutex_lock(&freelist_lock); - if (freelist == NULL) - { + if (freelist == NULL) { x_list_block *b; int i; - b = malloc (sizeof (x_list_block)); + b = malloc(sizeof(x_list_block)); assert(b != NULL); for (i = 0; i < NODES_PER_BLOCK - 1; i++) - b->l[i].next = &(b->l[i+1]); + b->l[i].next = &(b->l[i + 1]); b->l[i].next = NULL; freelist = b->l; @@ -109,7 +103,7 @@ X_PFX (list_prepend) (x_list *lst, void *data) node = freelist; freelist = node->next; - pthread_mutex_unlock (&freelist_lock); + pthread_mutex_unlock(&freelist_lock); node->next = lst; node->data = data; @@ -117,29 +111,24 @@ X_PFX (list_prepend) (x_list *lst, void *data) return node; } -X_EXTERN x_list * -X_PFX (list_append) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_append) (x_list * lst, void *data) { x_list *head = lst; if (lst == NULL) - return X_PFX (list_prepend) (NULL, data); + return X_PFX(list_prepend) (NULL, data); while (lst->next != NULL) lst = lst->next; - lst->next = X_PFX (list_prepend) (NULL, data); + lst->next = X_PFX(list_prepend) (NULL, data); return head; } -X_EXTERN x_list * -X_PFX (list_reverse) (x_list *lst) -{ +X_EXTERN x_list *X_PFX(list_reverse) (x_list * lst) { x_list *head = NULL, *next; - - while (lst != NULL) - { + + while (lst != NULL) { next = lst->next; lst->next = head; head = lst; @@ -149,11 +138,8 @@ X_PFX (list_reverse) (x_list *lst) return head; } -X_EXTERN x_list * -X_PFX (list_find) (x_list *lst, void *data) -{ - for (; lst != NULL; lst = lst->next) - { +X_EXTERN x_list *X_PFX(list_find) (x_list * lst, void *data) { + for (; lst != NULL; lst = lst->next) { if (lst->data == data) return lst; } @@ -161,26 +147,22 @@ X_PFX (list_find) (x_list *lst, void *data) return NULL; } -X_EXTERN x_list * -X_PFX (list_nth) (x_list *lst, int n) -{ +X_EXTERN x_list *X_PFX(list_nth) (x_list * lst, int n) { while (n-- > 0 && lst != NULL) lst = lst->next; return lst; } -X_EXTERN x_list * -X_PFX (list_pop) (x_list *lst, void **data_ret) -{ +X_EXTERN x_list *X_PFX(list_pop) (x_list * lst, void **data_ret) { void *data = NULL; - if (lst != NULL) - { + if (lst != NULL) { x_list *tem = lst; + data = lst->data; lst = lst->next; - X_PFX (list_free_1) (tem); + X_PFX(list_free_1) (tem); } if (data_ret != NULL) @@ -189,61 +171,50 @@ X_PFX (list_pop) (x_list *lst, void **data_ret) return lst; } -X_EXTERN x_list * -X_PFX (list_filter) (x_list *lst, - int (*pred) (void *item, void *data), void *data) -{ +X_EXTERN x_list *X_PFX(list_filter) (x_list * lst, + int (*pred) (void *item, void *data), + void *data) { x_list *ret = NULL, *node; - for (node = lst; node != NULL; node = node->next) - { + for (node = lst; node != NULL; node = node->next) { if ((*pred) (node->data, data)) - ret = X_PFX (list_prepend) (ret, node->data); + ret = X_PFX(list_prepend) (ret, node->data); } - return X_PFX (list_reverse) (ret); + return X_PFX(list_reverse) (ret); } -X_EXTERN x_list * -X_PFX (list_map) (x_list *lst, - void *(*fun) (void *item, void *data), void *data) -{ +X_EXTERN x_list *X_PFX(list_map) (x_list * lst, + void *(*fun) (void *item, void *data), + void *data) { x_list *ret = NULL, *node; - for (node = lst; node != NULL; node = node->next) - { - X_PFX (list_prepend) (ret, fun (node->data, data)); + for (node = lst; node != NULL; node = node->next) { + X_PFX(list_prepend) (ret, fun(node->data, data)); } - return X_PFX (list_reverse) (ret); + return X_PFX(list_reverse) (ret); } -X_EXTERN x_list * -X_PFX (list_copy) (x_list *lst) -{ +X_EXTERN x_list *X_PFX(list_copy) (x_list * lst) { x_list *copy = NULL; - for (; lst != NULL; lst = lst->next) - { - copy = X_PFX (list_prepend) (copy, lst->data); + for (; lst != NULL; lst = lst->next) { + copy = X_PFX(list_prepend) (copy, lst->data); } - return X_PFX (list_reverse) (copy); + return X_PFX(list_reverse) (copy); } -X_EXTERN x_list * -X_PFX (list_remove) (x_list *lst, void *data) -{ +X_EXTERN x_list *X_PFX(list_remove) (x_list * lst, void *data) { x_list **ptr, *node; - for (ptr = &lst; *ptr != NULL;) - { + for (ptr = &lst; *ptr != NULL;) { node = *ptr; - if (node->data == data) - { + if (node->data == data) { *ptr = node->next; - X_PFX (list_free_1) (node); + X_PFX(list_free_1) (node); } else ptr = &((*ptr)->next); @@ -253,8 +224,7 @@ X_PFX (list_remove) (x_list *lst, void *data) } X_EXTERN unsigned int -X_PFX (list_length) (x_list *lst) -{ + X_PFX(list_length) (x_list * lst) { unsigned int n; n = 0; @@ -265,19 +235,17 @@ X_PFX (list_length) (x_list *lst) } X_EXTERN void -X_PFX (list_foreach) (x_list *lst, - void (*fun) (void *data, void *user_data), - void *user_data) -{ - for (; lst != NULL; lst = lst->next) - { + +X_PFX(list_foreach) (x_list * lst, + void (*fun) (void *data, void *user_data), + void *user_data) { + for (; lst != NULL; lst = lst->next) { (*fun) (lst->data, user_data); } } static x_list * -list_sort_1 (x_list *lst, int length, - int (*less) (const void *, const void *)) +list_sort_1(x_list * lst, int length, int (*less) (const void *, const void *)) { x_list *mid, *ptr; x_list *out_head, *out; @@ -299,20 +267,19 @@ list_sort_1 (x_list *lst, int length, /* Sort each sub-list. */ - lst = list_sort_1 (lst, mid_point, less); - mid = list_sort_1 (mid, length - mid_point, less); + lst = list_sort_1(lst, mid_point, less); + mid = list_sort_1(mid, length - mid_point, less); /* Then merge them back together. */ - assert (lst != NULL && mid != NULL); + assert(lst != NULL && mid != NULL); if ((*less) (mid->data, lst->data)) out = out_head = mid, mid = mid->next; else out = out_head = lst, lst = lst->next; - while (lst != NULL && mid != NULL) - { + while (lst != NULL && mid != NULL) { if ((*less) (mid->data, lst->data)) out = out->next = mid, mid = mid->next; else @@ -327,12 +294,11 @@ list_sort_1 (x_list *lst, int length, return out_head; } -X_EXTERN x_list * -X_PFX (list_sort) (x_list *lst, int (*less) (const void *, const void *)) -{ +X_EXTERN x_list *X_PFX(list_sort) (x_list * lst, + int (*less) (const void *, const void *)) { int length; - length = X_PFX (list_length) (lst); + length = X_PFX(list_length) (lst); - return list_sort_1 (lst, length, less); + return list_sort_1(lst, length, less); } |