Bläddra i källkod

base: BPending: use SLinkedList instead of LinkedList1

ambrop7 13 år sedan
förälder
incheckning
65f199e4a4
3 ändrade filer med 27 tillägg och 21 borttagningar
  1. 14 17
      base/BPending.c
  2. 9 4
      base/BPending.h
  3. 4 0
      base/BPending_list.h

+ 14 - 17
base/BPending.c

@@ -34,10 +34,13 @@
 
 
 #include "BPending.h"
 #include "BPending.h"
 
 
+#include "BPending_list.h"
+#include <structure/SLinkedList_impl.h>
+
 void BPendingGroup_Init (BPendingGroup *g)
 void BPendingGroup_Init (BPendingGroup *g)
 {
 {
     // init jobs list
     // init jobs list
-    LinkedList1_Init(&g->jobs);
+    BPending__List_Init(&g->jobs);
     
     
     // init pending counter
     // init pending counter
     DebugCounter_Init(&g->pending_ctr);
     DebugCounter_Init(&g->pending_ctr);
@@ -49,7 +52,7 @@ void BPendingGroup_Init (BPendingGroup *g)
 void BPendingGroup_Free (BPendingGroup *g)
 void BPendingGroup_Free (BPendingGroup *g)
 {
 {
     DebugCounter_Free(&g->pending_ctr);
     DebugCounter_Free(&g->pending_ctr);
-    ASSERT(LinkedList1_IsEmpty(&g->jobs))
+    ASSERT(BPending__List_IsEmpty(&g->jobs))
     DebugObject_Free(&g->d_obj);
     DebugObject_Free(&g->d_obj);
 }
 }
 
 
@@ -57,21 +60,20 @@ int BPendingGroup_HasJobs (BPendingGroup *g)
 {
 {
     DebugObject_Access(&g->d_obj);
     DebugObject_Access(&g->d_obj);
     
     
-    return !LinkedList1_IsEmpty(&g->jobs);
+    return !BPending__List_IsEmpty(&g->jobs);
 }
 }
 
 
 void BPendingGroup_ExecuteJob (BPendingGroup *g)
 void BPendingGroup_ExecuteJob (BPendingGroup *g)
 {
 {
-    ASSERT(!LinkedList1_IsEmpty(&g->jobs))
+    ASSERT(!BPending__List_IsEmpty(&g->jobs))
     DebugObject_Access(&g->d_obj);
     DebugObject_Access(&g->d_obj);
     
     
     // get a job
     // get a job
-    LinkedList1Node *node = LinkedList1_GetLast(&g->jobs);
-    BPending *p = UPPER_OBJECT(node, BPending, pending_node);
+    BPending *p = BPending__List_First(&g->jobs);
     ASSERT(p->pending)
     ASSERT(p->pending)
     
     
     // remove from jobs list
     // remove from jobs list
-    LinkedList1_Remove(&g->jobs, &p->pending_node);
+    BPending__List_Remove(&g->jobs, p);
     
     
     // set not pending
     // set not pending
     p->pending = 0;
     p->pending = 0;
@@ -85,12 +87,7 @@ BPending * BPendingGroup_PeekJob (BPendingGroup *g)
 {
 {
     DebugObject_Access(&g->d_obj);
     DebugObject_Access(&g->d_obj);
     
     
-    LinkedList1Node *node = LinkedList1_GetLast(&g->jobs);
-    if (!node) {
-        return NULL;
-    }
-    
-    return UPPER_OBJECT(node, BPending, pending_node);
+    return BPending__List_First(&g->jobs);
 }
 }
 
 
 void BPending_Init (BPending *o, BPendingGroup *g, BPending_handler handler, void *user)
 void BPending_Init (BPending *o, BPendingGroup *g, BPending_handler handler, void *user)
@@ -117,7 +114,7 @@ void BPending_Free (BPending *o)
     
     
     // remove from jobs list
     // remove from jobs list
     if (o->pending) {
     if (o->pending) {
-        LinkedList1_Remove(&o->g->jobs, &o->pending_node);
+        BPending__List_Remove(&o->g->jobs, o);
     }
     }
 }
 }
 
 
@@ -127,11 +124,11 @@ void BPending_Set (BPending *o)
     
     
     // remove from jobs list
     // remove from jobs list
     if (o->pending) {
     if (o->pending) {
-        LinkedList1_Remove(&o->g->jobs, &o->pending_node);
+        BPending__List_Remove(&o->g->jobs, o);
     }
     }
     
     
     // insert to jobs list
     // insert to jobs list
-    LinkedList1_Append(&o->g->jobs, &o->pending_node);
+    BPending__List_Prepend(&o->g->jobs, o);
     
     
     // set pending
     // set pending
     o->pending = 1;
     o->pending = 1;
@@ -143,7 +140,7 @@ void BPending_Unset (BPending *o)
     
     
     if (o->pending) {
     if (o->pending) {
         // remove from jobs list
         // remove from jobs list
-        LinkedList1_Remove(&o->g->jobs, &o->pending_node);
+        BPending__List_Remove(&o->g->jobs, o);
         
         
         // set not pending
         // set not pending
         o->pending = 0;
         o->pending = 0;

+ 9 - 4
base/BPending.h

@@ -37,9 +37,14 @@
 #include <stdint.h>
 #include <stdint.h>
 
 
 #include <misc/debugcounter.h>
 #include <misc/debugcounter.h>
-#include <structure/LinkedList1.h>
+#include <structure/SLinkedList.h>
 #include <base/DebugObject.h>
 #include <base/DebugObject.h>
 
 
+struct BPending_s;
+
+#include "BPending_list.h"
+#include <structure/SLinkedList_decl.h>
+
 /**
 /**
  * Job execution handler.
  * Job execution handler.
  * It is guaranteed that the associated {@link BPending} object was
  * It is guaranteed that the associated {@link BPending} object was
@@ -55,7 +60,7 @@ typedef void (*BPending_handler) (void *user);
  * Object that contains a list of jobs pending execution.
  * Object that contains a list of jobs pending execution.
  */
  */
 typedef struct {
 typedef struct {
-    LinkedList1 jobs;
+    BPending__List jobs;
     DebugCounter pending_ctr;
     DebugCounter pending_ctr;
     DebugObject d_obj;
     DebugObject d_obj;
 } BPendingGroup;
 } BPendingGroup;
@@ -63,12 +68,12 @@ typedef struct {
 /**
 /**
  * Object for queuing a job for execution.
  * Object for queuing a job for execution.
  */
  */
-typedef struct {
+typedef struct BPending_s {
     BPendingGroup *g;
     BPendingGroup *g;
     BPending_handler handler;
     BPending_handler handler;
     void *user;
     void *user;
     uint8_t pending;
     uint8_t pending;
-    LinkedList1Node pending_node;
+    BPending__ListNode pending_node;
     DebugObject d_obj;
     DebugObject d_obj;
 } BPending;
 } BPending;
 
 

+ 4 - 0
base/BPending_list.h

@@ -0,0 +1,4 @@
+#define SLINKEDLIST_PARAM_NAME BPending__List
+#define SLINKEDLIST_PARAM_FEATURE_LAST 0
+#define SLINKEDLIST_PARAM_TYPE_ENTRY struct BPending_s
+#define SLINKEDLIST_PARAM_MEMBER_NODE pending_node