~drizzle-trunk/drizzle/development

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
73
74
75
76
77
/* Copyright (C) 2005 PrimeBase Technologies GmbH
 *
 * PrimeBase XT
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * 2005-02-03	Paul McCullagh
 *
 * H&G2JCtL
 */
#ifndef __xt_linklist_h__
#define __xt_linklist_h__

#include "xt_defs.h"

struct XTThread;

typedef struct XTLinkedItem {
	struct XTLinkedItem		*li_prev;
	struct XTLinkedItem		*li_next;
} XTLinkedItemRec, *XTLinkedItemPtr;

typedef struct XTLinkedList {
	xt_mutex_type			*ll_lock;
	xt_cond_type			*ll_cond;			/* Condition for wait for empty. */
	void					*ll_thunk;
	XTFreeFunc				ll_free_func;
	u_int					ll_item_count;
	XTLinkedItemPtr			ll_items;
} XTLinkedListRec, *XTLinkedListPtr;

XTLinkedListPtr		xt_new_linkedlist(struct XTThread *self, void *thunk, XTFreeFunc free_func, xtBool with_lock);
void				xt_free_linkedlist(struct XTThread *self, XTLinkedListPtr ll);

void				xt_ll_add(struct XTThread *self, XTLinkedListPtr ll, XTLinkedItemPtr li, xtBool lock);
void				xt_ll_remove(struct XTThread *self, XTLinkedListPtr ll, XTLinkedItemPtr li, xtBool lock);
xtBool 				xt_ll_exists(struct XTThread *self, XTLinkedListPtr ll, XTLinkedItemPtr li, xtBool lock);

void				xt_ll_lock(struct XTThread *self, XTLinkedListPtr ll);
void				xt_ll_unlock(struct XTThread *self, XTLinkedListPtr ll);

void				xt_ll_wait_till_empty(struct XTThread *self, XTLinkedListPtr ll);

XTLinkedItemPtr		xt_ll_first_item(struct XTThread *self, XTLinkedListPtr ll);
XTLinkedItemPtr		xt_ll_next_item(struct XTThread *self, XTLinkedItemPtr item);
u_int				xt_ll_get_size(XTLinkedListPtr ll);

typedef struct XTLinkedQItem {
	struct XTLinkedQItem	*qi_next;
} XTLinkedQItemRec, *XTLinkedQItemPtr;

typedef struct XTLinkedQueue {
	size_t					lq_count;
	XTLinkedQItemPtr		lq_front;
	XTLinkedQItemPtr		lq_back;
} XTLinkedQueueRec, *XTLinkedQueuePtr;

void				xt_init_linkedqueue(struct XTThread *self, XTLinkedQueuePtr lq);
void				xt_exit_linkedqueue(struct XTThread *self, XTLinkedQueuePtr lq);

void				xt_lq_add(struct XTThread *self, XTLinkedQueuePtr lq, XTLinkedQItemPtr qi);
XTLinkedQItemPtr	xt_lq_remove(struct XTThread *self, XTLinkedQueuePtr lq);

#endif