mirror-ac/driver/queue.c

64 lines
1.2 KiB
C
Raw Normal View History

2023-08-20 16:12:04 +02:00
#include "queue.h"
2023-09-02 10:54:04 +02:00
#include "callbacks.h"
#include "driver.h"
#include "queue.h"
#include "pool.h"
#include "thread.h"
#include "io.h"
2023-08-30 18:29:44 +02:00
#include "common.h"
#include "imports.h"
2023-08-30 18:29:44 +02:00
2023-10-05 08:27:17 +02:00
VOID
2023-12-13 05:06:27 +01:00
QueuePush(_Inout_ PQUEUE_HEAD Head, _In_ PVOID Data)
2023-08-20 16:12:04 +02:00
{
ImpKeAcquireGuardedMutex(&Head->lock);
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
PQUEUE_NODE temp = ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(QUEUE_NODE), QUEUE_POOL_TAG);
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
if (!temp)
goto end;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
Head->entries += 1;
2023-08-20 17:04:53 +02:00
2023-12-13 05:06:27 +01:00
temp->data = Data;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
if (Head->end != NULL)
Head->end->next = temp;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
Head->end = temp;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
if (Head->start == NULL)
Head->start = temp;
2023-08-20 16:12:04 +02:00
end:
ImpKeReleaseGuardedMutex(&Head->lock);
2023-08-20 16:12:04 +02:00
}
2023-10-05 08:27:17 +02:00
PVOID
2023-12-13 05:06:27 +01:00
QueuePop(_Inout_ PQUEUE_HEAD Head)
2023-08-20 16:12:04 +02:00
{
ImpKeAcquireGuardedMutex(&Head->lock);
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
PVOID data = NULL;
PQUEUE_NODE temp = Head->start;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
if (temp == NULL)
goto end;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
Head->entries = Head->entries - 1;
2023-08-20 17:04:53 +02:00
2023-12-13 05:06:27 +01:00
data = temp->data;
Head->start = temp->next;
2023-08-20 16:12:04 +02:00
2023-12-13 05:06:27 +01:00
if (Head->end == temp)
Head->end = NULL;
2023-08-20 16:12:04 +02:00
ImpExFreePoolWithTag(temp, QUEUE_POOL_TAG);
2023-08-20 16:12:04 +02:00
end:
ImpKeReleaseGuardedMutex(&Head->lock);
2023-12-13 05:06:27 +01:00
return data;
2024-01-14 05:31:19 +01:00
}