Clone host runtime when creating test threads
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/901aa9cc Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/901aa9cc Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/901aa9cc Branch: refs/heads/master Commit: 901aa9cc0cf1709b4b1f2a326c57876e995cd220 Parents: fd79848 Author: Nick Wellnhofer <[email protected]> Authored: Sun May 10 18:32:02 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Tue May 12 20:15:25 2015 +0200 ---------------------------------------------------------------------- runtime/c/src/Clownfish/Test/TestThreads.c | 2 +- runtime/c/src/Clownfish/TestHarness/TestUtils.c | 38 ++++++++++++++++++++ .../core/Clownfish/Test/TestLockFreeRegistry.c | 3 +- runtime/core/Clownfish/TestHarness/TestUtils.c | 22 ++++++++++-- .../core/Clownfish/TestHarness/TestUtils.cfh | 12 ++++++- runtime/perl/xs/XSBind.c | 24 ++++++++++++- 6 files changed, 95 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/c/src/Clownfish/Test/TestThreads.c ---------------------------------------------------------------------- diff --git a/runtime/c/src/Clownfish/Test/TestThreads.c b/runtime/c/src/Clownfish/Test/TestThreads.c index f75c097..4fd3bd3 100644 --- a/runtime/c/src/Clownfish/Test/TestThreads.c +++ b/runtime/c/src/Clownfish/Test/TestThreads.c @@ -45,7 +45,7 @@ test_threads(TestBatchRunner *runner) { Err_set_error(Err_new(Str_newf("main"))); - Thread *thread = TestUtils_thread_create(S_err_thread, runner); + Thread *thread = TestUtils_thread_create(S_err_thread, runner, NULL); TestUtils_thread_join(thread); String *mess = Err_Get_Mess(Err_get_error()); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/c/src/Clownfish/TestHarness/TestUtils.c ---------------------------------------------------------------------- diff --git a/runtime/c/src/Clownfish/TestHarness/TestUtils.c b/runtime/c/src/Clownfish/TestHarness/TestUtils.c new file mode 100644 index 0000000..e862423 --- /dev/null +++ b/runtime/c/src/Clownfish/TestHarness/TestUtils.c @@ -0,0 +1,38 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CFISH_USE_SHORT_NAMES + +#include "charmony.h" + +#include "Clownfish/TestHarness/TestUtils.h" + +void* +cfish_TestUtils_clone_host_runtime() { + return NULL; +} + +void +cfish_TestUtils_set_host_runtime(void *runtime) { + UNUSED_VAR(runtime); +} + +void +cfish_TestUtils_destroy_host_runtime(void *runtime) { + UNUSED_VAR(runtime); +} + + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/core/Clownfish/Test/TestLockFreeRegistry.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c index 3e7edf1..4b0fe1b 100644 --- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c +++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c @@ -139,7 +139,8 @@ test_threads(TestBatchRunner *runner) { for (uint32_t i = 0; i < NUM_THREADS; i++) { thread_args[i].target_time = target_time; - threads[i] = TestUtils_thread_create(S_register_many, &thread_args[i]); + threads[i] + = TestUtils_thread_create(S_register_many, &thread_args[i], NULL); } uint32_t total_succeeded = 0; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/core/Clownfish/TestHarness/TestUtils.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.c b/runtime/core/Clownfish/TestHarness/TestUtils.c index 228aef7..03ce1f8 100644 --- a/runtime/core/Clownfish/TestHarness/TestUtils.c +++ b/runtime/core/Clownfish/TestHarness/TestUtils.c @@ -190,6 +190,7 @@ TestUtils_usleep(uint64_t microseconds) { struct Thread { HANDLE handle; + void *runtime; thread_routine_t routine; void *arg; }; @@ -199,13 +200,21 @@ bool TestUtils_has_threads = true; static DWORD S_thread(void *arg) { Thread *thread = (Thread*)arg; + + if (thread->runtime) { + TestUtils_set_host_runtime(thread->runtime); + } + thread->routine(thread->arg); + return 0; } Thread* -TestUtils_thread_create(thread_routine_t routine, void *arg) { +TestUtils_thread_create(thread_routine_t routine, void *arg, + void *host_runtime) { Thread *thread = (Thread*)MALLOCATE(sizeof(Thread)); + thread->runtime = host_runtime; thread->routine = routine; thread->arg = arg; @@ -239,6 +248,7 @@ TestUtils_thread_join(Thread *thread) { struct Thread { pthread_t pthread; + void *runtime; thread_routine_t routine; void *arg; }; @@ -248,13 +258,21 @@ bool TestUtils_has_threads = true; static void* S_thread(void *arg) { Thread *thread = (Thread*)arg; + + if (thread->runtime) { + TestUtils_set_host_runtime(thread->runtime); + } + thread->routine(thread->arg); + return NULL; } Thread* -TestUtils_thread_create(thread_routine_t routine, void *arg) { +TestUtils_thread_create(thread_routine_t routine, void *arg, + void *host_runtime) { Thread *thread = (Thread*)MALLOCATE(sizeof(Thread)); + thread->runtime = host_runtime; thread->routine = routine; thread->arg = arg; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/core/Clownfish/TestHarness/TestUtils.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.cfh b/runtime/core/Clownfish/TestHarness/TestUtils.cfh index 594f838..1a3bd1a 100644 --- a/runtime/core/Clownfish/TestHarness/TestUtils.cfh +++ b/runtime/core/Clownfish/TestHarness/TestUtils.cfh @@ -80,13 +80,23 @@ inert class Clownfish::TestHarness::TestUtils { usleep(uint64_t microseconds); inert cfish_Thread* - thread_create(cfish_thread_routine_t routine, void *arg); + thread_create(cfish_thread_routine_t routine, void *arg, + void *host_runtime); inert void thread_yield(); inert void thread_join(cfish_Thread *thread); + + inert void* + clone_host_runtime(); + + inert void + set_host_runtime(void *runtime); + + inert void + destroy_host_runtime(void *runtime); } __C__ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/901aa9cc/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 2902045..c8263eb 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -26,7 +26,7 @@ #include "Clownfish/HashIterator.h" #include "Clownfish/Method.h" #include "Clownfish/Test/TestThreads.h" -#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Clownfish/TestHarness/TestUtils.h" #include "Clownfish/Util/Atomic.h" #include "Clownfish/Util/StringHelper.h" #include "Clownfish/Util/Memory.h" @@ -1050,6 +1050,28 @@ cfish_Err_trap(CFISH_Err_Attempt_t routine, void *context) { return error; } +/********************* Clownfish::TestHarness::TestUtils ********************/ + +void* +cfish_TestUtils_clone_host_runtime() { + PerlInterpreter *interp = (PerlInterpreter*)PERL_GET_CONTEXT; + PerlInterpreter *clone = perl_clone(interp, CLONEf_CLONE_HOST); + PERL_SET_CONTEXT(interp); + return clone; +} + +void +cfish_TestUtils_set_host_runtime(void *runtime) { + PERL_SET_CONTEXT(runtime); +} + +void +cfish_TestUtils_destroy_host_runtime(void *runtime) { + PerlInterpreter *interp = (PerlInterpreter*)runtime; + perl_destruct(interp); + perl_free(interp); +} + /*********************** Clownfish::Test::TestThreads ***********************/ void
