on master help sign in
Allow quitting threads
75248d6Edwin Brady
libs/base/System/Concurrency/Channels.idr+4
@@ -61,3 +61,7 @@ export
61unsafeRecv : (expected : Type) -> Channel -> IO (Maybe expected)
61unsafeRecv : (expected : Type) -> Channel -> IO (Maybe expected)
62unsafeRecv a (MkConc pid ch_id) = getMsgFrom {a} pid ch_id
62unsafeRecv a (MkConc pid ch_id) = getMsgFrom {a} pid ch_id
63
63
64+||| Exit the thread immediately
65+export
66+stopThread : IO a
67+stopThread = Raw.stopThread
libs/base/System/Concurrency/Raw.idr+6
@@ -106,3 +106,9 @@ getMsgFrom {a} sender channel
106 foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
106 foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
107 pure (Just x)
107 pure (Just x)
108
108
109+stopThread : IO a
110+stopThread = do vm <- getMyVM
111+ MkRaw res <- foreign FFI_C "idris_stopThread" (Ptr -> IO (Raw a)) vm
112+ pure res
113+
114+
rts/idris_rts.c+6
@@ -753,6 +753,12 @@ void* vmThread(VM* callvm, func f, VAL arg) {
753 return vm;
753 return vm;
754}
754}
755
755
756+void* idris_stopThread(VM* vm) {
757+ close_vm(vm);
758+ pthread_exit(NULL);
759+ return NULL;
760+}
761+
756// VM is assumed to be a different vm from the one x lives on
762// VM is assumed to be a different vm from the one x lives on
757
763
758VAL doCopyTo(VM* vm, VAL x) {
764VAL doCopyTo(VM* vm, VAL x) {
rts/idris_rts.h+1
@@ -309,6 +309,7 @@ void free_nullaries();
309void init_signals();
309void init_signals();
310
310
311void* vmThread(VM* callvm, func f, VAL arg);
311void* vmThread(VM* callvm, func f, VAL arg);
312+void* idris_stopThread(VM* vm);
312
313
313// Copy a structure to another vm's heap
314// Copy a structure to another vm's heap
314VAL copyTo(VM* newVM, VAL x);
315VAL copyTo(VM* newVM, VAL x);