create separate mailbox structures for draw and input messages, because our plan is to: 'handle input + drawing on a single thread'
This commit is contained in:
1
shell/draw-mailbox.sml
Normal file
1
shell/draw-mailbox.sml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
structure DrawMailbox = MakeMailbox(DrawMsg)
|
||||||
1
shell/input-mailbox.sml
Normal file
1
shell/input-mailbox.sml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
structure InputMailbox = MakeMailbox(InputMsg)
|
||||||
29
shell/make-mailbox.sml
Normal file
29
shell/make-mailbox.sml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
signature MAKE_MAILBOX =
|
||||||
|
sig
|
||||||
|
type t
|
||||||
|
end
|
||||||
|
|
||||||
|
functor MakeMailbox(Fn: MAKE_MAILBOX) =
|
||||||
|
struct
|
||||||
|
val messages: Fn.t vector ref = ref #[]
|
||||||
|
|
||||||
|
fun getMessagesAndClear () =
|
||||||
|
let
|
||||||
|
val () = MLton.Thread.atomicBegin ()
|
||||||
|
val msgs = !messages
|
||||||
|
val () = messages := #[]
|
||||||
|
val () = MLton.Thread.atomicEnd ()
|
||||||
|
in
|
||||||
|
msgs
|
||||||
|
end
|
||||||
|
|
||||||
|
fun append newMsg =
|
||||||
|
let
|
||||||
|
val () = MLton.Thread.atomicBegin ()
|
||||||
|
val msgs = !messages
|
||||||
|
val msgs = Vector.concat [msgs, #[newMsg]]
|
||||||
|
val () = messages := msgs
|
||||||
|
in
|
||||||
|
MLton.Thread.atomicEnd ()
|
||||||
|
end
|
||||||
|
end
|
||||||
8
shf.mlb
8
shf.mlb
@@ -66,6 +66,14 @@ in
|
|||||||
ffi/glfw-input.sml
|
ffi/glfw-input.sml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ann
|
||||||
|
"allowVectorExps true"
|
||||||
|
in
|
||||||
|
shell/make-mailbox.sml
|
||||||
|
end
|
||||||
|
shell/input-mailbox.sml
|
||||||
|
shell/draw-mailbox.sml
|
||||||
|
|
||||||
shell/exception-logger.sml
|
shell/exception-logger.sml
|
||||||
shell/search-thread.sml
|
shell/search-thread.sml
|
||||||
shell/update-thread.sml
|
shell/update-thread.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user