os4ec /Chapter_07_Threads/00_Start/lib/list.h

Language C/C++ Header Lines 73
MD5 Hash 5f7ecd279753488e1f2173d5d4ff00f2
Repository https://github.com/l30nard0/os4ec.git View Raw File View Project SPDX
 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
65
66
67
68
69
70
71
72
/*! List manipulation functions
 *
 * Double linked lists are used
 * List header points to first and last list element
 *
 */

#pragma once

/*! List element pointers */
typedef struct _list_h_
{
	struct _list_h_ *prev; /* pointer to previous list element */
	struct _list_h_ *next; /* pointer to next list element */
	void *object; /* pointer to object start */
}
list_h;

/*! list header type */
typedef struct _list_
{
	list_h *first;
	list_h *last;
}
list_t;

/*
 List element must be included in object that we want to put in list. Place and
 variable name is unimportant, but must be used when calling list functions.

 Simple list width only two elements will look like:

 struct some_object {
	 int something;
	 ...
	 list_h le1; // list element 1 for list1
	 ...
 } object1, object2;

 list_t some_list1;

 --when list is formed and both object are in list, data will lool like:

 some_list1.first = &object1.le1
 some_list1.last  = &object2.le1

 object1.le1.prev = NULL;			object2.le1.prev = &object2.le1;
 object1.le1.next = &object2.le1;		object2.le1.next = NULL;
 object1.le1.object = &object1			object2.le1.object = &object2;

 Same object can be in multiple list simultaneously if it have multiple list
 element data member (e.g. le2, le3).
*/

/* for static list elements initialization */
#define LIST_H_NULL	{ NULL, NULL, NULL }

/* for static list initialization (empty list) */
#define LIST_T_NULL	{ NULL, NULL }

#define FIRST	0	/* get first or last list element */
#define LAST	1

void list_init ( list_t *list );
void list_append ( list_t *list, void *object, list_h *hdr );
void list_prepend ( list_t *list, void *object, list_h *hdr );
void list_sort_add ( list_t *list, void *object, list_h *hdr,
				   int (*cmp) ( void *, void * ) );
void *list_get ( list_t *list, unsigned int flags );
void *list_remove ( list_t *list, unsigned int flags, list_h *ref );
void *list_find_and_remove ( list_t *list, list_h *ref );
void *list_get_next ( list_h *hdr );
Back to Top