use concurrency for rebuilding search list after deletion so we don't block main thread on very, very large files
This commit is contained in:
14
shell/search-thread.sml
Normal file
14
shell/search-thread.sml
Normal file
@@ -0,0 +1,14 @@
|
||||
structure SearchThread =
|
||||
struct
|
||||
open CML
|
||||
|
||||
(* Prerequisite to sending message: move buffer to end. *)
|
||||
fun loop (searchMailbox, inputMailbox) =
|
||||
let
|
||||
val (buffer, searchString) = Mailbox.recv searchMailbox
|
||||
val (_, searchList) = SearchList.build (buffer, searchString)
|
||||
val () = Mailbox.send (inputMailbox, InputMsg.WITH_SEARCH_LIST searchList)
|
||||
in
|
||||
loop (searchMailbox, inputMailbox)
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,7 @@ struct
|
||||
(* create mailboxes for CML communication *)
|
||||
val inputMailbox = Mailbox.mailbox ()
|
||||
val drawMailbox = Mailbox.mailbox ()
|
||||
val searchMailbox = Mailbox.mailbox ()
|
||||
|
||||
fun frameBufferSizeCallback (width, height) =
|
||||
Mailbox.send (inputMailbox, RESIZE_EVENT (width, height))
|
||||
@@ -79,7 +80,9 @@ struct
|
||||
|
||||
val _ = CML.spawn (fn () => GlDraw.loop (drawMailbox, window))
|
||||
val _ = CML.spawn (fn () =>
|
||||
UpdateThread.loop (app, inputMailbox, drawMailbox))
|
||||
UpdateThread.loop (app, inputMailbox, drawMailbox, searchMailbox))
|
||||
val _ = CML.spawn (fn () =>
|
||||
SearchThread.loop (searchMailbox, inputMailbox))
|
||||
in
|
||||
()
|
||||
end
|
||||
|
||||
@@ -4,18 +4,21 @@ struct
|
||||
open MailboxType
|
||||
open InputMsg
|
||||
|
||||
fun sendMsg (msg, drawMailbox) =
|
||||
case msg of DRAW msg => Mailbox.send (drawMailbox, msg)
|
||||
fun sendMsg (msg, drawMailbox, searchMailbox) =
|
||||
case msg of
|
||||
DRAW msg => Mailbox.send (drawMailbox, msg)
|
||||
| SEARCH (buffer, searchString) =>
|
||||
Mailbox.send (searchMailbox, (buffer, searchString))
|
||||
|
||||
fun sendMsgs (msgList, drawMailbox) =
|
||||
fun sendMsgs (msgList, drawMailbox, searchMailbox) =
|
||||
case msgList of
|
||||
hd :: tl =>
|
||||
let val _ = sendMsg (hd, drawMailbox)
|
||||
in sendMsgs (tl, drawMailbox)
|
||||
let val _ = sendMsg (hd, drawMailbox, searchMailbox)
|
||||
in sendMsgs (tl, drawMailbox, searchMailbox)
|
||||
end
|
||||
| [] => ()
|
||||
|
||||
fun loop (app: AppType.app_type, inputMailbox, drawMailbox) =
|
||||
fun loop (app: AppType.app_type, inputMailbox, drawMailbox, searchMailbox) =
|
||||
let
|
||||
val inputMsg = Mailbox.recv inputMailbox
|
||||
val () =
|
||||
@@ -33,8 +36,8 @@ struct
|
||||
val app = AppUpdate.update (app, inputMsg)
|
||||
handle e => ExceptionLogger.log e
|
||||
|
||||
val () = sendMsgs (#msgs app, drawMailbox)
|
||||
val () = sendMsgs (#msgs app, drawMailbox, searchMailbox)
|
||||
in
|
||||
loop (app, inputMailbox, drawMailbox)
|
||||
loop (app, inputMailbox, drawMailbox, searchMailbox)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user