The Pedigree Project  0.1
TimeoutGuard.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef TIMEOUT_GUARD_H
21 #define TIMEOUT_GUARD_H
22 
29 #include "pedigree/kernel/Spinlock.h"
30 #include "pedigree/kernel/compiler.h"
31 #include "pedigree/kernel/process/Event.h"
32 #include "pedigree/kernel/process/eventNumbers.h"
33 #include "pedigree/kernel/processor/state.h"
34 #include "pedigree/kernel/processor/types.h"
35 
46 {
47  public:
49  TimeoutGuard(size_t timeoutSecs);
50 
52  ~TimeoutGuard();
53 
56  bool timedOut()
57  {
58  return m_bTimedOut;
59  }
60 
63  void cancel() NORETURN;
64 
66  class TimeoutGuardEvent : public Event
67  {
68  public:
69  TimeoutGuardEvent() : Event(0, false), m_pTarget(0)
70  {
71  }
72  TimeoutGuardEvent(TimeoutGuard *pTarget, size_t specificNestingLevel);
73  virtual ~TimeoutGuardEvent();
74 
75  virtual size_t serialize(uint8_t *pBuffer);
76  static bool unserialize(uint8_t *pBuffer, TimeoutGuardEvent &event);
77 
78  virtual size_t getNumber()
79  {
80  return EventNumbers::TimeoutGuard;
81  }
82 
85 
86  private:
88  TimeoutGuardEvent &operator=(const TimeoutGuardEvent &);
89  };
90 
91  private:
92  TimeoutGuard(const TimeoutGuard &);
93  TimeoutGuard &operator=(const TimeoutGuard &);
94 
97 
100 
102 #ifdef THREADS
103  SchedulerState m_State;
104 #else
105  void *m_State;
106 #endif
107 
109  size_t m_nLevel;
110 
113 };
114 
115 #endif
Spinlock m_Lock
Definition: TimeoutGuard.h:112
size_t m_nLevel
Definition: TimeoutGuard.h:109
TimeoutGuardEvent * m_pEvent
Definition: TimeoutGuard.h:96
bool timedOut()
Definition: TimeoutGuard.h:56
SchedulerState m_State
Definition: TimeoutGuard.h:103
bool m_bTimedOut
Definition: TimeoutGuard.h:99
Definition: Event.h:48