]> Nishi Git Mirror - gwion.git/commitdiff
:art: Shred/Fork get_now
authorJérémie Astor <astor.jeremie@wanadoo.fr>
Tue, 14 Jul 2020 08:34:37 +0000 (10:34 +0200)
committerJérémie Astor <astor.jeremie@wanadoo.fr>
Tue, 14 Jul 2020 08:34:37 +0000 (10:34 +0200)
src/lib/shred.c
tests/fork/fork_now.gw [new file with mode: 0644]

index bcbf0c9575c7af80ce687786448c5122ebcb81bb..4f382a1ea4a32ece2f6cc4ac3a1c928ee8d481f3 100644 (file)
@@ -213,6 +213,13 @@ static MFUN(fork_test_cancel) {
   }
 }
 
+static MFUN(shred_now) {
+  VM *vm = shred->info->vm;
+  while(vm->parent)
+    vm = vm->parent;
+  *(m_float*)RETURN = vm->bbq->pos;
+}
+
 struct ThreadLauncher {
   MUTEX_TYPE mutex;
   THREAD_COND_TYPE cond;
@@ -350,6 +357,8 @@ GWION_IMPORT(shred) {
   GWI_BB(gwi_func_end(gwi, shred_lock, ae_flag_none))
   gwi_func_ini(gwi, "void", "unlock");
   GWI_BB(gwi_func_end(gwi, shred_unlock, ae_flag_none))
+  gwi_func_ini(gwi, "float", "get_now");
+  GWI_BB(gwi_func_end(gwi, shred_now, ae_flag_none))
   GWI_BB(gwi_class_end(gwi))
 
   struct SpecialId_ spid = { .type=t_shred, .exec=RegPushMe, .is_const=1 };
diff --git a/tests/fork/fork_now.gw b/tests/fork/fork_now.gw
new file mode 100644 (file)
index 0000000..c019e5c
--- /dev/null
@@ -0,0 +1,3 @@
+samp => now;
+fork { <<< me.get_now() >>>; };
+samp => now;