aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-09-10 16:48:15 +0200
committerToni Uhlig <matzeton@googlemail.com>2022-09-10 16:48:57 +0200
commit74146a39c666a87d0480125669feb9901e5bc8cb (patch)
tree184e9fa86293bd7eafec64c72fe6b657f36199c7 /examples
parent51521cb642358770e94b8f9b4f40dd3b4c827cad (diff)
Implemented WorkQueue's as they are pretty common in WDK.
* added calloc() symbol Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/dpp-example-cplusplus.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/dpp-example-cplusplus.cpp b/examples/dpp-example-cplusplus.cpp
index c1d9b29..0d04d37 100644
--- a/examples/dpp-example-cplusplus.cpp
+++ b/examples/dpp-example-cplusplus.cpp
@@ -56,6 +56,13 @@ private:
unsigned int some_value = 0;
};
+struct WorkItem
+{
+ SLIST_ENTRY QueueEntry;
+
+ UINT32 counter;
+};
+static DriverThread::WorkQueue work_queue;
static DerivedWithCDtor some_static(0xDEADC0DE);
struct threadContext
@@ -79,6 +86,21 @@ 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;
@@ -94,6 +116,12 @@ static void test_cplusplus(void)
ctx.dth.WaitForTermination();
DbgPrint("MainThread EOF\n");
+ struct WorkItem * wi = (struct WorkItem *)calloc(1, sizeof(*wi));
+ wi->counter = 3;
+ work_queue.Enqueue(&wi->QueueEntry);
+ work_queue.Start(test_worker);
+ work_queue.Stop();
+
some_static.doSmth();
}