Don't lock the MVar closure on tryReadMVar
authorDavid Feuer <david.feuer@gmail.com>
Fri, 29 Jun 2018 18:31:33 +0000 (14:31 -0400)
committerDavid Feuer <David.Feuer@gmail.com>
Fri, 29 Jun 2018 18:31:34 +0000 (14:31 -0400)
It shouldn't be necessary to lock the `MVar` closure on `tryReadMVar`, since it
just reads one field of the structure and doesn't make any modifications. So
let's not.

Reviewers: bgamari, erikd, simonmar, fryguybob, osa1

Reviewed By: osa1

Subscribers: osa1, rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4905

rts/PrimOps.cmm

index 6081fab..058fe1e 100644 (file)
@@ -1825,18 +1825,14 @@ stg_readMVarzh ( P_ mvar, /* :: MVar a */ )
 
 stg_tryReadMVarzh ( P_ mvar, /* :: MVar a */ )
 {
-    W_ val, info, tso, q;
+    W_ val;
 
-    LOCK_CLOSURE(mvar, info);
+    val = StgMVar_value(mvar);
 
-    if (StgMVar_value(mvar) == stg_END_TSO_QUEUE_closure) {
-        unlockClosure(mvar, info);
+    if (val == stg_END_TSO_QUEUE_closure) {
         return (0, stg_NO_FINALIZER_closure);
     }
 
-    val = StgMVar_value(mvar);
-
-    unlockClosure(mvar, info);
     return (1, val);
 }