aboutsummaryrefslogtreecommitdiff
path: root/DriverThread.hpp
blob: 39f5a89abea06ee165ca468489fe5ad7b4704290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef DDK_THREAD
#define DDK_THREAD 1

#include <ntddk.h>

#define TERMINATE_MYSELF(ntstatus) PsTerminateSystemThread(ntstatus);

namespace DriverThread
{

class Thread
{
public:
    Thread();
    NTSTATUS Start(PKSTART_ROUTINE threadRoutine, PVOID threadContext);
    NTSTATUS WaitForTermination(LONGLONG timeout = 0);

private:
    PETHREAD m_threadObject;
};

class Spinlock
{
public:
    Spinlock(void);
    NTSTATUS Acquire(KIRQL * const oldIrql);
    void Release(KIRQL * const oldIrql);

private:
    KSPIN_LOCK m_spinLock;
};

class Semaphore
{
public:
    explicit Semaphore(LONG initialValue = 0, LONG maxValue = MAXLONG);
    NTSTATUS Wait(LONGLONG timeout = 0);
    LONG Release(LONG adjustment = 1);

private:
    KSEMAPHORE m_semaphore;
};

}; // namespace DriverThread

#endif