File: list.h

package info (click to toggle)
tsdecrypt 10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,288 kB
  • sloc: ansic: 14,377; makefile: 245; sh: 166
file content (64 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * List manipulations header file
 * Copyright (C) 2006-2010 Unix Solutions Ltd.
 *
 * Released under MIT license.
 * See LICENSE-MIT.txt for license terms.
 */
#ifndef LIST_H
# define LIST_H

#ifdef __cplusplus
extern "C" {
#endif

#include <pthread.h>

typedef struct LNODE {
	struct LNODE *prev;
	struct LNODE *next;
	void *data;
} LNODE;

typedef struct LIST {
	pthread_mutex_t *mutex;		// List's lock
	struct LNODE *head;			// Points to first element of the list
	struct LNODE *tail;			// Points to last element of the list
	unsigned int items;			// How many items are in the list
	char *name;
} LIST;

// Safe against calling list_del inside
#define list_for_each(list, elem, tmp_el) \
	for (elem = (list)->head->next, tmp_el = elem->next; elem != (list)->head && elem->data; elem = tmp_el, tmp_el = elem->next)

#define list_for_each_reverse(list, elem, tmp_el) \
	for (elem = (list)->head->prev, tmp_el = elem->prev; elem != (list)->head && elem->data; elem = tmp_el, tmp_el = elem->prev)

// list_del can not be called inside this for
#define list_for_each_unsafe(list, elem) \
	for (elem = (list)->head->next; elem != (list)->head && elem->data; elem = elem->next)

#define list_for_each_reverse_unsafe(list, elem) \
	for (elem = (list)->head->prev; elem != (list)->head && elem->data; elem = elem->prev)

LIST *list_new			(char *listname);
void list_free			(LIST **l, void (*l_free)(void *), void (*l_freep)(void **));

void list_lock			(LIST *l);
void list_unlock		(LIST *l);

void list_add			(LIST *l, void *data);

int  list_del			(LIST *l, LNODE **node);
int  list_del_unlocked	(LIST *l, LNODE **node);

int  list_del_entry		(LIST *l, void *data);

void list_dump(LIST *l);

#ifdef __cplusplus
}
#endif

#endif