haiku/headers/private/kernel/DPC.h
Ingo Weinhold 24df65921b Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
  handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
  support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
  of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
  [set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-06-12 00:00:23 +00:00

115 lines
2.1 KiB
C++

/*
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_DPC_H
#define _KERNEL_DPC_H
#include <sys/cdefs.h>
#include <KernelExport.h>
#include <util/DoublyLinkedList.h>
#include <condition_variable.h>
namespace BKernel {
class DPCQueue;
class DPCCallback : public DoublyLinkedListLinkImpl<DPCCallback> {
public:
DPCCallback();
virtual ~DPCCallback();
virtual void DoDPC(DPCQueue* queue) = 0;
private:
friend class DPCQueue;
private:
DPCQueue* fInQueue;
};
class FunctionDPCCallback : public DPCCallback {
public:
FunctionDPCCallback(DPCQueue* owner);
void SetTo(void (*function)(void*), void* argument);
virtual void DoDPC(DPCQueue* queue);
private:
DPCQueue* fOwner;
void (*fFunction)(void*);
void* fArgument;
};
class DPCQueue {
public:
DPCQueue();
~DPCQueue();
static DPCQueue* DefaultQueue(int priority);
status_t Init(const char* name, int32 priority,
uint32 reservedSlots);
void Close(bool cancelPending);
status_t Add(DPCCallback* callback,
bool schedulerLocked);
status_t Add(void (*function)(void*), void* argument,
bool schedulerLocked);
bool Cancel(DPCCallback* callback);
thread_id Thread() const
{ return fThreadID; }
public:
// conceptually package private
void Recycle(FunctionDPCCallback* callback);
private:
typedef DoublyLinkedList<DPCCallback> CallbackList;
private:
static status_t _ThreadEntry(void* data);
status_t _Thread();
bool _IsClosed() const
{ return fThreadID < 0; }
private:
spinlock fLock;
thread_id fThreadID;
CallbackList fCallbacks;
CallbackList fUnusedFunctionCallbacks;
ConditionVariable fPendingCallbacksCondition;
DPCCallback* fCallbackInProgress;
ConditionVariable* fCallbackDoneCondition;
};
} // namespace BKernel
using BKernel::DPCCallback;
using BKernel::DPCQueue;
using BKernel::FunctionDPCCallback;
__BEGIN_DECLS
void dpc_init();
__END_DECLS
#endif // _KERNEL_DPC_H