[svn:parrot] r46169 - in trunk: include/parrot src

tewk at svn.parrot.org tewk at svn.parrot.org
Fri Apr 30 03:48:35 UTC 2010


Author: tewk
Date: Fri Apr 30 03:48:35 2010
New Revision: 46169
URL: https://trac.parrot.org/parrot/changeset/46169

Log:
new thread creation functions

Modified:
   trunk/include/parrot/thread.h
   trunk/src/thread.c

Modified: trunk/include/parrot/thread.h
==============================================================================
--- trunk/include/parrot/thread.h	Fri Apr 30 03:48:28 2010	(r46168)
+++ trunk/include/parrot/thread.h	Fri Apr 30 03:48:35 2010	(r46169)
@@ -201,6 +201,28 @@
 
 void pt_thread_kill(UINTVAL tid);
 void pt_thread_prepare_for_run(Parrot_Interp d, NULLOK(Parrot_Interp s));
+PMC* pt_thread_create(PARROT_INTERP,
+    INTVAL type,
+    INTVAL clone_flags)
+        __attribute__nonnull__(1);
+
+int pt_thread_create_run(PARROT_INTERP,
+    INTVAL type,
+    INTVAL clone_flags,
+    ARGIN(PMC *sub),
+    ARGIN_NULLOK(PMC *arg))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(4)
+        __attribute__nonnull__(5);
+
+int pt_thread_run(PARROT_INTERP,
+    ARGOUT(PMC *thread_interp_pmc),
+    ARGIN(PMC *sub),
+    ARGIN_NULLOK(PMC *arg))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3)
+        FUNC_MODIFIES(*thread_interp_pmc);
 
 void pt_thread_wait_with(PARROT_INTERP, ARGMOD(Parrot_mutex *mutex))
         __attribute__nonnull__(1)
@@ -246,6 +268,16 @@
        PARROT_ASSERT_ARG(parent))
 #define ASSERT_ARGS_pt_thread_kill __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_pt_thread_prepare_for_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_pt_thread_create __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_pt_thread_create_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(sub) \
+    , PARROT_ASSERT_ARG(arg))
+#define ASSERT_ARGS_pt_thread_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(thread_interp_pmc) \
+    , PARROT_ASSERT_ARG(sub))
 #define ASSERT_ARGS_pt_thread_wait_with __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(mutex))

Modified: trunk/src/thread.c
==============================================================================
--- trunk/src/thread.c	Fri Apr 30 03:48:28 2010	(r46168)
+++ trunk/src/thread.c	Fri Apr 30 03:48:35 2010	(r46169)
@@ -703,6 +703,55 @@
     return make_local_copy(d, s, sub);
 }
 
+PMC *
+pt_thread_create(PARROT_INTERP, INTVAL type, INTVAL clone_flags)
+{
+    ASSERT_ARGS(pt_thread_create)
+    PMC *new_interp_pmc = pmc_new(interp, type);
+    Interp *new_interp  = (Interp *)VTABLE_get_pointer(interp, new_interp_pmc);
+
+    clone_interpreter(new_interp, interp, clone_flags);
+    pt_thread_prepare_for_run(new_interp, interp);
+
+    return new_interp_pmc;
+}
+
+int
+pt_thread_run(PARROT_INTERP, PMC *thread_interp_pmc, ARGIN(PMC *sub), ARGIN_NULLOK(PMC *arg))
+{
+    ASSERT_ARGS(pt_thread_run)
+    Interp *thread_interp = (Interp *)VTABLE_get_pointer(interp, thread_interp_pmc);
+
+    SETATTR_ParrotInterpreter_sub(interp, thread_interp_pmc, pt_transfer_sub(thread_interp, interp, sub));
+    VTABLE_set_pmc(interp, thread_interp_pmc, make_local_args_copy(thread_interp, interp, arg));
+    thread_interp->thread_data->state = THREAD_STATE_JOINABLE;
+
+    THREAD_CREATE_JOINABLE(thread_interp->thread_data->thread, thread_func, thread_interp_pmc);
+
+    /* check for pending GC */
+    /*
+     * can't do multi-threaded GC yet
+     * XXX a quick hack to pass the few tests
+
+    LOCK(interpreter_array_mutex);
+    if (interp->thread_data->state & THREAD_STATE_SUSPEND_GC_REQUESTED)
+        pt_suspend_one_for_gc(new_interp);
+    UNLOCK(interpreter_array_mutex);
+
+    */
+
+    return thread_interp->thread_data->tid;
+}
+
+int
+pt_thread_create_run(PARROT_INTERP, INTVAL type, INTVAL clone_flags, ARGIN(PMC *sub), ARGIN_NULLOK(PMC *arg))
+{
+  ASSERT_ARGS(pt_thread_create_run)
+  PMC *thread_interp_pmc = pt_thread_create(interp, type, clone_flags);
+  return pt_thread_run(interp, thread_interp_pmc, sub, arg);
+}
+
+
 /*
 
 =item C<void pt_thread_yield(void)>


More information about the parrot-commits mailing list