]> gitweb.factorcode.org Git - factor.git/blob - basis/core-foundation/run-loop/run-loop.factor
Create basis vocab root
[factor.git] / basis / core-foundation / run-loop / run-loop.factor
1 ! Copyright (C) 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.syntax kernel threads init namespaces alien
4 core-foundation ;
5 IN: core-foundation.run-loop
6
7 : kCFRunLoopRunFinished 1 ; inline
8 : kCFRunLoopRunStopped 2 ; inline
9 : kCFRunLoopRunTimedOut 3 ; inline
10 : kCFRunLoopRunHandledSource 4 ; inline
11
12 TYPEDEF: void* CFRunLoopRef
13
14 FUNCTION: CFRunLoopRef CFRunLoopGetMain ( ) ;
15 FUNCTION: CFRunLoopRef CFRunLoopGetCurrent ( ) ;
16
17 FUNCTION: SInt32 CFRunLoopRunInMode (
18    CFStringRef mode,
19    CFTimeInterval seconds,
20    Boolean returnAfterSourceHandled
21 ) ;
22
23 : CFRunLoopDefaultMode ( -- alien )
24     #! Ugly, but we don't have static NSStrings
25     \ CFRunLoopDefaultMode get-global dup expired? [
26         drop
27         "kCFRunLoopDefaultMode" <CFString>
28         dup \ CFRunLoopDefaultMode set-global
29     ] when ;
30
31 : run-loop-thread ( -- )
32     CFRunLoopDefaultMode 0 f CFRunLoopRunInMode
33     kCFRunLoopRunHandledSource = [ 1000 sleep ] unless
34     run-loop-thread ;
35
36 : start-run-loop-thread ( -- )
37     [ run-loop-thread t ] "CFRunLoop dispatcher" spawn-server drop ;
38
39 [ start-run-loop-thread ] "core-foundation.run-loop" add-init-hook