ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/EV/EV.pm
Revision: 1.47
Committed: Sat Aug 22 22:36:23 2009 UTC (14 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-5_17
Changes since 1.46: +1 -1 lines
Log Message:
5.17

File Contents

# Content
1 =head1 NAME
2
3 Coro::EV - do events the coro-way, with EV
4
5 =head1 SYNOPSIS
6
7 use Coro;
8 use Coro::EV;
9
10 EV::loop;
11
12 =head1 DESCRIPTION
13
14 This module does two things: First, it offers some utility functions that
15 might be useful for threads, and secondly, it integrates Coro into the
16 EV main loop:
17
18 Before the process blocks (in EV::loop) to wait for events, this module
19 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 priority, then continue in the event loop.
22
23 That means that threads with the same or higher pripority as the threads
24 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
29 =head1 RUNNING WITH OR WITHOUT A MAINLOOP
30
31 In general, you should always run EV::loop, either in your main program,
32 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
41 =head1 FUNCTIONS
42
43 =over 4
44
45 =cut
46
47 package Coro::EV;
48
49 no warnings;
50 use strict;
51
52 use Carp;
53 no warnings;
54
55 use Coro;
56
57 use EV ();
58 use XSLoader;
59
60 BEGIN {
61 our $VERSION = 5.17;
62
63 local $^W = 0; # avoid redefine warning for Coro::ready;
64 XSLoader::load __PACKAGE__, $VERSION;
65 }
66
67 our $IDLE = new Coro sub {
68 while () {
69 &_loop_oneshot;
70 &Coro::schedule;
71 }
72 };
73 $IDLE->{desc} = "[EV idle thread]";
74
75 $Coro::idle = $IDLE;
76
77 =item $revents = Coro::EV::timed_io_once $fileno_or_fh, $events[, $timeout]
78
79 Blocks the coroutine until either the given event set has occured on the
80 fd, or the timeout has been reached (if timeout is missing or C<undef>
81 then there will be no timeout). Returns the received flags.
82
83 =item Coro::EV::timer_once $after
84
85 Blocks the coroutine for at least C<$after> seconds.
86
87 =cut
88
89 1;
90
91 =back
92
93 =head1 AUTHOR
94
95 Marc Lehmann <schmorp@schmorp.de>
96 http://home.schmorp.de/
97
98 =cut
99