source: trunk/module-obj-llist.h@ 3690

Last change on this file since 3690 was 3690, checked in by dingo35, 13 years ago

module-obj-llist.h also restoring this to the right file, sorry for this mess

File size: 1.8 KB
Line 
1/*
2 * module-obj-llist.h
3 *
4 * Created on: 23.04.2010
5 * Author: alno
6 */
7
8#ifndef OSCAMLLIST_D__H_
9#define OSCAMLLIST_D__H_
10
11/******************************** */
12/* LINKED LIST CODE - IF IT'S USEFUL ELSEWHERE, IT SHOULD BE SPLIT OFF INTO linkedlist.h/.c */
13/******************************** */
14
15// Simple, doubly linked
16// This is thread-safe, so requires pthread. Also expect locking if iterators are not destroyed.
17
18#include <pthread.h>
19
20struct llist_node {
21 void *obj;
22 struct llist_node *prv;
23 struct llist_node *nxt;
24};
25
26typedef struct llist_d {
27 struct llist_node *first;
28 struct llist_node *last;
29 int items;
30 pthread_mutex_t lock;
31} LLIST_D_;
32
33typedef struct llist_itr {
34 LLIST_D_ *l;
35 struct llist_node *cur;
36} LLIST_D__ITR;
37
38LLIST_D_ *llist_create(void); // init linked list
39void llist_destroy(LLIST_D_ *l); // de-init linked list - frees all objects on the list
40void llist_clear(LLIST_D_ *l); // frees all objects on the list
41
42void *llist_append(LLIST_D_ *l, void *o); // append object onto bottom of list, returns ptr to obj
43void *llist_insert_first(LLIST_D_ *l, void *o); // append object onto bottom of list, returns ptr to obj
44
45void *llist_itr_init(LLIST_D_ *l, LLIST_D__ITR *itr); // linked list iterator, returns ptr to first obj
46//void llist_itr_release(LLIST_D__ITR *itr); // release iterator
47void *llist_itr_next(LLIST_D__ITR *itr); // iterates, returns ptr to next obj
48
49void *llist_itr_insert(LLIST_D__ITR *itr, void *o); // insert object at itr point, iterates to and returns ptr to new obj
50void *llist_itr_remove(LLIST_D__ITR *itr); // remove obj at itr, iterates to and returns ptr to next obj
51
52int llist_count(LLIST_D_ *l); // returns number of obj in list
53
54#endif /* OSCAMLLIST_D__H_ */
Note: See TracBrowser for help on using the repository browser.