]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/threads/threads.factor
1b862562c575f46230e88a53588fcf4b374b995b
[factor.git] / basis / tools / threads / threads.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.\r
2 ! See http://factorcode.org/license.txt for BSD license.\r
3 USING: accessors assocs io io.styles kernel math.order\r
4 math.parser prettyprint sequences sorting system threads ;\r
5 IN: tools.threads\r
6 \r
7 : thread. ( thread -- )\r
8     dup id>> pprint-cell\r
9     dup name>> [\r
10         over write-object\r
11     ] with-cell\r
12     dup state>> [\r
13         [ dup self eq? "running" "yield" ? ] unless*\r
14         write\r
15     ] with-cell\r
16     [\r
17         sleep-entry>> [\r
18             key>> nano-count [-] number>string write\r
19             " nanos" write\r
20         ] when*\r
21     ] with-cell ;\r
22 \r
23 : threads. ( -- )\r
24     standard-table-style [\r
25         [\r
26             { "ID:" "Name:" "Waiting on:" "Remaining sleep:" }\r
27             [ [ write ] with-cell ] each\r
28         ] with-row\r
29 \r
30         threads sort-keys values [\r
31             [ thread. ] with-row\r
32         ] each\r
33     ] tabular-output nl ;\r