Xenomai 3.3.2
Loading...
Searching...
No Matches
timerobj.h
1/*
2 * Copyright (C) 2010 Philippe Gerum <rpm@xenomai.org>.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18
19#ifndef _COPPERPLATE_TIMEROBJ_H
20#define _COPPERPLATE_TIMEROBJ_H
21
22#include <pthread.h>
23#include <time.h>
24#include <boilerplate/list.h>
25#include <boilerplate/lock.h>
26
27struct timerobj {
28 struct itimerspec itspec;
29 void (*handler)(struct timerobj *tmobj);
30 timer_t timer;
31 pthread_mutex_t lock;
32 int cancel_state;
33 struct pvholder next;
34};
35
36static inline int timerobj_lock(struct timerobj *tmobj)
37{
38 return write_lock_safe(&tmobj->lock, tmobj->cancel_state);
39}
40
41static inline int timerobj_unlock(struct timerobj *tmobj)
42{
43 return write_unlock_safe(&tmobj->lock, tmobj->cancel_state);
44}
45
46static inline int timerobj_enabled(const struct timerobj *tmobj)
47{
48 return tmobj->handler != NULL;
49}
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55int timerobj_init(struct timerobj *tmobj);
56
57void timerobj_destroy(struct timerobj *tmobj);
58
59int timerobj_start(struct timerobj *tmobj,
60 void (*handler)(struct timerobj *tmobj),
61 struct itimerspec *it);
62
63int timerobj_stop(struct timerobj *tmobj);
64
65int timerobj_pkg_init(void);
66
67#ifdef __cplusplus
68}
69#endif
70
71#endif /* _COPPERPLATE_TIMEROBJ_H */