aboutsummaryrefslogtreecommitdiff
path: root/examples/dpp-example-cplusplus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dpp-example-cplusplus.cpp')
-rw-r--r--examples/dpp-example-cplusplus.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/examples/dpp-example-cplusplus.cpp b/examples/dpp-example-cplusplus.cpp
index 0d04d37..cbdd7c6 100644
--- a/examples/dpp-example-cplusplus.cpp
+++ b/examples/dpp-example-cplusplus.cpp
@@ -56,12 +56,12 @@ private:
unsigned int some_value = 0;
};
-struct WorkItem
+class MyWorkItem : public DriverThread::WorkItem
{
- SLIST_ENTRY QueueEntry;
-
+public:
UINT32 counter;
};
+
static DriverThread::WorkQueue work_queue;
static DerivedWithCDtor some_static(0xDEADC0DE);
@@ -86,21 +86,6 @@ static NTSTATUS threadRoutine(PVOID threadContext)
return STATUS_SUCCESS;
}
-static NTSTATUS test_worker(PSLIST_ENTRY workItem)
-{
- struct WorkItem * wi = CONTAINING_RECORD(workItem, struct WorkItem, QueueEntry);
-
- while (wi->counter-- > 0)
- {
- DbgPrint("WorkItem Counter: %u\n", wi->counter);
- }
- DbgPrint("Worker finished.\n");
-
- free(wi);
-
- return STATUS_SUCCESS;
-}
-
static void test_cplusplus(void)
{
TestSmth t;
@@ -116,10 +101,24 @@ static void test_cplusplus(void)
ctx.dth.WaitForTermination();
DbgPrint("MainThread EOF\n");
- struct WorkItem * wi = (struct WorkItem *)calloc(1, sizeof(*wi));
+ MyWorkItem * wi = new MyWorkItem();
wi->counter = 3;
- work_queue.Enqueue(&wi->QueueEntry);
- work_queue.Start(test_worker);
+ work_queue.Enqueue(wi);
+ work_queue.Start(
+ [](DriverThread::WorkItem * item)
+ {
+ MyWorkItem * wi =
+ reinterpret_cast<MyWorkItem *>(CONTAINING_RECORD(item, DriverThread::WorkItem, QueueEntry));
+
+ while (wi->counter-- > 0)
+ {
+ DbgPrint("WorkItem Counter: %u\n", wi->counter);
+ }
+ DbgPrint("Worker finished.\n");
+
+ delete item;
+ return STATUS_SUCCESS;
+ });
work_queue.Stop();
some_static.doSmth();