Permalink
Browse files

Doubly-linked list container.

  • Loading branch information...
1 parent 0b6edaa commit b93d2fb2922b2fa53a2fd52db5a1efb21113043b @pdoane committed Jun 4, 2012
Showing with 64 additions and 0 deletions.
  1. +5 −0 kernel/link.c
  2. +51 −0 kernel/link.h
  3. +1 −0 kernel/module.mk
  4. +7 −0 osdev.sln
View
@@ -0,0 +1,5 @@
+// ------------------------------------------------------------------------------------------------
+// link.c
+// ------------------------------------------------------------------------------------------------
+
+#include "link.h"
View
@@ -0,0 +1,51 @@
+// ------------------------------------------------------------------------------------------------
+// link.h
+// ------------------------------------------------------------------------------------------------
+
+#pragma once
+
+#include "types.h"
+
+// ------------------------------------------------------------------------------------------------
+typedef struct Link
+{
+ struct Link* prev;
+ struct Link* next;
+} Link;
+
+// ------------------------------------------------------------------------------------------------
+static inline void link_after(Link* a, Link* x)
+{
+ Link* p = a;
+ Link* n = a->next;
+ n->prev = x;
+ x->next = n;
+ x->prev = p;
+ p->next = x;
+}
+
+// ------------------------------------------------------------------------------------------------
+static inline void link_before(Link* a, Link* x)
+{
+ Link* p = a->prev;
+ Link* n = a;
+ n->prev = x;
+ x->next = n;
+ x->prev = p;
+ p->next = x;
+}
+
+// ------------------------------------------------------------------------------------------------
+static inline void link_remove(Link* a)
+{
+ Link* p = a->prev;
+ Link* n = a->next;
+ n->prev = p;
+ p->next = n;
+ a->next = 0;
+ a->prev = 0;
+}
+
+// ------------------------------------------------------------------------------------------------
+#define link_data(link,T,m) \
+ (T*)((char*)link - (unsigned long)(&(((T*)0)->m)))
View
@@ -15,6 +15,7 @@ KERNEL_SOURCES := \
kernel/ioapic.c \
kernel/ipv4.c \
kernel/keymap.c \
+ kernel/link.c \
kernel/local_apic.c \
kernel/mem_dump.c \
kernel/net.c \
View
@@ -171,6 +171,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "stdlib", "stdlib", "{030391
kernel\types.h = kernel\types.h
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "container", "container", "{C24EBB89-B139-4C30-8C50-CD8DF486149C}"
+ ProjectSection(SolutionItems) = preProject
+ kernel\link.c = kernel\link.c
+ kernel\link.h = kernel\link.h
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -184,5 +190,6 @@ Global
{EC4B8992-44EC-4A6E-80EA-912B53F173B6} = {540847D6-87C3-435D-994A-C12DE71831B0}
{FFFF12C1-5F5D-4FF1-B826-F766CF0BCA47} = {540847D6-87C3-435D-994A-C12DE71831B0}
{030391D5-E8D0-45AB-AEA0-6417655B89BF} = {540847D6-87C3-435D-994A-C12DE71831B0}
+ {C24EBB89-B139-4C30-8C50-CD8DF486149C} = {540847D6-87C3-435D-994A-C12DE71831B0}
EndGlobalSection
EndGlobal

0 comments on commit b93d2fb

Please sign in to comment.