src/Pure/Concurrent/mailbox.ML
changeset 28158 96cbf4afdc7d
parent 28147 b44a7b259909
child 28170 a18cf8a0e656
equal deleted inserted replaced
28157:0435d23deccc 28158:96cbf4afdc7d
    51       val limit = Time.+ (Time.now (), timeout);
    51       val limit = Time.+ (Time.now (), timeout);
    52       fun check () = not (Queue.is_empty (! messages)) orelse
    52       fun check () = not (Queue.is_empty (! messages)) orelse
    53         ConditionVar.waitUntil (cond, lock, limit) andalso check ();
    53         ConditionVar.waitUntil (cond, lock, limit) andalso check ();
    54       val ok = restore_attributes check ()
    54       val ok = restore_attributes check ()
    55         handle Interrupt => (Mutex.unlock lock; raise Interrupt);
    55         handle Interrupt => (Mutex.unlock lock; raise Interrupt);
    56       val res =
    56       val res = if ok then SOME (change_result messages Queue.dequeue) else NONE;
    57         if ok then
       
    58           let
       
    59             val (msg, msgs) = Queue.dequeue (! messages);
       
    60             val _ = messages := msgs;
       
    61           in SOME msg end
       
    62         else NONE;
       
    63 
    57 
    64       val _ = Mutex.unlock lock;
    58       val _ = Mutex.unlock lock;
    65     in res end) ();
    59     in res end) ();
    66 
    60 
    67 fun receive mailbox =
    61 fun receive mailbox =