git.iko.soy/distributed-process
on master help sign in
Improvements to unsafe primitives
commit9e7b360856d29b96238734ae894b642fe8796865 authorTim Watson <watson.timothy@gmail.com> dateFri 29 Nov 2013, 15:57 (13 years ago) parent79734d3
3 files changed+19−13
src/Control/Distributed/Process.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+2 src/Control/Distributed/Process/UnsafePrimitives.hs+15−13
src/Control/Distributed/Process.hs+2
@@ -40,6 +40,7 @@ module Control.Distributed.Process
4040 , unsafeSend
4141 , unsafeSendChan
4242 , unsafeNSend
43+ , unsafeWrapMessage
4344 -- * Advanced messaging
4445 , Match
4546 , receiveWait
@@ -210,6 +211,7 @@ import Control.Distributed.Process.Internal.Primitives
210211 , matchMessageIf
211212 , isEncoded
212213 , wrapMessage
214+ , unsafeWrapMessage
213215 , unwrapMessage
214216 , handleMessage
215217 , handleMessageIf
src/Control/Distributed/Process/Internal/Primitives.hs+2
@@ -434,6 +434,8 @@ forward msg them = do
434434wrapMessage :: Serializable a => a -> Message
435435wrapMessage = createUnencodedMessage -- see [note Serializable UnencodedMessage]
436436
437+-- | This is the /unsafe/ variant of 'wrapMessage'. See
438+-- "Control.Distributed.Process.UnsafePrimitives" for details.
437439unsafeWrapMessage :: Serializable a => a -> Message
438440unsafeWrapMessage = Unsafe.wrapMessage
439441
src/Control/Distributed/Process/UnsafePrimitives.hs+15−13
@@ -24,11 +24,12 @@
2424-- by several orders of magnitude.
2525--
2626-- This module provides variants of Cloud Haskell's messaging primitives
27−-- ('send', 'sendChan' and 'nsend') which do /not/ force binary serialisation in
28−-- the local case, thereby offering superior intra-node messaging performance.
29−-- The /catch/ is that any evaluation problems lurking within the passed data
30−-- structure - e.g., fields set to @undefined@ and so on - will show up in the
31−-- receiver rather than in the caller (as they would with the /normal/ strategy).
27+-- ('send', 'sendChan', 'nsend' and 'wrapMessage') which do /not/ force binary
28+-- serialisation in the local case, thereby offering superior intra-node
29+-- messaging performance. The /catch/ is that any evaluation problems lurking
30+-- within the passed data structure (e.g., fields set to @undefined@ and so on)
31+-- will show up in the receiver rather than in the caller (as they would with
32+-- the /normal/ strategy).
3233--
3334-- Use of the functions in this module can potentially change the runtime
3435-- behaviour of your application. You have been warned!
@@ -90,6 +91,10 @@ send them msg = do
9091 (ProcessIdentifier them)
9192 NoImplicitReconnect
9293 msg
94+ where
95+ unsafeSendLocal :: (Serializable a) => ProcessId -> a -> Process ()
96+ unsafeSendLocal pid msg =
97+ sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg)
9398
9499-- | Send a message on a typed channel
95100sendChan :: Serializable a => SendPort a -> a -> Process ()
@@ -105,15 +110,12 @@ sendChan (SendPort cid) msg = do
105110 (SendPortIdentifier cid)
106111 NoImplicitReconnect
107112 msg
113+ where
114+ unsafeSendChanLocal :: (Serializable a) => SendPortId -> a -> Process ()
115+ unsafeSendChanLocal spId msg =
116+ sendCtrlMsg Nothing $ LocalPortSend spId (unsafeCreateUnencodedMessage msg)
108117
118+-- | Create an unencoded @Message@ for any @Serializable@ type.
109119wrapMessage :: Serializable a => a -> Message
110120wrapMessage = unsafeCreateUnencodedMessage
111121
112−unsafeSendLocal :: (Serializable a) => ProcessId -> a -> Process ()
113−unsafeSendLocal pid msg =
114− sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg)
115−
116−unsafeSendChanLocal :: (Serializable a) => SendPortId -> a -> Process ()
117−unsafeSendChanLocal spId msg =
118− sendCtrlMsg Nothing $ LocalPortSend spId (unsafeCreateUnencodedMessage msg)
119−