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