make use_spacer an enum
[monky] / src / timed_thread.h
1 /* timed_thread.h: Abstraction layer for timed threads
2  *
3  * Copyright (C) 2006-2007 Philip Kovacs pkovacs@users.sourceforge.net
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
18  * USA. */
19
20 #ifndef _TIMED_THREAD_H_
21 #define _TIMED_THREAD_H_
22
23 #include <stdlib.h>
24
25 /* 10000 microseconds = 10 ms =  0.01 sec */
26 #define MINIMUM_INTERVAL_USECS 10000
27
28 /* opaque structure for clients */
29 typedef struct _timed_thread timed_thread;
30
31 /* create a timed thread (object creation only) */
32 timed_thread *timed_thread_create(void *start_routine(void *), void *arg,
33         unsigned int interval_usecs);
34
35 /* run a timed thread (drop the thread and run it) */
36 int timed_thread_run(timed_thread *p_timed_thread);
37
38 /* destroy a timed thread */
39 void timed_thread_destroy(timed_thread *p_timed_thread,
40         timed_thread **addr_of_p_timed_thread);
41
42 /* lock a timed thread for critical section activity */
43 int timed_thread_lock(timed_thread *p_timed_thread);
44
45 /* unlock a timed thread after critical section activity */
46 int timed_thread_unlock(timed_thread *p_timed_thread);
47
48 /* waits required interval (unless override_wait_time is non-zero) for
49  * termination signal returns 1 if received, 0 otherwise. */
50 int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time);
51
52 /* exit a timed thread */
53 void timed_thread_exit(timed_thread *p_timed_thread) __attribute__((noreturn));
54
55 /* register a timed thread for future destruction via
56  * timed_thread_destroy_registered_threads() */
57 int timed_thread_register(timed_thread *p_timed_thread,
58         timed_thread **addr_of_p_timed_thread);
59
60 /* destroy all registered timed threads */
61 void timed_thread_destroy_registered_threads(void);
62
63 /* returns read file descriptor for thread pipe */
64 int timed_thread_readfd(timed_thread *p_timed_thread);
65
66 #endif /* #ifdef _TIMED_THREAD_H_ */