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

Comparing libev/ev.3 (file contents):
Revision 1.122 by root, Mon Jun 8 11:15:59 2020 UTC vs.
Revision 1.123 by root, Sun Jul 26 11:10:45 2020 UTC

131.\} 131.\}
132.rm #[ #] #H #V #F C 132.rm #[ #] #H #V #F C
133.\" ======================================================================== 133.\" ========================================================================
134.\" 134.\"
135.IX Title "LIBEV 3" 135.IX Title "LIBEV 3"
136.TH LIBEV 3 "2020-04-19" "libev-4.33" "libev - high performance full featured event loop" 136.TH LIBEV 3 "2020-07-12" "libev-4.33" "libev - high performance full featured event loop"
137.\" For nroff, turn off justification. Always turn off hyphenation; it makes 137.\" For nroff, turn off justification. Always turn off hyphenation; it makes
138.\" way too many mistakes in technical documents. 138.\" way too many mistakes in technical documents.
139.if n .ad l 139.if n .ad l
140.nh 140.nh
141.SH "NAME" 141.SH "NAME"
4002.PP 4002.PP
4003First, you need to associate some data with the event loop: 4003First, you need to associate some data with the event loop:
4004.PP 4004.PP
4005.Vb 6 4005.Vb 6
4006\& typedef struct { 4006\& typedef struct {
4007\& mutex_t lock; /* global loop lock */ 4007\& pthread_mutex_t lock; /* global loop lock */
4008\& pthread_t tid;
4009\& pthread_cond_t invoke_cv;
4008\& ev_async async_w; 4010\& ev_async async_w;
4009\& thread_t tid;
4010\& cond_t invoke_cv;
4011\& } userdata; 4011\& } userdata;
4012\& 4012\&
4013\& void prepare_loop (EV_P) 4013\& void prepare_loop (EV_P)
4014\& { 4014\& {
4015\& // for simplicity, we use a static userdata struct. 4015\& // for simplicity, we use a static userdata struct.
4016\& static userdata u; 4016\& static userdata u;
4017\& 4017\&
4018\& ev_async_init (&u\->async_w, async_cb); 4018\& ev_async_init (&u.async_w, async_cb);
4019\& ev_async_start (EV_A_ &u\->async_w); 4019\& ev_async_start (EV_A_ &u.async_w);
4020\& 4020\&
4021\& pthread_mutex_init (&u\->lock, 0); 4021\& pthread_mutex_init (&u.lock, 0);
4022\& pthread_cond_init (&u\->invoke_cv, 0); 4022\& pthread_cond_init (&u.invoke_cv, 0);
4023\& 4023\&
4024\& // now associate this with the loop 4024\& // now associate this with the loop
4025\& ev_set_userdata (EV_A_ u); 4025\& ev_set_userdata (EV_A_ &u);
4026\& ev_set_invoke_pending_cb (EV_A_ l_invoke); 4026\& ev_set_invoke_pending_cb (EV_A_ l_invoke);
4027\& ev_set_loop_release_cb (EV_A_ l_release, l_acquire); 4027\& ev_set_loop_release_cb (EV_A_ l_release, l_acquire);
4028\& 4028\&
4029\& // then create the thread running ev_run 4029\& // then create the thread running ev_run
4030\& pthread_create (&u\->tid, 0, l_run, EV_A); 4030\& pthread_create (&u.tid, 0, l_run, EV_A);
4031\& } 4031\& }
4032.Ve 4032.Ve
4033.PP 4033.PP
4034The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used 4034The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used
4035solely to wake up the event loop so it takes notice of any new watchers 4035solely to wake up the event loop so it takes notice of any new watchers

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines