UserEvent.h revision 6a80e688
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
18namespace BKernel {
19
20
21struct Team;
22struct Thread;
23
24
25struct UserEvent : public BReferenceable {
26	virtual						~UserEvent();
27
28	virtual	status_t			Fire() = 0;
29};
30
31
32struct SignalEvent : UserEvent, private DPCCallback {
33	virtual						~SignalEvent();
34
35			void				SetUserValue(union sigval userValue);
36
37	virtual	status_t			Fire();
38
39protected:
40			struct EventSignal;
41
42protected:
43								SignalEvent(EventSignal* signal);
44
45protected:
46			EventSignal*		fSignal;
47			int32				fPendingDPC;
48};
49
50
51struct TeamSignalEvent : SignalEvent {
52	static	TeamSignalEvent*	Create(Team* team, uint32 signalNumber,
53									int32 signalCode, int32 errorCode);
54
55	virtual	status_t			Fire();
56
57protected:
58	virtual	void				DoDPC(DPCQueue* queue);
59
60private:
61								TeamSignalEvent(Team* team,
62									EventSignal* signal);
63
64private:
65			Team*				fTeam;
66};
67
68
69struct 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
76protected:
77	virtual	void				DoDPC(DPCQueue* queue);
78
79private:
80								ThreadSignalEvent(Thread* thread,
81									EventSignal* signal);
82
83private:
84			Thread*				fThread;
85};
86
87
88struct CreateThreadEvent : UserEvent, private DPCCallback {
89								~CreateThreadEvent();
90
91	static	CreateThreadEvent*	Create(
92									const ThreadCreationAttributes& attributes);
93
94	virtual	status_t			Fire();
95
96private:
97								CreateThreadEvent(
98									const ThreadCreationAttributes& attributes);
99
100	virtual	void				DoDPC(DPCQueue* queue);
101
102private:
103			ThreadCreationAttributes fCreationAttributes;
104			char				fThreadName[B_OS_NAME_LENGTH];
105			int32				fPendingDPC;
106};
107
108
109}	// namespace BKernel
110
111
112using BKernel::CreateThreadEvent;
113using BKernel::SignalEvent;
114using BKernel::TeamSignalEvent;
115using BKernel::ThreadSignalEvent;
116using BKernel::UserEvent;
117
118
119#endif	// _KERNEL_USER_EVENT_H
120