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