1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB. |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#ifndef __FFADO_WATCHDOG__ |
---|
25 |
#define __FFADO_WATCHDOG__ |
---|
26 |
|
---|
27 |
#include "debugmodule/debugmodule.h" |
---|
28 |
#include "libutil/Thread.h" |
---|
29 |
|
---|
30 |
namespace Util { |
---|
31 |
|
---|
32 |
typedef std::vector<Thread *> ThreadVector; |
---|
33 |
typedef std::vector<Thread *>::iterator ThreadVectorIterator; |
---|
34 |
|
---|
35 |
class IsoHandlerManager; |
---|
36 |
|
---|
37 |
class Watchdog |
---|
38 |
{ |
---|
39 |
private: |
---|
40 |
class WatchdogCheckTask : public Util::RunnableInterface |
---|
41 |
{ |
---|
42 |
public: |
---|
43 |
WatchdogCheckTask(Watchdog& parent, unsigned int interval_usecs); |
---|
44 |
virtual ~WatchdogCheckTask() {}; |
---|
45 |
|
---|
46 |
bool Init(); |
---|
47 |
bool Execute(); |
---|
48 |
private: |
---|
49 |
Watchdog& m_parent; |
---|
50 |
unsigned int m_interval; |
---|
51 |
// debug stuff |
---|
52 |
#ifdef DEBUG |
---|
53 |
uint64_t m_last_loop_entry; |
---|
54 |
int m_successive_short_loops; |
---|
55 |
#endif |
---|
56 |
DECLARE_DEBUG_MODULE_REFERENCE; |
---|
57 |
}; |
---|
58 |
|
---|
59 |
class WatchdogHartbeatTask : public Util::RunnableInterface |
---|
60 |
{ |
---|
61 |
public: |
---|
62 |
WatchdogHartbeatTask(Watchdog& parent, unsigned int interval_usecs); |
---|
63 |
virtual ~WatchdogHartbeatTask() {}; |
---|
64 |
|
---|
65 |
bool Init(); |
---|
66 |
bool Execute(); |
---|
67 |
private: |
---|
68 |
Watchdog& m_parent; |
---|
69 |
unsigned int m_interval; |
---|
70 |
// debug stuff |
---|
71 |
#ifdef DEBUG |
---|
72 |
uint64_t m_last_loop_entry; |
---|
73 |
int m_successive_short_loops; |
---|
74 |
#endif |
---|
75 |
DECLARE_DEBUG_MODULE_REFERENCE; |
---|
76 |
}; |
---|
77 |
|
---|
78 |
public: |
---|
79 |
Watchdog(); |
---|
80 |
Watchdog(unsigned int interval_usec, bool realtime, unsigned int priority); |
---|
81 |
virtual ~Watchdog(); |
---|
82 |
|
---|
83 |
bool registerThread(Thread *thread); |
---|
84 |
bool unregisterThread(Thread *thread); |
---|
85 |
|
---|
86 |
bool start(); |
---|
87 |
|
---|
88 |
bool setThreadParameters(bool rt, int priority); |
---|
89 |
|
---|
90 |
void setVerboseLevel(int i); |
---|
91 |
|
---|
92 |
protected: |
---|
93 |
bool getHartbeat() {return m_hartbeat;}; |
---|
94 |
void clearHartbeat() {m_hartbeat=false;}; |
---|
95 |
void setHartbeat() {m_hartbeat=true;}; |
---|
96 |
|
---|
97 |
void rescheduleThreads(); |
---|
98 |
|
---|
99 |
private: |
---|
100 |
ThreadVector m_Threads; |
---|
101 |
bool m_hartbeat; |
---|
102 |
|
---|
103 |
unsigned int m_check_interval; |
---|
104 |
bool m_realtime; |
---|
105 |
int m_priority; |
---|
106 |
Util::Thread * m_CheckThread; |
---|
107 |
Util::Thread * m_HartbeatThread; |
---|
108 |
WatchdogCheckTask * m_CheckTask; |
---|
109 |
WatchdogHartbeatTask * m_HartbeatTask; |
---|
110 |
|
---|
111 |
DECLARE_DEBUG_MODULE; |
---|
112 |
}; |
---|
113 |
|
---|
114 |
} // end of namespace Util |
---|
115 |
|
---|
116 |
#endif /* __FFADO_WATCHDOG__ */ |
---|
117 |
|
---|
118 |
|
---|