added a stupid implementation of the id management code, which can't leak
authorTony Cook <tony@develop=help.com>
Sat, 8 Jul 2006 03:19:21 +0000 (03:19 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 8 Jul 2006 03:19:21 +0000 (03:19 +0000)
found the leak, fixed it
add leak manual test script to svn

leak.pl [new file with mode: 0644]
queue.c

diff --git a/leak.pl b/leak.pl
new file mode 100644 (file)
index 0000000..72bc782
--- /dev/null
+++ b/leak.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+use POE::XS::Queue::Array;
+my $q = POE::XS::Queue::Array->new;
+# or
+#use POE::Queue::Array;
+#my $q = POE::Queue::Array->new;
+
+print "inital: \n";
+system "ps -o rss -p $$";
+for (1..2000){
+my $id = $q->enqueue($_ % 4, "payload $_");
+$q->dequeue_next;
+}
+system "ps -o rss -p $$";
+for (1..2000){
+my $id = $q->enqueue($_ % 4, "payload $_");
+$q->dequeue_next;
+}
+system "ps -o rss -p $$";
+
diff --git a/queue.c b/queue.c
index 070ff4bc78273c849ca7800c851e0a3ea217a496..3bbc49c0c4eedebe91091e211994da0d47bdcf96 100644 (file)
--- a/queue.c
+++ b/queue.c
@@ -14,7 +14,7 @@
 #define AT_START 0\r
 #define AT_END 1\r
 \r
-pq_id_t queue_seq;\r
+#define STUPID_IDS 0\r
 \r
 /*\r
 We store the queue in a similar way to the way perl deals with arrays,\r
@@ -120,14 +120,33 @@ all that needs to be modified if we change hash implementations.
 static\r
 pq_id_t\r
 pq_new_id(poe_queue *pq, pq_priority_t priority) {\r
-  int seq = ++pq->queue_seq;\r
-  SV *index = newSViv(seq);\r
+#if STUPID_IDS\r
+  int seq;\r
+  int i;\r
+  int found;\r
+  \r
+  do {\r
+    seq = ++pq->queue_seq;\r
+    found = 0;\r
+    for (i = pq->start; i < pq->end; ++i) {\r
+      if (pq->entries[i].id == seq) {\r
+       found = 1;\r
+       break;\r
+      }\r
+    }\r
+  } while (found);\r
+\r
+  return seq;\r
+#else\r
+  int seq = ++pq->queue_seq;;\r
+  SV *index = sv_2mortal(newSViv(seq));\r
 \r
   while (hv_exists_ent(pq->ids, index, 0)) {\r
     seq = ++pq->queue_seq;\r
     sv_setiv(index, seq);\r
   }\r
   hv_store_ent(pq->ids, index, newSVnv(priority), 0);\r
+#endif\r
 \r
   return seq;\r
 }\r
@@ -138,9 +157,12 @@ pq_release_id - releases an id for future use.
 static\r
 void\r
 pq_release_id(poe_queue *pq, pq_id_t id) {\r
+#if STUPID_IDS\r
+#else\r
   SV *id_sv = sv_2mortal(newSViv(id));\r
 \r
   hv_delete_ent(pq->ids, id_sv, 0, 0);\r
+#endif\r
 }\r
 \r
 /*\r
@@ -149,6 +171,18 @@ pq_item_priority - get the priority of an item given it's id
 static\r
 int\r
 pq_item_priority(poe_queue *pq, pq_id_t id, pq_priority_t *priority) {\r
+#if STUPID_IDS\r
+  int i;\r
+\r
+  for (i = pq->start; i < pq->end; ++i) {\r
+    if (pq->entries[i].id == id) {\r
+      *priority = pq->entries[i].priority;\r
+      return 1;\r
+    }\r
+  }\r
+\r
+  return 0;\r
+#else\r
   HE *entry = hv_fetch_ent(pq->ids, sv_2mortal(newSViv(id)), 0, 0);\r
 \r
   if (!entry)\r
@@ -157,6 +191,7 @@ pq_item_priority(poe_queue *pq, pq_id_t id, pq_priority_t *priority) {
   *priority = SvNV(HeVAL(entry));\r
 \r
   return 1;\r
+#endif\r
 }\r
 \r
 /*\r
@@ -165,12 +200,16 @@ pq_set_id_priority - set the priority of an item in the id hash
 static\r
 void\r
 pq_set_id_priority(poe_queue *pq, pq_id_t id, pq_priority_t new_priority) {\r
+#if STUPID_IDS\r
+  /* nothing to do, caller set it in the array */\r
+#else\r
   HE *entry = hv_fetch_ent(pq->ids, sv_2mortal(newSViv(id)), 0, 0);\r
 \r
   if (!entry)\r
     croak("pq_set_priority: id not found");\r
 \r
   sv_setnv(HeVAL(entry), new_priority);\r
+#endif\r
 }\r
 \r
 /*\r