Tomato 1.28
[tomato.git] / release / src / router / zebra / lib / thread.h
blobfa230855ef33f96ce5f886c2ec1e36ae67a03433
1 /*
2 * Thread management routine header.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
23 #ifndef _ZEBRA_THREAD_H
24 #define _ZEBRA_THREAD_H
26 /* Linked list of thread. */
27 struct thread_list
29 struct thread *head;
30 struct thread *tail;
31 int count;
34 /* Master of the theads. */
35 struct thread_master
37 struct thread_list read;
38 struct thread_list write;
39 struct thread_list timer;
40 struct thread_list event;
41 struct thread_list ready;
42 struct thread_list unuse;
43 fd_set readfd;
44 fd_set writefd;
45 fd_set exceptfd;
46 unsigned long alloc;
49 /* Thread itself. */
50 struct thread
52 unsigned long id;
53 unsigned char type; /* thread type */
54 struct thread *next; /* next pointer of the thread */
55 struct thread *prev; /* previous pointer of the thread */
56 struct thread_master *master; /* pointer to the struct thread_master. */
57 int (*func) (struct thread *); /* event function */
58 void *arg; /* event argument */
59 union {
60 int val; /* second argument of the event. */
61 int fd; /* file descriptor in case of read/write. */
62 struct timeval sands; /* rest of time sands value. */
63 } u;
66 /* Macros. */
67 #define THREAD_ARG(X) ((X)->arg)
68 #define THREAD_FD(X) ((X)->u.fd)
69 #define THREAD_VAL(X) ((X)->u.val)
71 /* Prototypes. */
72 struct thread_master *thread_make_master ();
74 struct thread *
75 thread_add_read (struct thread_master *m,
76 int (*func)(struct thread *),
77 void *arg,
78 int fd);
80 struct thread *
81 thread_add_write (struct thread_master *m,
82 int (*func)(struct thread *),
83 void *arg,
84 int fd);
86 struct thread *
87 thread_add_timer (struct thread_master *m,
88 int (*func)(struct thread *),
89 void *arg,
90 long timer);
92 struct thread *
93 thread_add_event (struct thread_master *m,
94 int (*func)(struct thread *),
95 void *arg,
96 int val);
98 void
99 thread_cancel (struct thread *thread);
101 void
102 thread_cancel_event (struct thread_master *m, void *arg);
104 struct thread *
105 thread_fetch (struct thread_master *m,
106 struct thread *fetch);
108 void
109 thread_call (struct thread *thread);
111 struct thread *
112 thread_execute (struct thread_master *m,
113 int (*func)(struct thread *),
114 void *arg,
115 int val);
117 #endif /* _ZEBRA_THREAD_H */