diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 1c4fe0a..b1b2080 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -92,6 +92,7 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/rtl/endian.cc ${XTOSKRNL_SOURCE_DIR}/rtl/exports.cc ${XTOSKRNL_SOURCE_DIR}/rtl/guid.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/lifo.cc ${XTOSKRNL_SOURCE_DIR}/rtl/llist.cc ${XTOSKRNL_SOURCE_DIR}/rtl/math.cc ${XTOSKRNL_SOURCE_DIR}/rtl/memory.cc diff --git a/xtoskrnl/includes/rtl.hh b/xtoskrnl/includes/rtl.hh index 939ee8c..8dae02d 100644 --- a/xtoskrnl/includes/rtl.hh +++ b/xtoskrnl/includes/rtl.hh @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/xtoskrnl/includes/rtl/lifo.hh b/xtoskrnl/includes/rtl/lifo.hh new file mode 100644 index 0000000..35a4740 --- /dev/null +++ b/xtoskrnl/includes/rtl/lifo.hh @@ -0,0 +1,31 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/rtl/lifo.hh + * DESCRIPTION: Last In First Out (LIFO) queue implementation + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_RTL_LIFO_HH +#define __XTOSKRNL_RTL_LIFO_HH + +#include + + +/* Runtime Library */ +namespace RTL +{ + class LifoQueue + { + public: + STATIC XTFASTCALL BOOLEAN EmptyList(IN PSINGLE_LIST_ENTRY ListHead); + STATIC XTFASTCALL PSINGLE_LIST_ENTRY PeekEntryList(IN PSINGLE_LIST_ENTRY ListHead); + STATIC XTFASTCALL PSINGLE_LIST_ENTRY PopEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead); + STATIC XTFASTCALL VOID PushEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead, + IN PSINGLE_LIST_ENTRY Entry); + STATIC XTFASTCALL BOOLEAN SearchEntryList(IN PSINGLE_LIST_ENTRY ListHead, + IN PSINGLE_LIST_ENTRY Entry); + }; +} + +#endif /* __XTOSKRNL_RTL_LIFO_HH */ diff --git a/xtoskrnl/rtl/lifo.cc b/xtoskrnl/rtl/lifo.cc new file mode 100644 index 0000000..7742a3c --- /dev/null +++ b/xtoskrnl/rtl/lifo.cc @@ -0,0 +1,140 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/rtl/lifo.cc + * DESCRIPTION: Last In First Out (LIFO) queue implementation + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Evaluates whether the LIFO queue is completely empty. + * + * @param ListHead + * Supplies a pointer to the head of the LIFO queue. + * + * @return This routine returns TRUE if the queue is empty, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTFASTCALL +BOOLEAN +RTL::LifoQueue::EmptyList(IN PSINGLE_LIST_ENTRY ListHead) +{ + /* Return the queue status */ + return (ListHead->Next == NULLPTR); +} + +/** + * Retrieves the first entry from the LIFO queue without removing it. + * + * @param ListHead + * Supplies a pointer to the head of the LIFO queue. + * + * @return This routine returns a pointer to the first entry, or NULLPTR if empty. + * + * @since XT 1.0 + */ +XTFASTCALL +PSINGLE_LIST_ENTRY +RTL::LifoQueue::PeekEntryList(IN PSINGLE_LIST_ENTRY ListHead) +{ + /* Return the entry at the top of the queue */ + return ListHead->Next; +} + +/** + * Removes and returns the entry at the top of the LIFO queue. + * + * @param ListHead + * Supplies a pointer to the head of the LIFO queue. + * + * @return This routine returns a pointer to the removed entry, or NULLPTR if empty. + * + * @since XT 1.0 + */ +XTFASTCALL +PSINGLE_LIST_ENTRY +RTL::LifoQueue::PopEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead) +{ + PSINGLE_LIST_ENTRY Entry; + + /* Capture the entry currently at the top of the queue */ + Entry = ListHead->Next; + + /* Check if the queue is not empty */ + if(Entry) + { + /* Unlink the first entry */ + ListHead->Next = Entry->Next; + } + + /* Return the captured entry */ + return Entry; +} + +/** + * Pushes an entry onto the top of the LIFO queue. + * + * @param ListHead + * Supplies a pointer to the head of the LIFO queue. + * + * @param Entry + * Supplies a pointer to the entry to be pushed onto the queue. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTFASTCALL +VOID +RTL::LifoQueue::PushEntryList(IN OUT PSINGLE_LIST_ENTRY ListHead, + IN PSINGLE_LIST_ENTRY Entry) +{ + /* Link the new entry and update queue head */ + Entry->Next = ListHead->Next; + ListHead->Next = Entry; +} + +/** + * Searches the LIFO queue to determine if a specific entry is present. + * + * @param ListHead + * Supplies a pointer to the head of the LIFO queue. + * + * @param Entry + * Supplies a pointer to the entry being searched for. + * + * @return This routine returns TRUE if the entry is found, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTFASTCALL +BOOLEAN +RTL::LifoQueue::SearchEntryList(IN PSINGLE_LIST_ENTRY ListHead, + IN PSINGLE_LIST_ENTRY Entry) +{ + PSINGLE_LIST_ENTRY CurrentEntry; + + /* Start traversing from the first entry in the queue */ + CurrentEntry = ListHead->Next; + + /* Iterate through the linked list until the end is reached */ + while(CurrentEntry != NULLPTR) + { + /* Check if the current node matches the target entry */ + if(CurrentEntry == Entry) + { + /* Entry found within the queue, return TRUE */ + return TRUE; + } + + /* Move to the next entry in the chain */ + CurrentEntry = CurrentEntry->Next; + } + + /* Target entry not found, return FALSE */ + return FALSE; +}