[svn:parrot] r48440 - in branches/gsoc_threads: include/parrot src src/interp src/pmc t/src
Chandon at svn.parrot.org
Chandon at svn.parrot.org
Thu Aug 12 21:30:21 UTC 2010
Author: Chandon
Date: Thu Aug 12 21:30:20 2010
New Revision: 48440
URL: https://trac.parrot.org/parrot/changeset/48440
Log:
[gsoc_threads] Now with passing tests.
Modified:
branches/gsoc_threads/include/parrot/interpreter.h
branches/gsoc_threads/include/parrot/thr_pthread.h
branches/gsoc_threads/include/parrot/thread.h
branches/gsoc_threads/include/parrot/threads.h
branches/gsoc_threads/src/alarm.c
branches/gsoc_threads/src/exit.c
branches/gsoc_threads/src/interp/inter_create.c
branches/gsoc_threads/src/pmc/sub.pmc
branches/gsoc_threads/src/threads.c
branches/gsoc_threads/t/src/threads_io.t
Modified: branches/gsoc_threads/include/parrot/interpreter.h
==============================================================================
--- branches/gsoc_threads/include/parrot/interpreter.h Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/include/parrot/interpreter.h Thu Aug 12 21:30:20 2010 (r48440)
@@ -394,9 +394,7 @@
void Parrot_destroy(PARROT_INTERP)
__attribute__nonnull__(1);
-void Parrot_really_destroy(PARROT_INTERP,
- NULLOK(int exit_code),
- SHIM(void *arg))
+void Parrot_really_destroy(PARROT_INTERP, int exit_code, SHIM(void *arg))
__attribute__nonnull__(1);
#define ASSERT_ARGS_allocate_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
Modified: branches/gsoc_threads/include/parrot/thr_pthread.h
==============================================================================
--- branches/gsoc_threads/include/parrot/thr_pthread.h Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/include/parrot/thr_pthread.h Thu Aug 12 21:30:20 2010 (r48440)
@@ -58,6 +58,8 @@
# define CLEANUP_PUSH(f, a) pthread_cleanup_push((f), (a))
# define CLEANUP_POP(a) pthread_cleanup_pop(a)
+# define THREAD_EXIT(s) pthread_exit((void*) (s))
+
typedef pthread_mutex_t Parrot_mutex;
typedef pthread_cond_t Parrot_cond;
typedef pthread_t Parrot_thread;
Modified: branches/gsoc_threads/include/parrot/thread.h
==============================================================================
--- branches/gsoc_threads/include/parrot/thread.h Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/include/parrot/thread.h Thu Aug 12 21:30:20 2010 (r48440)
@@ -40,6 +40,8 @@
# define CLEANUP_PUSH(f, a)
# define CLEANUP_POP(a)
+# define THREAD_EXIT(s) exit(s)
+
# define Parrot_mutex int
# define Parrot_cond int
# define Parrot_thread int
Modified: branches/gsoc_threads/include/parrot/threads.h
==============================================================================
--- branches/gsoc_threads/include/parrot/threads.h Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/include/parrot/threads.h Thu Aug 12 21:30:20 2010 (r48440)
@@ -72,6 +72,9 @@
INTVAL Parrot_threads_check_and_reset(PARROT_INTERP)
__attribute__nonnull__(1);
+void Parrot_threads_cleanup(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
INTVAL Parrot_threads_count_active(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -117,6 +120,8 @@
#define ASSERT_ARGS_Parrot_threads_check_and_reset \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_threads_cleanup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_threads_count_active __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_threads_current __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Modified: branches/gsoc_threads/src/alarm.c
==============================================================================
--- branches/gsoc_threads/src/alarm.c Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/src/alarm.c Thu Aug 12 21:30:20 2010 (r48440)
@@ -56,6 +56,7 @@
ASSERT_ARGS(Parrot_alarm_init)
struct sigaction sa;
+ memset(&sa, 0, sizeof (struct sigaction));
sa.sa_handler = Parrot_alarm_callback;
sa.sa_flags = SA_RESTART;
@@ -124,6 +125,7 @@
{
ASSERT_ARGS(Parrot_alarm_mask)
sigset_t mask;
+ sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
pthread_sigmask(SIG_BLOCK, &mask, 0);
}
@@ -133,6 +135,7 @@
{
ASSERT_ARGS(Parrot_alarm_unmask)
sigset_t mask;
+ sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
pthread_sigmask(SIG_UNBLOCK, &mask, 0);
}
Modified: branches/gsoc_threads/src/exit.c
==============================================================================
--- branches/gsoc_threads/src/exit.c Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/src/exit.c Thu Aug 12 21:30:20 2010 (r48440)
@@ -80,7 +80,14 @@
* and: interp->exit_handler_list is gone, after the last exit handler
* (Parrot_really_destroy) has run
*/
- handler_node_t *node = interp->exit_handler_list;
+ handler_node_t *node;
+
+ INTVAL tidx = Parrot_threads_current(interp);
+ if (tidx != 0) {
+ exit(status);
+ }
+
+ node = interp->exit_handler_list;
Parrot_block_GC_mark(interp);
Parrot_block_GC_sweep(interp);
Modified: branches/gsoc_threads/src/interp/inter_create.c
==============================================================================
--- branches/gsoc_threads/src/interp/inter_create.c Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/src/interp/inter_create.c Thu Aug 12 21:30:20 2010 (r48440)
@@ -344,21 +344,19 @@
Waits for any threads to complete, then frees all allocated memory, and
closes any open file handles, etc.
-Note that C<exit_code> is ignored.
-
=cut
*/
void
-Parrot_really_destroy(PARROT_INTERP, SHIM(int exit_code), SHIM(void *arg))
+Parrot_really_destroy(PARROT_INTERP, int exit_code, SHIM(void *arg))
{
ASSERT_ARGS(Parrot_really_destroy)
- /* Chandon TODO: Restore this functionality */
- return;
-
/* wait for threads to complete if needed; terminate the event loop */
+ Parrot_threads_reap(interp);
+ Parrot_threads_cleanup(interp);
+
if (!interp->parent_interpreter) {
Parrot_cx_runloop_end(interp);
pt_join_threads(interp);
Modified: branches/gsoc_threads/src/pmc/sub.pmc
==============================================================================
--- branches/gsoc_threads/src/pmc/sub.pmc Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/src/pmc/sub.pmc Thu Aug 12 21:30:20 2010 (r48440)
@@ -35,7 +35,7 @@
/*
-=item C<void print_sub_name(PARROT_INTERP, PMC *sub)>
+=item C<static void print_sub_name(PARROT_INTERP, PMC *sub)>
=cut
Modified: branches/gsoc_threads/src/threads.c
==============================================================================
--- branches/gsoc_threads/src/threads.c Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/src/threads.c Thu Aug 12 21:30:20 2010 (r48440)
@@ -26,10 +26,9 @@
/*
-=item C<void* Parrot_cx_thread_main(void *interp_ptr)>
+=item C<void Parrot_threads_init(PARROT_INTERP)>
-When an interpreter spawns a new worker thread, that thread starts
-here.
+Initialize the interpreter to support worker threads.
=cut
@@ -67,6 +66,29 @@
/*
+=item C<void Parrot_threads_cleanup(PARROT_INTERP)>
+
+Clean up the threads stuff in this interpreter.
+
+=cut
+
+*/
+
+void
+Parrot_threads_cleanup(PARROT_INTERP)
+{
+ ASSERT_ARGS(Parrot_threads_cleanup)
+
+ Thread_table *tbl = interp->thread_table;
+
+ COND_DESTROY(tbl->threads[0].cvar);
+ free(tbl->threads);
+
+ free(interp->thread_table);
+}
+
+/*
+
=item C<void* Parrot_threads_main(void *args_ptr)>
When an interpreter spawns a new worker thread, that thread starts
@@ -95,6 +117,7 @@
UNLOCK(interp->thread_lock);
Parrot_threads_outer_runloop(interp, tidx);
+
return 0;
}
@@ -362,7 +385,8 @@
if (i < (long)tbl->size / 3) {
/* Shrink that table */
tbl->size /= 2;
- tbl->threads = (Thread_info*) realloc(tbl, sizeof(Thread_info) * tbl->size);
+ tbl->threads = (Thread_info*) realloc(
+ tbl->threads, sizeof(Thread_info) * tbl->size);
}
UNLOCK(interp->thread_lock);
Modified: branches/gsoc_threads/t/src/threads_io.t
==============================================================================
--- branches/gsoc_threads/t/src/threads_io.t Thu Aug 12 19:46:58 2010 (r48439)
+++ branches/gsoc_threads/t/src/threads_io.t Thu Aug 12 21:30:20 2010 (r48440)
@@ -30,7 +30,7 @@
pass
say "ok 2 - main task sleeping"
- sleep 0.2
+ sleep 0.3
say "ok 4 - main task back"
spintask.'kill'()
@@ -57,6 +57,8 @@
$I0 = 0
spin_more:
$I0 = $I0 + 1
+ $I1 = $I0 % 4096
+ if $I1 != 0 goto spin_more
goto spin_more
.end
@@ -66,8 +68,8 @@
open my $run, "|perl ${\$pir->filename} ${\$tmp->filename}";
-sleep(0.1);
+sleep(0.05);
$run->print("grumblecake\n");
-sleep(0.3);
+sleep(0.2);
close($run);
More information about the parrot-commits
mailing list