Index: src/pmc/tqueue.pmc =================================================================== --- src/pmc/tqueue.pmc (.../trunk) (revision 37010) +++ src/pmc/tqueue.pmc (.../branches/deprecate_tqueue) (revision 37012) @@ -1,283 +0,0 @@ -/* -Copyright (C) 2001-2008, Parrot Foundation. -$Id$ - -=head1 NAME - -src/pmc/tqueue.pmc - Threadsafe Queue - -=head1 DESCRIPTION - -Threadsafe queue class for inter thread communication. If you have an -unthreaded program then please use an Array-like PMC. - - new P0, 'TQueue' - push P0, some - new P2, 'ParrotThread' - ... - -and in other thread (at least, when shared PMCs work :) - - shift P1, P0 - -Note: The TQueue must always be emptied before program exit. - -=head2 Methods - -=over 4 - -=cut - -*/ - -#include "parrot/parrot.h" - -pmclass TQueue need_ext is_shared { - ATTR struct QUEUE *queue; - ATTR INTVAL thread_count; - -/* - -=item C - -Initializes the queue. - -=cut - -*/ - - VTABLE void init() { - 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); - } - -/* - -=item C - -Returns the queue itself. No copy is made. - -=cut - -*/ - - VTABLE PMC *clone() { - /* XXX fake a shared PMC */ - return SELF; - } - -/* - -=item C - -Marks all the threads in the queue as live. - -=cut - -*/ - - VTABLE void mark() { - QUEUE *queue; - QUEUE_ENTRY *entry; - - GET_ATTR_queue(INTERP, SELF, queue); - - queue_lock(queue); - entry = queue->head; - - while (entry) { - pobject_lives(INTERP, (PObj *)entry->data); - - if (entry == queue->tail) - break; - - entry = entry->next; - } - - queue_unlock(queue); - } - -/* - -=item C - -Destroys the queue. - -=cut - -*/ - - VTABLE void destroy() { - QUEUE *queue; - GET_ATTR_queue(INTERP, SELF, queue); - - if (queue) { -#if 0 - /* - * wait til queue is empty - * XXX implement a time wait and PANIC if queue - * isn't empty after some TIMEOUT - */ - while (SELF.elements()) { - queue_lock(queue); - queue_wait(queue); - queue_unlock(queue); - } -#endif - mem_sys_free(queue); - } - mem_sys_free(PMC_data(SELF)); - } - -/* - -=item C - -Returns whether there are any threads in the queue. - -=cut - -*/ - - VTABLE INTVAL defined() { - return SELF.get_integer() != 0; - } - -/* - -=item C - -=cut - -*/ - - VTABLE INTVAL get_integer() { - - INTVAL thread_count; - GET_ATTR_thread_count(INTERP, SELF, thread_count); - return thread_count; - } - -/* - -=item C - -Returns the number of threads in the queue. - -=cut - -*/ - - VTABLE INTVAL elements() { - return SELF.get_integer(); - } - -/* - -=item C - -Adds the thread C<*item> to the end of the queue. - -=cut - -*/ - - void push_pmc(PMC *item) { - QUEUE_ENTRY * const entry = mem_allocate_typed(QUEUE_ENTRY); - QUEUE * queue; - INTVAL thread_count; - - GET_ATTR_queue(INTERP, SELF, queue); - - /* - * if item isn't shared nor const, then make - * a shared item - */ - if (!(item->vtable->flags & - (VTABLE_IS_CONST_FLAG | VTABLE_IS_SHARED_FLAG))) - VTABLE_share(INTERP, item); - - GC_WRITE_BARRIER(INTERP, SELF, NULL, item); - - entry->data = item; - entry->type = QUEUE_ENTRY_TYPE_NONE; - - /* s. tsq.c:queue_push */ - queue_lock(queue); - - 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) { - queue->tail->next = entry; - queue->tail = entry; - } - else { - queue->head = entry; - queue->tail = entry; - } - - /* signal all waiters */ - queue_broadcast(queue); - queue_unlock(queue); - } - -/* - -=item C - -Removes the first thread from the start of the queue. - -=cut - -*/ - - VTABLE PMC *shift_pmc() { - QUEUE *queue; - QUEUE_ENTRY *entry; - PMC *ret; - INTVAL thread_count; - - GET_ATTR_queue(INTERP, SELF, queue); - queue_lock(queue); - - while (queue->head == NULL) { - queue_wait(queue); - } - - entry = nosync_pop_entry(queue); - GET_ATTR_thread_count(INTERP, SELF, thread_count); - --thread_count; - SET_ATTR_thread_count(INTERP, SELF, thread_count); - - queue_unlock(queue); - - ret = (PMC *)entry->data; - mem_sys_free(entry); - - return ret; - } -} - -/* - -=back - -=cut - -*/ - -/* - * Local variables: - * c-file-style: "parrot" - * End: - * vim: expandtab shiftwidth=4: - */ Index: src/pmc/pmc.num =================================================================== --- src/pmc/pmc.num (.../trunk) (revision 37010) +++ src/pmc/pmc.num (.../branches/deprecate_tqueue) (revision 37012) @@ -75,10 +75,8 @@ # other -tqueue.pmc 50 +parrotclass.pmc 50 +parrotobject.pmc 51 -parrotclass.pmc 51 -parrotobject.pmc 52 - -os.pmc 53 -file.pmc 54 +os.pmc 52 +file.pmc 53 Index: MANIFEST =================================================================== --- MANIFEST (.../trunk) (revision 37010) +++ MANIFEST (.../branches/deprecate_tqueue) (revision 37012) @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Wed Feb 25 17:00:32 2009 UT +# generated by tools/dev/mk_manifest_and_skip.pl Thu Feb 26 01:36:56 2009 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -717,7 +717,6 @@ examples/pir/readline.pir [examples] examples/pir/substr.pir [examples] examples/pir/sudoku.pir [examples] -examples/pir/thr-primes.pir [examples] examples/pir/uniq.pir [examples] examples/sdl/anim_image.pir [examples] examples/sdl/anim_image_dblbuf.pir [examples] @@ -2322,7 +2321,6 @@ src/pmc/sub.pmc [devel]src src/pmc/task.pmc [devel]src src/pmc/timer.pmc [devel]src -src/pmc/tqueue.pmc [devel]src src/pmc/undef.pmc [devel]src src/pmc/unmanagedstruct.pmc [devel]src src/pmc_freeze.c [] @@ -2770,7 +2768,6 @@ t/pmc/task.t [test] t/pmc/threads.t [test] t/pmc/timer.t [test] -t/pmc/tqueue.t [test] t/pmc/undef.t [test] t/pmc/unmanagedstruct.t [test] t/postconfigure/01-options.t [test] Index: editor/pir-mode.el =================================================================== --- editor/pir-mode.el (.../trunk) (revision 37010) +++ editor/pir-mode.el (.../branches/deprecate_tqueue) (revision 37012) @@ -156,7 +156,7 @@ "ParrotRunningThread" "ParrotThread" "Pointer" "Random" "Ref" "ResizableBooleanArray" "ResizableFloatArray" "ResizableIntegerArray" "ResizablePMCArray" "ResizableStringArray" "RetContinuation" - "Role" "Scalar" "SharedRef" "Slice" "String" "Sub" "Super" "TQueue" + "Role" "Scalar" "SharedRef" "Slice" "String" "Sub" "Super" "Timer" "UnManagedStruct" "Undef" "VtableCache")) (defvar pir-ops Index: t/pmc/tqueue.t =================================================================== --- t/pmc/tqueue.t (.../trunk) (revision 37010) +++ t/pmc/tqueue.t (.../branches/deprecate_tqueue) (revision 37012) @@ -1,61 +0,0 @@ -#! parrot -# Copyright (C) 2001-2005, Parrot Foundation. -# $Id$ - -=head1 NAME - -t/pmc/tqueue.t - Thread Queue - -=head1 SYNOPSIS - - % prove t/pmc/tqueue.t - -=head1 DESCRIPTION - -Tests the thread queue. - -=cut - -.sub main :main - .include "include/test_more.pir" - plan(5) - thread_safe_queue_tests() -.end - -.sub thread_safe_queue_tests - .local int i, is_ok - .local pmc tq, pInt - - new tq, ['TQueue'] - ok(1, "didn't crash") - - i = tq - is_ok = i == 0 - ok(is_ok, "int assignment gets # of elements in empty queue") - - pInt = new ['Integer'] - pInt = 2 - push tq, pInt - pInt = new ['Integer'] - pInt = 3 - push tq, pInt - i = tq - is_ok = i == 2 - ok(is_ok, "int assignment gets # of elements in non-empty queue") - - shift pInt, tq - i = pInt - is_ok = i == 2 - ok(is_ok, "int retrieval works") - shift pInt, tq - i = pInt - is_ok = i == 3 - ok(is_ok, "int retrieval works") -.end - -# Local Variables: -# mode: pir -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4 ft=pir: Index: t/pmc/threads.t =================================================================== --- t/pmc/threads.t (.../trunk) (revision 37010) +++ t/pmc/threads.t (.../branches/deprecate_tqueue) (revision 37012) @@ -46,7 +46,7 @@ } } if ( $platforms{$^O} ) { - plan tests => 20; + plan tests => 15; } else { plan skip_all => "No threading yet or test not enabled for '$^O'"; @@ -288,36 +288,6 @@ 500500 OUTPUT - -pir_output_like( <<'CODE', <<'OUTPUT', "detach" ); -.sub main :main - .local pmc foo - .local pmc queue - .local pmc thread - foo = get_global '_foo' - queue = new ['TQueue'] # flag for when the thread is done - thread = new ['ParrotThread'] - thread.'run_clone'(foo, queue) - - thread.'detach'() -wait: - defined $I0, queue - if $I0 == 0 goto wait - print "done\n" -.end - -.sub _foo - .param pmc queue - print "thread\n" - sleep 0.1 - $P1 = new ['Integer'] - push queue, $P1 -.end -CODE -/(done\nthread\n)|(thread\ndone\n)/ -OUTPUT - - pir_output_is( <<'CODE', <<'OUTPUT', "share a PMC" ); .sub main :main .local pmc foo @@ -354,54 +324,6 @@ 21 OUTPUT -pir_output_is( <<'CODE', <<'OUT', "multi-threaded" ); -.sub main :main - .local pmc queue - queue = new ['TQueue'] - .local pmc tmpInt - tmpInt = new ['Integer'] - tmpInt = 1 - push queue, tmpInt - tmpInt = new ['Integer'] - tmpInt = 2 - push queue, tmpInt - tmpInt = new ['Integer'] - tmpInt = 3 - push queue, tmpInt - - .local pmc thread - thread = new ['ParrotThread'] - .local pmc foo - foo = get_global '_foo' - thread.'run_clone'(foo, queue) - thread.'join'() - print "done main\n" -.end - -.sub _foo - .param pmc queue - $I0 = queue - print $I0 - print "\n" -loop: - $I0 = queue - if $I0 == 0 goto done - shift $P0, queue - print $P0 - print "\n" - branch loop -done: - print "done thread\n" -.end -CODE -3 -1 -2 -3 -done thread -done main -OUT - pir_output_is( <<'CODE', <<'OUT', "sub name lookup in new thread" ); .sub check $P0 = get_global ['Foo'], 'foo' @@ -1016,135 +938,6 @@ 42 OUTPUT -pir_output_is( <<'CODE', <<'OUT', 'multi-threaded strings via SharedRef' ); -.sub main :main - .local pmc queue - .local pmc tmp_string - .local pmc shared_ref - - queue = new ['TQueue'] - tmp_string = new ['String'] - tmp_string = "ok 1\n" - shared_ref = new ['SharedRef'], tmp_string - push queue, shared_ref - tmp_string = new ['String'] - tmp_string = "ok 2\n" - shared_ref = new ['SharedRef'], tmp_string - push queue, shared_ref - tmp_string = new ['String'] - tmp_string = "ok 3\n" - shared_ref = new ['SharedRef'], tmp_string - push queue, shared_ref - - .local pmc thread - .local pmc foo - - thread = new ['ParrotThread'] - foo = get_global '_foo' - thread.'run_clone'(foo, queue) - thread.'join'() - print "done main\n" -.end - -.sub _foo - .param pmc queue - $I0 = queue - print $I0 - print "\n" -loop: - $I0 = queue - if $I0 == 0 goto done - shift $P0, queue - print $P0 - branch loop -done: - print "done thread\n" -.end -CODE -3 -ok 1 -ok 2 -ok 3 -done thread -done main -OUT - -SKIP: { - skip( "no shared Strings yet", 2 ); - pasm_output_is( <<'CODE', <<'OUT', "thread safe queue strings 1" ); - new P10, ['TQueue'] - print "ok 1\n" - set I0, P10 - print I0 - print "\n" - new P7, ['String'] - set P7, "ok 2\n" - push P10, P7 - new P7, ['String'] - set P7, "ok 3\n" - push P10, P7 - set I0, P10 - print I0 - print "\n" - - shift P8, P10 - print P8 - shift P8, P10 - print P8 - end -CODE -ok 1 -0 -2 -ok 2 -ok 3 -OUT - - pasm_output_is( <<'CODE', <<'OUT', "multi-threaded strings" ); - new P10, ['TQueue'] - new P7, ['String'] - set P7, "ok 1\n" - push P10, P7 - new P7, ['String'] - set P7, "ok 2\n" - push P10, P7 - new P7, ['String'] - set P7, "ok 3\n" - push P10, P7 - set P6, P10 - - get_global P5, "_foo" - new P2, ['ParrotThread'] - callmethod "thread3" - set I5, P2 - getinterp P2 - callmethod "join" - print "done main\n" - end - -.pcc_sub _foo: - set I0, P6 - print I0 - print "\n" -loop: - set I0, P6 - unless I0, ex - shift P8, P6 - print P8 - branch loop -ex: - print "done thread\n" - returncc -CODE -3 -ok 1 -ok 2 -ok 3 -done thread -done main -OUT -} - # Local Variables: # mode: cperl # cperl-indent-level: 4 Index: t/steps/auto_pmc-01.t =================================================================== --- t/steps/auto_pmc-01.t (.../trunk) (revision 37010) +++ t/steps/auto_pmc-01.t (.../branches/deprecate_tqueue) (revision 37012) @@ -184,7 +184,6 @@ fixedstringarray.pmc hash.pmc orderedhash.pmc - tqueue.pmc os.pmc file.pmc addrregistry.pmc Index: t/op/gc.t =================================================================== --- t/op/gc.t (.../trunk) (revision 37010) +++ t/op/gc.t (.../branches/deprecate_tqueue) (revision 37012) @@ -6,7 +6,7 @@ use warnings; use lib qw( . lib ../lib ../../lib ); use Test::More; -use Parrot::Test tests => 20; +use Parrot::Test tests => 19; =head1 NAME @@ -474,72 +474,6 @@ ok OUTPUT -pasm_output_is( <<'CODE', <: - - 1 #!/usr/bin/perl -w - 2 # prime-pthread, courtesy of Tom Christiansen - 3 - 4 use strict; - 5 - 6 use threads; - 7 use Thread::Queue; - 8 - 9 my $stream = new Thread::Queue; - 10 my $kid = new threads(\&check_num, $stream, 2); - 11 - 12 for my $i ( 3 .. 1000 ) { - 13 $stream->enqueue($i); - 14 } - 15 - 16 $stream->enqueue(undef); - 17 $kid->join; - 18 - 19 sub check_num { - 20 my ($upstream, $cur_prime) = @_; - 21 my $kid; - 22 my $downstream = new Thread::Queue; - 23 while (my $num = $upstream->dequeue) { - 24 next unless $num % $cur_prime; - 25 if ($kid) { - 26 $downstream->enqueue($num); - 27 } else { - 28 print "Found prime $num\n"; - 29 $kid = new threads(\&check_num, $downstream, $num); - 30 } - 31 } - 32 $downstream->enqueue(undef) if $kid; - 33 $kid->join if $kid; - 34 } - -=cut - -# translate to PIR by leo - -# Runs here (i386/linux 256MB mem) w. -# ARENA_GC_FLAGS = 1 MAX=500 (~ 95 threads) -# ARENA_GC_FLAGS = 0 MAX=1000 (~ 168 threads) - - -.sub _main - .param pmc argv - .const int MAX = 500 - .local int max - .local pmc kid - .local pmc Check_num - .local pmc stream - .local int argc - argc = argv - max = MAX - if argc < 2 goto no_arg - $S0 = argv[1] - max = $S0 -no_arg: - - #sweepoff -# 9 my $stream = new Thread::Queue; - stream = new 'TQueue' -# 10 my $kid = new threads(\&check_num, $stream, 2); - Check_num = get_global "_check_num" - kid = new 'ParrotThread' - $P2 = new 'Integer' - $P2 = 2 - kid.'run_clone'(Check_num, Check_num, stream, $P2) - -# 12 for my $i ( 3 .. 1000 ) { - .local int i - i = 3 -lp: -# 13 $stream->enqueue($i); - $P3 = new 'Integer' - $P3 = i - push stream, $P3 - inc i - if i <= max goto lp -# 14 } - -# 16 $stream->enqueue(undef); - $P4 = new 'Undef' - push stream, $P4 - -# 17 $kid->join; - kid.'join'() -.end - -# 19 sub check_num { -# 20 my ($upstream, $cur_prime) = @_; -# XXX still no comments inside pcc param block -.sub _check_num - .param pmc sub - .param pmc upstream - .param pmc cur_prime - -# 21 my $kid; - .local pmc kid - kid = new 'Undef' -# 22 my $downstream = new Thread::Queue; - .local pmc downstream - downstream = new 'TQueue' -# 23 while (my $num = $upstream->dequeue) { - .local pmc Num # num is a reserved word -lp: - shift Num, upstream - $I0 = defined Num - unless $I0 goto ewhile -# 24 next unless $num % $cur_prime; - $P0 = new 'Integer' - $P0 = Num % cur_prime - unless $P0 goto lp -# 25 if ($kid) { - $I1 = defined kid - unless $I1 goto no_kid1 -# 26 $downstream->enqueue($num); - push downstream, Num - goto lp -# 27 } else { -no_kid1: -# 28 print "Found prime $num\n"; - print "Found prime " - print Num - print "\n" - -# 29 $kid = new threads(\&check_num, $downstream, $num); - kid = new 'ParrotThread' - kid.'run_clone'(sub, sub, downstream, Num) - goto lp -# 31 } -ewhile: - -# 32 $downstream->enqueue(undef) if $kid; - $I1 = defined kid - unless $I1 goto no_kid2 - - $P4 = new 'Undef' - push downstream, $P4 - -# 33 $kid->join if $kid; - kid.'join'() - -no_kid2: -# 34 } - # sleep 1 # turn on for watching memory usage -.end - -# Local Variables: -# mode: pir -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4 ft=pir: