! Copyright (C) 2008 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
USING: dlists kernel threads math concurrency.conditions\r
-continuations accessors summary ;\r
+continuations accessors summary locals fry ;\r
IN: concurrency.semaphores\r
\r
TUPLE: semaphore count threads ;\r
: acquire-timeout ( semaphore timeout -- )\r
over count>> zero?\r
[ dupd wait-to-acquire ] [ drop ] if\r
- [ 1- ] change-count drop ;\r
+ [ 1 - ] change-count drop ;\r
\r
: acquire ( semaphore -- )\r
f acquire-timeout ;\r
\r
: release ( semaphore -- )\r
- [ 1+ ] change-count\r
+ [ 1 + ] change-count\r
threads>> notify-1 ;\r
\r
-: with-semaphore-timeout ( semaphore timeout quot -- )\r
- pick rot acquire-timeout swap\r
- [ release ] curry [ ] cleanup ; inline\r
+:: with-semaphore-timeout ( semaphore timeout quot -- )\r
+ semaphore timeout acquire-timeout\r
+ quot [ semaphore release ] [ ] cleanup ; inline\r
\r
: with-semaphore ( semaphore quot -- )\r
- over acquire swap [ release ] curry [ ] cleanup ; inline\r
+ swap dup acquire '[ _ release ] [ ] cleanup ; inline\r