The Pedigree Project  0.1
Event.h
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 EVENT_H
21 #define EVENT_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/List.h"
27 #include "pedigree/kernel/utilities/new"
28 
29 #ifdef THREADS
30 class Thread;
31 #endif
32 
34 #define EVENT_LIMIT 4096
35 
36 #define EVENT_TID_MAX 255
37 
39 #define MAX_NESTED_EVENTS 16
40 
41 #define EVENT_MAGIC 0x8899AABBCCDDEEFFULL
42 
49 {
50  public:
60  Event(
61  uintptr_t handlerAddress, bool isDeletable,
62  size_t specificNestingLevel = ~0UL);
63  virtual ~Event();
64 
66  static uintptr_t getTrampoline();
67 
69  static uintptr_t getSecondaryTrampoline();
70 
72  static uintptr_t getHandlerBuffer();
73 
75  static uintptr_t getLastHandlerBuffer();
76 
80  virtual bool isDeletable();
81 
93  virtual size_t serialize(uint8_t *pBuffer) = 0;
94 
101  static bool unserialize(uint8_t *pBuffer, Event &event);
102 
105  static size_t getEventType(uint8_t *pBuffer);
106 
108  uintptr_t getHandlerAddress()
109  {
110  return m_HandlerAddress;
111  }
112 
115  {
116  return m_NestingLevel;
117  }
118 
120  virtual size_t getNumber() = 0;
121 
122  Event(const Event &other);
123  Event &operator=(const Event &other);
124 
125 #ifdef THREADS
126 
128  void registerThread(Thread *thread);
129 
131  void deregisterThread(Thread *thread);
132 
134  size_t pendingCount();
135 #endif
136 
138  virtual void waitForDeliveries();
139 
140  protected:
142  uintptr_t m_HandlerAddress;
143 
146 
149 
151  size_t m_Magic;
152 
153 #ifdef THREADS
154 
156 
159 #endif
160 };
161 
162 #endif
Spinlock m_Lock
Definition: Event.h:158
size_t getSpecificNestingLevel()
Definition: Event.h:114
size_t m_NestingLevel
Definition: Event.h:148
uintptr_t getHandlerAddress()
Definition: Event.h:108
size_t m_Magic
Definition: Event.h:151
uintptr_t m_HandlerAddress
Definition: Event.h:142
List< Thread * > m_Threads
Definition: Event.h:155
Definition: Thread.h:54
Definition: Event.h:48
bool m_bIsDeletable
Definition: Event.h:145