Lines Matching refs:loop

5 libev - a high performance full-featured event loop written in C
49 // use the default event loop unless you have special needs
50 struct ev_loop *loop = EV_DEFAULT;
55 ev_io_start (loop, &stdin_watcher);
60 ev_timer_start (loop, &timeout_watcher);
63 ev_run (loop, 0);
95 Libev is an event loop: you register interest in certain events (such as a
100 (or thread) by executing the I<event loop> handler, and will then
118 loop mechanism itself (C<ev_idle>, C<ev_embed>, C<ev_prepare> and
133 name C<loop> (which is always of type C<struct ev_loop *>) will not have
329 An event loop is described by a C<struct ev_loop *> (the C<struct> is
333 The library knows two types of such loops, the I<default> loop, which
341 This returns the "default" event loop object, which is what you should
342 normally use when you just need "the event loop". Event loop objects and
346 If the default loop is already initialised then this function simply
352 If you don't know what event loop to use, use the one returned from this
360 The default loop is the only loop that can handle C<ev_child> watchers,
362 a problem for your application you can either create a dynamic loop with
378 This will create and initialise a new event loop object. If the loop
382 threads is indeed to create one loop per thread, and using the default
383 loop in the "main" or "initial" thread.
413 This works by calling C<getpid ()> on every iteration of the loop,
414 and thus this might slow down your event loop if you do a lot of loop
432 otherwise each loop using C<ev_stat> watchers consumes one inotify handle.
472 writing a server, you should C<accept ()> in a loop to accept as many
585 (for which it usually works), by embedding it into another event loop
606 file descriptor per loop iteration. For small and medium numbers of file
651 Example: Try to create a event loop that uses epoll and nothing else.
660 struct ev_loop *loop = ev_loop_new (ev_recommended_backends () | EVBACKEND_KQUEUE);
662 =item ev_loop_destroy (loop)
664 Destroys an event loop object (frees all memory and kernel state
676 This function is normally used on loop objects allocated by
677 C<ev_loop_new>, but it can also be used on the default loop returned by
680 Note that it is not advisable to call this function on the default loop
685 =item ev_loop_fork (loop)
694 In addition, if you want to reuse a loop (via this function or
697 Again, you I<have> to call it on I<any> loop that you want to re-use after
698 a fork, I<even if you do not plan to use the loop in the parent>. This is
703 process if and only if you want to use the event loop in the child. If
704 you just fork+exec or create a new loop in the child, you don't have to
712 Example: Automate calling C<ev_loop_fork> on the default loop when
724 =item int ev_is_default_loop (loop)
726 Returns true when the given loop is, in fact, the default loop, and false
729 =item unsigned int ev_iteration (loop)
731 Returns the current iteration count for the event loop, which is identical
736 "ticks" the number of loop iterations), as it roughly corresponds with
740 =item unsigned int ev_depth (loop)
754 =item unsigned int ev_backend (loop)
759 =item ev_tstamp ev_now (loop)
761 Returns the current "event loop time", which is the time the event loop
767 =item ev_now_update (loop)
774 very long time without entering the event loop, updating libev's idea of
779 =item ev_suspend (loop)
781 =item ev_resume (loop)
783 These two functions suspend and resume an event loop, for use when the
784 loop is not used for a while and timeouts should not be processed.
799 given loop other than C<ev_resume>, and you B<must not> call C<ev_resume>
803 event loop time (see C<ev_now_update>).
805 =item bool ev_run (loop, int flags)
836 iteration of the loop. This is sometimes useful to poll and handle new
844 iteration of the loop.
855 - Increment loop depth.
866 - Update the "event loop time" (ev_now ()).
871 - Increment loop iteration counter.
874 - Update the "event loop time" (ev_now ()), and do time jump adjustments.
887 - Decrement the loop depth.
890 Example: Queue some jobs and then loop until no events are outstanding
898 =item ev_break (loop, how)
910 =item ev_ref (loop)
912 =item ev_unref (loop)
915 loop: Every watcher keeps one reference, and as long as the reference
938 ev_signal_start (loop, &exitsig);
939 ev_unref (loop);
943 ev_ref (loop);
944 ev_signal_stop (loop, &exitsig);
946 =item ev_set_io_collect_interval (loop, ev_tstamp interval)
948 =item ev_set_timeout_collect_interval (loop, ev_tstamp interval)
957 to increase efficiency of loop iterations (or to increase power-saving
961 one (or very few) event(s) per loop iteration. While this makes the
970 introduce an additional C<ev_sleep ()> call into most loop iterations. The
1004 =item ev_invoke_pending (loop)
1014 =item int ev_pending_count (loop)
1019 =item ev_set_invoke_pending_cb (loop, void (*invoke_pending_cb)(EV_P))
1021 This overrides the invoke pending functionality of the loop: Instead of
1029 =item ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ())
1031 Sometimes you want to share the same loop between multiple threads. This
1037 loop via C<ev_break> and C<ev_async_send>, another way is to set these
1038 I<release> and I<acquire> callbacks on the loop.
1047 While event loop modifications are allowed between invocations of
1049 modifications done will affect the event loop, i.e. adding watchers will
1060 =item ev_set_userdata (loop, void *data)
1062 =item void *ev_userdata (loop)
1064 Set and retrieve a single C<void *> associated with a loop. When
1068 These two functions can be used to associate arbitrary data with a loop,
1073 =item ev_verify (loop)
1099 static void my_cb (struct ev_loop *loop, ev_io *w, int revents)
1102 ev_break (loop, EVBREAK_ALL);
1105 struct ev_loop *loop = ev_default_loop (0);
1111 ev_io_start (loop, &stdin_watcher);
1113 ev_run (loop, 0);
1125 time the event loop detects that the file descriptor given is readable
1134 with a watcher-specific start function (C<< ev_TYPE_start (loop, watcher
1136 corresponding stop function (C<< ev_TYPE_stop (loop, watcher *) >>.
1142 Each and every callback receives the event loop pointer as first, the
1191 watchers invoked before the event loop sleeps or polls for new events, and
1193 or lower priority within an event loop iteration.
1202 The embedded event loop specified in the C<ev_embed> watcher needs attention.
1206 The event loop has been resumed in the child process after fork (see
1211 The event loop is about to be destroyed (see C<ev_cleanup>).
1259 The callback is always of type C<void (*)(struct ev_loop *loop, ev_TYPE *watcher,
1291 =item C<ev_TYPE_start> (loop, ev_TYPE *watcher)
1301 =item C<ev_TYPE_stop> (loop, ev_TYPE *watcher)
1362 =item ev_invoke (loop, ev_TYPE *watcher, int revents)
1364 Invoke the C<watcher> with the given C<loop> and C<revents>. Neither
1365 C<loop> nor C<revents> need to be valid as long as the watcher callback
1369 =item int ev_clear_pending (loop, ev_TYPE *watcher)
1378 =item ev_feed_event (loop, ev_TYPE *watcher, int revents)
1380 Feeds the given event set into the event loop, as if the specified event
1408 Before a watcher can be registered with the event loop it has to be
1413 use in an event loop. It can be moved around, freed, reused etc. at
1420 property of the event loop, and is actively waiting for events. While in
1436 but it is still property of the event loop at this time, so cannot be
1477 callback invocation within a single event loop iteration: Higher priority
1582 in each iteration of the event loop, or, more precisely, when reading
1708 typically causing the program to loop at 100% CPU usage.
1716 - when the program encounters an overload, it will just loop until the
1766 stdin_readable_cb (struct ev_loop *loop, ev_io *w, int revents)
1768 ev_io_stop (loop, w);
1773 struct ev_loop *loop = ev_default_init (0);
1776 ev_io_start (loop, &stdin_readable);
1777 ev_run (loop, 0);
1794 early", below). If multiple timers become ready during the same loop
1820 ev_timer_start (loop, timer);
1825 ev_timer_stop (loop, timer);
1827 ev_timer_start (loop, timer);
1853 ev_timer_again (loop, timer);
1857 ev_timer_again (loop, timer);
1863 ev_timer_again (loop, timer);
2007 event loop will schedule your timeout to elapse at a system time of 500
2042 If the event loop is suspended for a long time, you can also force an
2128 do stuff) the timer will not fire more than once per event loop iteration.
2130 =item ev_timer_again (loop, ev_timer *)
2154 =item ev_tstamp ev_timer_remaining (loop, ev_timer *)
2157 then this time is relative to the current event loop time, otherwise it's
2179 one_minute_cb (struct ev_loop *loop, ev_timer *w, int revents)
2186 ev_timer_start (loop, &mytimer);
2192 timeout_cb (struct ev_loop *loop, ev_timer *w, int revents)
2200 ev_run (loop, 0);
2234 timers become ready during the same loop iteration then the ones with
2301 or make ANY other event loop modifications whatsoever, unless explicitly
2306 only event loop modification you are allowed to do).
2333 =item ev_periodic_again (loop, ev_periodic *)
2377 clock_cb (struct ev_loop *loop, ev_periodic *w, int revents)
2384 ev_periodic_start (loop, &hourly_tick);
2402 fmod (ev_now (loop), 3600.), 3600., 0);
2403 ev_periodic_start (loop, &hourly_tick);
2416 synchronously wake up an event loop.
2419 only within the same loop, i.e. you can watch for C<SIGINT> in your
2420 default loop and for C<SIGIO> in another loop, but you cannot watch for
2421 C<SIGINT> in both the default loop and another loop at the same time. At
2422 the moment, C<SIGCHLD> is permanently tied to the default loop.
2500 sigint_cb (struct ev_loop *loop, ev_signal *w, int revents)
2502 ev_break (loop, EVBREAK_ALL);
2507 ev_signal_start (loop, &signal_watcher);
2516 as the event loop isn't entered (or is continued from a watcher), i.e.,
2518 but forking and registering a watcher a few event loop iterations later or
2521 Only the default event loop is capable of handling signals, and therefore
2522 you can only register child watchers in the default event loop.
2530 Libev grabs C<SIGCHLD> as soon as the default event loop is
2534 synchronously as part of the event loop processing. Libev always reaps all
2542 C<SIGCHLD> after initialising the default loop, and making sure the
2543 default loop never gets destroyed. You are encouraged, however, to use an
2725 ev_timer_again (loop, w)>).
2754 =item ev_stat_stat (loop, ev_stat *)
2792 passwd_cb (struct ev_loop *loop, ev_stat *w, int revents)
2811 ev_stat_start (loop, &passwd);
2838 ev_stat_start (loop, &passwd);
2851 are pending), the idle watchers are being called once per event loop
2861 event loop has handled all outstanding events.
2866 sleep unnecessarily. Or in other words, it will loop as fast as possible.
2871 to do something on each event loop iteration - for example to balance load
2895 idle_cb (struct ev_loop *loop, ev_idle *w, int revents)
2898 ev_idle_stop (loop, w);
2909 ev_idle_start (loop, idle_watcher);
2912 =head2 C<ev_prepare> and C<ev_check> - customise your event loop!
2919 current event loop) or C<ev_loop_fork> from either C<ev_prepare> or
2947 with priority higher than or equal to the event loop and one coroutine
2949 loop from blocking if lower-priority coroutines are active, thus mapping
2968 useful because they are called once per event loop iteration. For
2971 is more work to do, you wait for the next event loop iteration, so other
2975 next event loop iteration. However, that isn't as soon as possible -
2980 C<ev_check> watcher. The C<ev_idle> watcher makes sure the event loop
3006 Glib event loop).
3018 io_cb (struct ev_loop *loop, ev_io *w, int revents)
3024 adns_prepare_cb (struct ev_loop *loop, ev_prepare *w, int revents)
3028 // actual code will need to loop here and realloc etc.
3033 ev_timer_start (loop, &tw);
3043 ev_io_start (loop, iow + i);
3049 adns_check_cb (struct ev_loop *loop, ev_check *w, int revents)
3051 ev_timer_stop (loop, &tw);
3063 ev_io_stop (loop, iow + i);
3066 adns_afterpoll (adns, fds, nfd, timeval_from (ev_now (loop));
3100 main loop is now no longer controllable by EV. The C<Glib::EV> module uses
3102 libglib event loop.
3132 This is a rather advanced watcher type that lets you embed one event loop
3134 loop, other types of watchers might be handled in a delayed or incorrect
3143 so nicely. In this case, you would create a kqueue-based loop and embed
3144 it into your default loop (which might use e.g. poll). Overall operation
3152 this case you would put all the high priority stuff in one loop and all
3156 time there might be events pending in the embedded loop. The callback
3160 to give the embedded loop strictly lower priority for example).
3163 will automatically execute the embedded loop sweep whenever necessary.
3166 is active, i.e., the embedded loop will automatically be forked when the
3167 embedding loop forks. In other cases, the user is responsible for calling
3168 C<ev_loop_fork> on the embedded loop.
3175 that you cannot get an embeddable loop. The recommended way to get around
3176 this is to have a separate variables for your embeddable loop, try to
3177 create it, and if that fails, use the normal loop for everything.
3181 While the C<ev_embed> watcher is running, forks in the embedding loop will
3182 automatically be applied to the embedded loop as well, so no special
3195 Configures the watcher to embed the given loop, which must be
3201 =item ev_embed_sweep (loop, ev_embed *)
3203 Make a single, non-blocking sweep over the embedded loop. This works
3209 The embedded event loop.
3215 Example: Try to get an embeddable event loop and embed it into the default
3216 event loop. If that is not possible, use the default loop. The default
3217 loop is stored in C<loop_hi>, while the embeddable loop is stored in
3218 C<loop_lo> (which is C<loop_hi> in the case no embeddable loop can be
3242 kqueue implementation). Store the kqueue/socket-only event loop in
3245 struct ev_loop *loop = ev_default_init (0);
3253 ev_embed_start (loop, &embed);
3257 loop_socket = loop;
3259 // now use loop_socket for all sockets, and loop for everything else
3262 =head2 C<ev_fork> - the audacity to resume the event loop after a fork
3266 C<ev_loop_fork>). The invocation is done before the event loop blocks next
3292 simply create a new event loop, which of course will be "empty", and
3298 When this is not possible, or you want to use the default loop for
3301 Destroying the default loop will "orphan" (not stop) all registered
3321 Cleanup watchers are called just before the event loop is being destroyed
3324 While there is no guarantee that the event loop gets destroyed, cleanup
3327 loop when you want them to be invoked.
3330 all other watchers, they do not keep a reference to the event loop (which
3346 Example: Register an atexit handler to destroy the default loop, so any
3359 =head2 C<ev_async> - how to wake up an event loop
3365 Sometimes, however, you need to wake up an event loop you do not control,
3376 even without knowing which loop owns the signal.
3475 =item ev_async_send (loop, ev_async *)
3478 an C<EV_ASYNC> event on the watcher into the event loop, and instantly
3488 C<ev_async_send>, reset when the event loop detects that).
3491 loop iteration, if the event loop is blocked, and no syscall at all if
3492 the event loop (or your program) is processing events. That means that
3501 event loop.
3503 C<ev_async_send> sets a flag in the watcher and wakes up the loop. When
3504 the loop iterates next and checks for the watcher to have become active,
3506 quickly check whether invoking the loop might be a good idea.
3510 is a time window between the event loop checking and resetting the async
3522 =item ev_once (loop, int fd, int events, ev_tstamp timeout, callback)
3557 =item ev_feed_fd_event (loop, int fd, int revents)
3562 =item ev_feed_signal_event (loop, int signum)
3600 static void my_cb (struct ev_loop *loop, ev_io *w_, int revents)
3696 The solution is to maintain "break this loop" variable for each C<ev_run>
3697 invocation, and use a loop around C<ev_run> until the condition is
3700 // main loop
3714 // exit modal loop
3717 // exit main program, after modal loop is finished
3725 Here is a fictitious example of how to run an event loop in a different
3733 The example uses a pthread mutex to protect the loop data, a condition
3735 event loop thread and an unspecified mechanism to wake up the main thread.
3737 First, you need to associate some data with the event loop:
3740 mutex_t lock; /* global loop lock */
3757 // now associate this with the loop
3767 solely to wake up the event loop so it takes notice of any new watchers
3777 protecting the loop data, respectively.
3793 The event loop thread first acquires the mutex, and then jumps straight
3799 struct ev_loop *loop = (struct ev_loop *)thr_arg;
3812 have been called (in a while loop because a) spurious wakeups are possible
3829 will grab the lock, call C<ev_invoke_pending> and then signal the loop
3844 event loop, you will now have to lock:
3857 an event loop currently blocking in the kernel will have no knowledge
3858 about the newly added timer. By waking up the loop it will pick up any new
3859 watchers in the next event loop iteration.
3965 other callbacks (allocator, syserr, loop acquire/release and periodic
4004 classes add (compared to plain C-style watchers) is the event loop pointer
4044 =item ev::TYPE::TYPE (loop)
4048 The constructor (optionally) takes an event loop to associate the watcher
4129 =item w->set (loop)
4143 clashing with the C<set (loop)> method.
4147 Starts the watcher. Note that there is no C<loop> argument, as the
4148 constructor already stores the event loop.
4158 Stops the watcher if it is active. Again, no C<loop> argument.
4281 This provides the loop I<argument> for functions, if one is required ("ev
4282 loop argument"). The C<EV_A> form is used when this is the sole argument,
4289 It assumes the variable C<loop> of type C<struct ev_loop *> is in scope,
4294 This provides the loop I<parameter> for functions, if one is required ("ev
4295 loop parameter"). The C<EV_P> form is used when this is the sole parameter,
4304 It declares a parameter C<loop> of type C<struct ev_loop *>, quite
4310 loop, if multiple loops are supported ("ev loop default"). The default loop
4314 to initialise the loop somewhere.
4319 default loop has been initialised (C<UC> == unchecked). Their behaviour
4320 is undefined when the default loop has not been initialised by a previous
4604 kqueue loop.
4676 If undefined or defined to C<1>, then all event-loop-specific functions
4679 for multiple event loops and there is no first event loop pointer
4680 argument. Instead, all functions act on the single default loop.
4683 default loop when multiplicity is switched off - you always have to
4684 initialise the loop manually in this case.
4721 but multiple event loop support, async and child watchers and the poll
4876 called once per loop, which can slow down libev. If set to C<3>, then the
4974 are no concurrent calls into any libev function with the same loop
4975 parameter (C<ev_default_*> calls have an implicit default loop parameter,
4979 Or to put it differently: calls with different loop parameters can be done
4980 concurrently from multiple threads, calls with the same loop parameter
4983 a mutex per loop).
4987 concurrency on the same event loop, namely waking it up "from the
4990 If you want to know which design (one loop, locking, or multiple loops
4996 =item * most applications have a main thread: use the default libev loop
4997 in that thread, or create a separate thread running only the default loop.
5002 =item * one loop per thread is usually a good model.
5008 loop is handed through multiple threads in a kind of round-robin fashion.
5014 event loop.
5020 work in the default loop by registering the signal watcher with the
5021 default loop and triggering an C<ev_async> watcher from the default loop
5022 watcher callback into the event loop interested in the signal.
5032 coroutines (e.g. you can call C<ev_run> on the same loop from two
5034 the loop, as long as you don't confuse yourself). The only exception is
5134 loop - embedding a socket-only kqueue loop into a select-based one is
5145 a loop.
5327 except the initial one, and run the signal handling loop in the initial
5394 =item Finding the next timer in each loop iteration: O(1)
5399 =item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
5421 calls in the current loop iteration and the loop is currently
5508 detected. Callbacks are being passed the event loop, the watcher that
5526 A software package implementing an event model and loop.
5528 =item event loop
5535 The model used to describe how an event loop handles and processes
5556 to be started (attached to an event loop) before they can receive events.