mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Add janet_interpreter_interrupt for custom scheduling.
This would allow an embedder to suspend the current Janet fiber via an external event like a signal, other thread, or really anything. This is a useful primitive for custom schedulers that would call janet_interpreter_interupt periodically (say, in an interval with SIG_ALRM), do some work, and then use janet_continue on the janet_root_fiber, or for embedding into other soft-realtime applications like a game. To say, only allow about 5ms per frame of interpreter time.
This commit is contained in:
		| @@ -28,6 +28,10 @@ | ||||
|  | ||||
| JANET_THREAD_LOCAL JanetVM janet_vm; | ||||
|  | ||||
| JanetVM *janet_local_vm(void) { | ||||
|     return &janet_vm; | ||||
| } | ||||
|  | ||||
| JanetVM *janet_vm_alloc(void) { | ||||
|     JanetVM *mem = janet_malloc(sizeof(JanetVM)); | ||||
|     if (NULL == mem) { | ||||
| @@ -47,3 +51,14 @@ void janet_vm_save(JanetVM *into) { | ||||
| void janet_vm_load(JanetVM *from) { | ||||
|     janet_vm = *from; | ||||
| } | ||||
|  | ||||
| /* Trigger suspension of the Janet vm by trying to | ||||
|  * exit the interpeter loop when convenient. You can optionally | ||||
|  * use NULL to interrupt the current VM when convenient */ | ||||
| void janet_interpreter_interrupt(JanetVM *vm) { | ||||
|     if (NULL == vm) { | ||||
|         janet_vm.auto_suspend = 1; | ||||
|     } else { | ||||
|         vm->auto_suspend = 1; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 bakpakin
					bakpakin