1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _KERNEL_USER_EVENT_H 6 #define _KERNEL_USER_EVENT_H 7 8 9 #include <signal.h> 10 11 #include <SupportDefs.h> 12 13 #include <DPC.h> 14 #include <thread.h> 15 16 17 namespace BKernel { 18 19 20 struct Team; 21 struct Thread; 22 23 24 struct UserEvent { 25 virtual ~UserEvent(); 26 27 virtual status_t Fire() = 0; 28 }; 29 30 31 struct SignalEvent : UserEvent, private DPCCallback { 32 virtual ~SignalEvent(); 33 34 void SetUserValue(union sigval userValue); 35 36 virtual status_t Fire(); 37 38 protected: 39 struct EventSignal; 40 41 protected: 42 SignalEvent(EventSignal* signal); 43 44 protected: 45 EventSignal* fSignal; 46 int32 fPendingDPC; 47 }; 48 49 50 struct TeamSignalEvent : SignalEvent { 51 static TeamSignalEvent* Create(Team* team, uint32 signalNumber, 52 int32 signalCode, int32 errorCode); 53 54 protected: 55 virtual void DoDPC(DPCQueue* queue); 56 57 private: 58 TeamSignalEvent(Team* team, 59 EventSignal* signal); 60 61 private: 62 Team* fTeam; 63 }; 64 65 66 struct ThreadSignalEvent : SignalEvent { 67 static ThreadSignalEvent* Create(Thread* thread, uint32 signalNumber, 68 int32 signalCode, int32 errorCode, 69 pid_t sendingTeam); 70 71 protected: 72 virtual void DoDPC(DPCQueue* queue); 73 74 private: 75 ThreadSignalEvent(Thread* thread, 76 EventSignal* signal); 77 78 private: 79 Thread* fThread; 80 }; 81 82 83 struct CreateThreadEvent : UserEvent, private DPCCallback { 84 ~CreateThreadEvent(); 85 86 static CreateThreadEvent* Create( 87 const ThreadCreationAttributes& attributes); 88 89 virtual status_t Fire(); 90 91 private: 92 CreateThreadEvent( 93 const ThreadCreationAttributes& attributes); 94 95 virtual void DoDPC(DPCQueue* queue); 96 97 private: 98 ThreadCreationAttributes fCreationAttributes; 99 char fThreadName[B_OS_NAME_LENGTH]; 100 int32 fPendingDPC; 101 }; 102 103 104 } // namespace BKernel 105 106 107 using BKernel::CreateThreadEvent; 108 using BKernel::SignalEvent; 109 using BKernel::TeamSignalEvent; 110 using BKernel::ThreadSignalEvent; 111 using BKernel::UserEvent; 112 113 114 #endif // _KERNEL_USER_EVENT_H 115