diff options
author | Eduardo Julian | 2019-04-18 23:36:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-04-18 23:36:08 -0400 |
commit | c339a123ea6a9c9baaaed92281af471002f89321 (patch) | |
tree | 3d3a74a139d2ab6f807931973235a9057d0c7d53 /stdlib/source/lux/control/concurrency/process.lux | |
parent | f59327398a0350a42b640b247ea3d392011b4e94 (diff) |
WIP: Host interop for the new JVM compiler.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/concurrency/process.lux | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/stdlib/source/lux/control/concurrency/process.lux b/stdlib/source/lux/control/concurrency/process.lux index 322300a17..074ea96ac 100644 --- a/stdlib/source/lux/control/concurrency/process.lux +++ b/stdlib/source/lux/control/concurrency/process.lux @@ -10,12 +10,33 @@ ["." list]]] [tool [compiler - ["." host]]] - [host (#+ import: object)]] + ["@" host]]] + ["." host (#+ import: object)]] [// ["." atom (#+ Atom)]]) -(`` (for {(~~ (static host.old)) +(`` (for {(~~ (static @.old)) + (as-is (import: #long java/lang/Object) + + (import: #long java/lang/Runtime + (#static getRuntime [] java/lang/Runtime) + (availableProcessors [] int)) + + (import: #long java/lang/Runnable) + + (import: #long java/util/concurrent/TimeUnit + (#enum MILLISECONDS)) + + (import: #long java/util/concurrent/Executor + (execute [java/lang/Runnable] #io void)) + + (import: #long (java/util/concurrent/ScheduledFuture a)) + + (import: #long java/util/concurrent/ScheduledThreadPoolExecutor + (new [int]) + (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] #io (java/util/concurrent/ScheduledFuture java/lang/Object)))) + + (~~ (static @.jvm)) (as-is (import: #long java/lang/Object) (import: #long java/lang/Runtime @@ -45,17 +66,25 @@ (def: #export parallelism Nat - (`` (for {(~~ (static host.old)) + (`` (for {(~~ (static @.old)) + (|> (java/lang/Runtime::getRuntime) + (java/lang/Runtime::availableProcessors) + .nat) + + (~~ (static @.jvm)) (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) - .nat)} + (:coerce Nat))} ## Default 1))) (def: runner - (`` (for {(~~ (static host.old)) - (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism))} + (`` (for {(~~ (static @.old)) + (java/util/concurrent/ScheduledThreadPoolExecutor::new (.int ..parallelism)) + + (~~ (static @.jvm)) + (java/util/concurrent/ScheduledThreadPoolExecutor::new (:coerce host.Long ..parallelism))} ## Default (: (Atom (List Process)) @@ -63,7 +92,17 @@ (def: #export (schedule milli-seconds action) (-> Nat (IO Any) (IO Any)) - (`` (for {(~~ (static host.old)) + (`` (for {(~~ (static @.old)) + (let [runnable (object [] [java/lang/Runnable] + [] + (java/lang/Runnable [] (run) void + (io.run action)))] + (case milli-seconds + 0 (java/util/concurrent/Executor::execute runnable runner) + _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli-seconds) java/util/concurrent/TimeUnit::MILLISECONDS + runner))) + + (~~ (static @.jvm)) (let [runnable (object [] [java/lang/Runnable] [] (java/lang/Runnable [] (run) void @@ -79,11 +118,14 @@ #action action})) runner)))) -(`` (for {(~~ (static host.old)) +(`` (for {(~~ (static @.old)) + (as-is) + + (~~ (static @.jvm)) (as-is)} ## Default - (as-is (exception: #export (cannot-continue-running-processes) "") + (as-is (exception: #export cannot-continue-running-processes) (def: #export run! (IO Any) |