[svn:parrot] r35653 - trunk/src/pmc

[email protected]
Newsgroups perl.cvs.parrot
Message-ID <[email protected]>
Author: cotto
Date: Fri Jan 16 15:00:26 2009
New Revision: 35653

Modified:
   trunk/src/pmc/tqueue.pmc

Log:
[pmc] convert unionval to ATTRs in TQueue


Modified: trunk/src/pmc/tqueue.pmc
==============================================================================
--- trunk/src/pmc/tqueue.pmc	(original)
+++ trunk/src/pmc/tqueue.pmc	Fri Jan 16 15:00:26 2009
@@ -33,6 +33,8 @@
 #include "parrot/parrot.h"
 
 pmclass TQueue need_ext is_shared {
+    ATTR struct QUEUE *queue;
+    ATTR INTVAL        thread_count;
 
 /*
 
@@ -45,8 +47,13 @@
 */
 
     VTABLE void init() {
-        PMC_int_val(SELF) = 0;
-        PMC_data(SELF)    = queue_init(0);
+        Parrot_TQueue_attributes* attrs =
+            mem_allocate_zeroed_typed(Parrot_TQueue_attributes);
+
+        attrs->thread_count = 0;
+        attrs->queue        = queue_init(0);
+        PMC_data(SELF)      = attrs;
+
         PObj_custom_mark_destroy_SETALL(SELF);
     }
 
@@ -76,9 +83,11 @@
 */
 
     VTABLE void mark() {
-        QUEUE       *queue = PMC_data_typed(SELF, QUEUE *);
+        QUEUE       *queue;
         QUEUE_ENTRY *entry;
 
+        GET_ATTR_queue(INTERP, SELF, queue);
+
         queue_lock(queue);
         entry = queue->head;
 
@@ -105,8 +114,10 @@
 */
 
     VTABLE void destroy() {
-        if (PMC_data(SELF)) {
-            QUEUE * const queue = PMC_data_typed(SELF, QUEUE *);
+        QUEUE *queue;
+        GET_ATTR_queue(INTERP, SELF, queue);
+
+        if (queue) {
 #if 0
             /*
              * wait til queue is empty
@@ -120,8 +131,8 @@
             }
 #endif
             mem_sys_free(queue);
-            PMC_data(SELF) = NULL;
         }
+        mem_sys_free(PMC_data(SELF));
     }
 
 /*
@@ -147,7 +158,10 @@
 */
 
     VTABLE INTVAL get_integer() {
-        return PMC_int_val(SELF);
+
+        INTVAL thread_count;
+        GET_ATTR_thread_count(INTERP, SELF, thread_count);
+        return thread_count;
     }
 
 /*
@@ -176,7 +190,10 @@
 
     void push_pmc(PMC *item) {
         QUEUE_ENTRY * const entry = mem_allocate_typed(QUEUE_ENTRY);
-        QUEUE       * const queue = PMC_data_typed(SELF, QUEUE *);
+        QUEUE       *       queue;
+        INTVAL       thread_count;
+
+        GET_ATTR_queue(INTERP, SELF, queue);
 
         /*
          * if item isn't shared nor const, then make
@@ -193,7 +210,10 @@
 
         /* s. tsq.c:queue_push */
         queue_lock(queue);
-        ++PMC_int_val(SELF);
+        
+        GET_ATTR_thread_count(INTERP, SELF, thread_count);
+        ++thread_count;
+        SET_ATTR_thread_count(INTERP, SELF, thread_count);
 
         /* Is there something in the queue? */
         if (queue->tail) {
@@ -221,10 +241,12 @@
 */
 
     VTABLE PMC *shift_pmc() {
-        QUEUE       * const queue = PMC_data_typed(SELF, QUEUE *);
+        QUEUE       *queue;
         QUEUE_ENTRY *entry;
         PMC         *ret;
+        INTVAL       thread_count;
 
+        GET_ATTR_queue(INTERP, SELF, queue);
         queue_lock(queue);
 
         while (queue->head == NULL) {
@@ -232,7 +254,9 @@
         }
 
         entry = nosync_pop_entry(queue);
-        --PMC_int_val(SELF);
+        GET_ATTR_thread_count(INTERP, SELF, thread_count);
+        --thread_count;
+        SET_ATTR_thread_count(INTERP, SELF, thread_count);
 
         queue_unlock(queue);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.