btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / DPC.h
blob3c883a7a21b6237ccca42d9bd62a7c25f21dacab
1 /*
2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _KERNEL_DPC_H
6 #define _KERNEL_DPC_H
9 #include <sys/cdefs.h>
11 #include <KernelExport.h>
13 #include <util/DoublyLinkedList.h>
15 #include <condition_variable.h>
18 namespace BKernel {
21 class DPCQueue;
24 class DPCCallback : public DoublyLinkedListLinkImpl<DPCCallback> {
25 public:
26 DPCCallback();
27 virtual ~DPCCallback();
29 virtual void DoDPC(DPCQueue* queue) = 0;
31 private:
32 friend class DPCQueue;
34 private:
35 DPCQueue* fInQueue;
39 class FunctionDPCCallback : public DPCCallback {
40 public:
41 FunctionDPCCallback(DPCQueue* owner);
43 void SetTo(void (*function)(void*), void* argument);
45 virtual void DoDPC(DPCQueue* queue);
47 private:
48 DPCQueue* fOwner;
49 void (*fFunction)(void*);
50 void* fArgument;
54 class DPCQueue {
55 public:
56 DPCQueue();
57 ~DPCQueue();
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
70 { return fThreadID; }
72 public:
73 // conceptually package private
74 void Recycle(FunctionDPCCallback* callback);
76 private:
77 typedef DoublyLinkedList<DPCCallback> CallbackList;
79 private:
80 static status_t _ThreadEntry(void* data);
81 status_t _Thread();
83 bool _IsClosed() const
84 { return fThreadID < 0; }
86 private:
87 spinlock fLock;
88 thread_id fThreadID;
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;
105 __BEGIN_DECLS
107 void dpc_init();
109 __END_DECLS
112 #endif // _KERNEL_DPC_H