2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
11 #include <KernelExport.h>
13 #include <util/DoublyLinkedList.h>
15 #include <condition_variable.h>
24 class DPCCallback
: public DoublyLinkedListLinkImpl
<DPCCallback
> {
27 virtual ~DPCCallback();
29 virtual void DoDPC(DPCQueue
* queue
) = 0;
32 friend class DPCQueue
;
39 class FunctionDPCCallback
: public DPCCallback
{
41 FunctionDPCCallback(DPCQueue
* owner
);
43 void SetTo(void (*function
)(void*), void* argument
);
45 virtual void DoDPC(DPCQueue
* queue
);
49 void (*fFunction
)(void*);
59 static DPCQueue
* DefaultQueue(int priority
);
61 status_t
Init(const char* name
, int32 priority
,
62 uint32 reservedSlots
);
63 void Close(bool cancelPending
);
65 status_t
Add(DPCCallback
* callback
);
66 status_t
Add(void (*function
)(void*), void* argument
);
67 bool Cancel(DPCCallback
* callback
);
69 thread_id
Thread() const
73 // conceptually package private
74 void Recycle(FunctionDPCCallback
* callback
);
77 typedef DoublyLinkedList
<DPCCallback
> CallbackList
;
80 static status_t
_ThreadEntry(void* data
);
83 bool _IsClosed() const
84 { return fThreadID
< 0; }
89 CallbackList fCallbacks
;
90 CallbackList fUnusedFunctionCallbacks
;
91 ConditionVariable fPendingCallbacksCondition
;
92 DPCCallback
* fCallbackInProgress
;
93 ConditionVariable
* fCallbackDoneCondition
;
97 } // namespace BKernel
100 using BKernel::DPCCallback
;
101 using BKernel::DPCQueue
;
102 using BKernel::FunctionDPCCallback
;
112 #endif // _KERNEL_DPC_H