ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.124 by root, Fri Feb 1 13:41:03 2008 UTC vs.
Revision 1.130 by root, Wed Feb 6 18:34:24 2008 UTC

2078is that the author does not know of a simple (or any) algorithm for a 2078is that the author does not know of a simple (or any) algorithm for a
2079multiple-writer-single-reader queue that works in all cases and doesn't 2079multiple-writer-single-reader queue that works in all cases and doesn't
2080need elaborate support such as pthreads. 2080need elaborate support such as pthreads.
2081 2081
2082That means that if you want to queue data, you have to provide your own 2082That means that if you want to queue data, you have to provide your own
2083queue. And here is how you would implement locking: 2083queue. But at least I can tell you would implement locking around your
2084queue:
2084 2085
2085=over 4 2086=over 4
2086 2087
2087=item queueing from a signal handler context 2088=item queueing from a signal handler context
2088 2089
2097 { 2098 {
2098 sometype data; 2099 sometype data;
2099 2100
2100 // no locking etc. 2101 // no locking etc.
2101 queue_put (data); 2102 queue_put (data);
2102 ev_async_send (DEFAULT_LOOP, &mysig); 2103 ev_async_send (DEFAULT_ &mysig);
2103 } 2104 }
2104 2105
2105 static void 2106 static void
2106 mysig_cb (EV_P_ ev_async *w, int revents) 2107 mysig_cb (EV_P_ ev_async *w, int revents)
2107 { 2108 {
2125 2126
2126=item queueing from a thread context 2127=item queueing from a thread context
2127 2128
2128The strategy for threads is different, as you cannot (easily) block 2129The strategy for threads is different, as you cannot (easily) block
2129threads but you can easily preempt them, so to queue safely you need to 2130threads but you can easily preempt them, so to queue safely you need to
2130emply a traditional mutex lock, such as in this pthread example: 2131employ a traditional mutex lock, such as in this pthread example:
2131 2132
2132 static ev_async mysig; 2133 static ev_async mysig;
2133 static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER; 2134 static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
2134 2135
2135 static void 2136 static void
2138 // only need to lock the actual queueing operation 2139 // only need to lock the actual queueing operation
2139 pthread_mutex_lock (&mymutex); 2140 pthread_mutex_lock (&mymutex);
2140 queue_put (data); 2141 queue_put (data);
2141 pthread_mutex_unlock (&mymutex); 2142 pthread_mutex_unlock (&mymutex);
2142 2143
2143 ev_async_send (DEFAULT_LOOP, &mysig); 2144 ev_async_send (DEFAULT_ &mysig);
2144 } 2145 }
2145 2146
2146 static void 2147 static void
2147 mysig_cb (EV_P_ ev_async *w, int revents) 2148 mysig_cb (EV_P_ ev_async *w, int revents)
2148 { 2149 {
2695be detected at runtime. 2696be detected at runtime.
2696 2697
2697=item EV_ATOMIC_T 2698=item EV_ATOMIC_T
2698 2699
2699Libev requires an integer type (suitable for storing C<0> or C<1>) whose 2700Libev requires an integer type (suitable for storing C<0> or C<1>) whose
2700access is atomic with respect to other threads or signal contexts. No such type 2701access is atomic with respect to other threads or signal contexts. No such
2701is easily found using, so you cna provide your own type that you know is safe. 2702type is easily found in the C language, so you can provide your own type
2703that you know is safe for your purposes. It is used both for signal handler "locking"
2704as well as for signal and thread safety in C<ev_async> watchers.
2702 2705
2703In the absense of this define, libev will use C<sig_atomic_t volatile> 2706In the absense of this define, libev will use C<sig_atomic_t volatile>
2704from F<signal.h>, which is usually good enough on most platforms. 2707(from F<signal.h>), which is usually good enough on most platforms.
2705 2708
2706=item EV_H 2709=item EV_H
2707 2710
2708The name of the F<ev.h> header file used to include it. The default if 2711The name of the F<ev.h> header file used to include it. The default if
2709undefined is C<"ev.h"> in F<event.h>, F<ev.c> and F<ev++.h>. This can be 2712undefined is C<"ev.h"> in F<event.h>, F<ev.c> and F<ev++.h>. This can be
2910=item Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers) 2913=item Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)
2911 2914
2912That means that changing a timer costs less than removing/adding them 2915That means that changing a timer costs less than removing/adding them
2913as only the relative motion in the event queue has to be paid for. 2916as only the relative motion in the event queue has to be paid for.
2914 2917
2915=item Starting io/check/prepare/idle/signal/child watchers: O(1) 2918=item Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)
2916 2919
2917These just add the watcher into an array or at the head of a list. 2920These just add the watcher into an array or at the head of a list.
2918 2921
2919=item Stopping check/prepare/idle watchers: O(1) 2922=item Stopping check/prepare/idle/fork/async watchers: O(1)
2920 2923
2921=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE)) 2924=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))
2922 2925
2923These watchers are stored in lists then need to be walked to find the 2926These watchers are stored in lists then need to be walked to find the
2924correct watcher to remove. The lists are usually short (you don't usually 2927correct watcher to remove. The lists are usually short (you don't usually
2940=item Priority handling: O(number_of_priorities) 2943=item Priority handling: O(number_of_priorities)
2941 2944
2942Priorities are implemented by allocating some space for each 2945Priorities are implemented by allocating some space for each
2943priority. When doing priority-based operations, libev usually has to 2946priority. When doing priority-based operations, libev usually has to
2944linearly search all the priorities, but starting/stopping and activating 2947linearly search all the priorities, but starting/stopping and activating
2945watchers becomes O(1) w.r.t. prioritiy handling. 2948watchers becomes O(1) w.r.t. priority handling.
2949
2950=item Sending an ev_async: O(1)
2951
2952=item Processing ev_async_send: O(number_of_async_watchers)
2953
2954=item Processing signals: O(max_signal_number)
2955
2956Sending involves a syscall I<iff> there were no other C<ev_async_send>
2957calls in the current loop iteration. Checking for async and signal events
2958involves iterating over all running async watchers or all signal numbers.
2946 2959
2947=back 2960=back
2948 2961
2949 2962
2950=head1 Win32 platform limitations and workarounds 2963=head1 Win32 platform limitations and workarounds

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines