]> gitweb.factorcode.org Git - factor.git/blob - basis/core-foundation/run-loop/run-loop.factor
Merge branch 'master' of git://repo.or.cz/factor/jcg
[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 calendar ;
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 TYPEDEF: void* CFRunLoopSourceRef
14
15 FUNCTION: CFRunLoopRef CFRunLoopGetMain ( ) ;
16 FUNCTION: CFRunLoopRef CFRunLoopGetCurrent ( ) ;
17
18 FUNCTION: SInt32 CFRunLoopRunInMode (
19    CFStringRef mode,
20    CFTimeInterval seconds,
21    Boolean returnAfterSourceHandled
22 ) ;
23
24 FUNCTION: CFRunLoopSourceRef CFFileDescriptorCreateRunLoopSource (
25     CFAllocatorRef allocator,
26     CFFileDescriptorRef f,
27     CFIndex order
28 ) ;
29
30 FUNCTION: void CFRunLoopAddSource (
31    CFRunLoopRef rl,
32    CFRunLoopSourceRef source,
33    CFStringRef mode
34 ) ;
35
36 : CFRunLoopDefaultMode ( -- alien )
37     #! Ugly, but we don't have static NSStrings
38     \ CFRunLoopDefaultMode get-global dup expired? [
39         drop
40         "kCFRunLoopDefaultMode" <CFString>
41         dup \ CFRunLoopDefaultMode set-global
42     ] when ;
43
44 : run-loop-thread ( -- )
45     CFRunLoopDefaultMode 0 f CFRunLoopRunInMode
46     kCFRunLoopRunHandledSource = [ 1 seconds sleep ] unless
47     run-loop-thread ;
48
49 : start-run-loop-thread ( -- )
50     [ run-loop-thread t ] "CFRunLoop dispatcher" spawn-server drop ;