ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/EV/EV.pm
Revision: 1.55
Committed: Sat Oct 23 09:28:50 2010 UTC (13 years, 7 months ago) by root
Branch: MAIN
CVS Tags: rel-5_24
Changes since 1.54: +1 -1 lines
Log Message:
5_24

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.31 Coro::EV - do events the coro-way, with EV
4 root 1.1
5     =head1 SYNOPSIS
6    
7     use Coro;
8     use Coro::EV;
9    
10 root 1.5 EV::loop;
11    
12 root 1.4 =head1 DESCRIPTION
13 root 1.1
14 root 1.4 This module does two things: First, it offers some utility functions that
15 root 1.38 might be useful for threads, and secondly, it integrates Coro into the
16 root 1.4 EV main loop:
17    
18     Before the process blocks (in EV::loop) to wait for events, this module
19 root 1.38 will schedule and run all ready (= runnable) threads of the same or
20     higher priority. After that, it will cede once to a threads of lower
21 root 1.4 priority, then continue in the event loop.
22    
23 root 1.54 That means that threads with the same or higher priority as the threads
24 root 1.38 running the main loop will inhibit event processing, while threads of
25     lower priority will get the CPU, but cannot completeley inhibit event
26     processing. Note that for that to work you actually have to run the EV
27     event loop in some thread.
28 root 1.1
29 root 1.39 =head1 RUNNING WITH OR WITHOUT A MAINLOOP
30 root 1.5
31     In general, you should always run EV::loop, either in your main program,
32 root 1.38 or in a separate coroutine. If you don't do that and all coroutines
33     start waiting for some events, this module will run the event loop once,
34     but this is very inefficient and will also not make it possible to run
35     background threads.
36    
37     To run the EV event loop in a separate thread, you can simply do this:
38    
39     async { EV::loop };
40 root 1.5
41 root 1.1 =head1 FUNCTIONS
42    
43     =over 4
44    
45     =cut
46    
47     package Coro::EV;
48    
49 root 1.48 use common::sense;
50 root 1.1
51     use Carp;
52    
53     use Coro;
54    
55     use EV ();
56     use XSLoader;
57    
58     BEGIN {
59 root 1.55 our $VERSION = 5.24;
60 root 1.1
61     local $^W = 0; # avoid redefine warning for Coro::ready;
62     XSLoader::load __PACKAGE__, $VERSION;
63     }
64    
65 root 1.8 our $IDLE = new Coro sub {
66     while () {
67     &_loop_oneshot;
68 root 1.51 Coro::schedule if Coro::nready;
69 root 1.8 }
70     };
71 root 1.46 $IDLE->{desc} = "[EV idle thread]";
72 root 1.1
73 root 1.32 $Coro::idle = $IDLE;
74 root 1.1
75 root 1.39 =item $revents = Coro::EV::timed_io_once $fileno_or_fh, $events[, $timeout]
76 root 1.3
77     Blocks the coroutine until either the given event set has occured on the
78 root 1.39 fd, or the timeout has been reached (if timeout is missing or C<undef>
79     then there will be no timeout). Returns the received flags.
80 root 1.3
81     =item Coro::EV::timer_once $after
82    
83     Blocks the coroutine for at least C<$after> seconds.
84    
85     =cut
86    
87 root 1.1 1;
88    
89     =back
90    
91     =head1 AUTHOR
92    
93     Marc Lehmann <schmorp@schmorp.de>
94     http://home.schmorp.de/
95    
96     =cut
97