Add 'shf/' from commit 'b6c5a95b664aeb861d7b33ffc9eefe447ba99dd7'
git-subtree-dir: shf git-subtree-mainline:401408448fgit-subtree-split:b6c5a95b66
This commit is contained in:
29
shf/shell/make-mailbox.sml
Normal file
29
shf/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
|
||||
Reference in New Issue
Block a user