]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/concurrency/semaphores/semaphores.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / basis / concurrency / semaphores / semaphores.factor
index dcd0ed9a2c8c31e07f9f52d80b3d6a9ae993affd..392b7557d69e21a5e3f4198986e4f55b0256c1fa 100644 (file)
@@ -1,38 +1,38 @@
-! 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 locals fry ;\r
-IN: concurrency.semaphores\r
-\r
-TUPLE: semaphore count threads ;\r
-\r
-ERROR: negative-count-semaphore ;\r
-\r
-M: negative-count-semaphore summary\r
-    drop "Cannot have semaphore with negative count" ;\r
-\r
-: <semaphore> ( n -- semaphore )\r
-    dup 0 < [ negative-count-semaphore ] when\r
-    <dlist> semaphore boa ;\r
-\r
-: wait-to-acquire ( semaphore timeout -- )\r
-    [ threads>> ] dip "semaphore" wait ;\r
-\r
-: acquire-timeout ( semaphore timeout -- )\r
-    over count>> zero?\r
-    [ dupd wait-to-acquire ] [ drop ] if\r
-    [ 1 - ] change-count drop ;\r
-\r
-: acquire ( semaphore -- )\r
-    f acquire-timeout ;\r
-\r
-: release ( semaphore -- )\r
-    [ 1 + ] change-count\r
-    threads>> notify-1 ;\r
-\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
-    swap dup acquire '[ _ release ] [ ] cleanup ; inline\r
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: dlists kernel threads math concurrency.conditions
+continuations accessors summary locals fry ;
+IN: concurrency.semaphores
+
+TUPLE: semaphore count threads ;
+
+ERROR: negative-count-semaphore ;
+
+M: negative-count-semaphore summary
+    drop "Cannot have semaphore with negative count" ;
+
+: <semaphore> ( n -- semaphore )
+    dup 0 < [ negative-count-semaphore ] when
+    <dlist> semaphore boa ;
+
+: wait-to-acquire ( semaphore timeout -- )
+    [ threads>> ] dip "semaphore" wait ;
+
+: acquire-timeout ( semaphore timeout -- )
+    over count>> zero?
+    [ dupd wait-to-acquire ] [ drop ] if
+    [ 1 - ] change-count drop ;
+
+: acquire ( semaphore -- )
+    f acquire-timeout ;
+
+: release ( semaphore -- )
+    [ 1 + ] change-count
+    threads>> notify-1 ;
+
+:: with-semaphore-timeout ( semaphore timeout quot -- )
+    semaphore timeout acquire-timeout
+    quot [ semaphore release ] [ ] cleanup ; inline
+
+: with-semaphore ( semaphore quot -- )
+    swap dup acquire '[ _ release ] [ ] cleanup ; inline