|
|
@ -3864,10 +3864,10 @@ event loop thread and an unspecified mechanism to wake up the main thread. |
|
|
|
First, you need to associate some data with the event loop: |
|
|
|
|
|
|
|
typedef struct { |
|
|
|
mutex_t lock; /* global loop lock */ |
|
|
|
pthread_mutex_t lock; /* global loop lock */ |
|
|
|
pthread_t tid; |
|
|
|
pthread_cond_t invoke_cv; |
|
|
|
ev_async async_w; |
|
|
|
thread_t tid; |
|
|
|
cond_t invoke_cv; |
|
|
|
} userdata; |
|
|
|
|
|
|
|
void prepare_loop (EV_P) |
|
|
@ -3875,19 +3875,19 @@ First, you need to associate some data with the event loop: |
|
|
|
// for simplicity, we use a static userdata struct. |
|
|
|
static userdata u; |
|
|
|
|
|
|
|
ev_async_init (&u->async_w, async_cb); |
|
|
|
ev_async_start (EV_A_ &u->async_w); |
|
|
|
ev_async_init (&u.async_w, async_cb); |
|
|
|
ev_async_start (EV_A_ &u.async_w); |
|
|
|
|
|
|
|
pthread_mutex_init (&u->lock, 0); |
|
|
|
pthread_cond_init (&u->invoke_cv, 0); |
|
|
|
pthread_mutex_init (&u.lock, 0); |
|
|
|
pthread_cond_init (&u.invoke_cv, 0); |
|
|
|
|
|
|
|
// now associate this with the loop |
|
|
|
ev_set_userdata (EV_A_ u); |
|
|
|
ev_set_userdata (EV_A_ &u); |
|
|
|
ev_set_invoke_pending_cb (EV_A_ l_invoke); |
|
|
|
ev_set_loop_release_cb (EV_A_ l_release, l_acquire); |
|
|
|
|
|
|
|
// then create the thread running ev_run |
|
|
|
pthread_create (&u->tid, 0, l_run, EV_A); |
|
|
|
pthread_create (&u.tid, 0, l_run, EV_A); |
|
|
|
} |
|
|
|
|
|
|
|
The callback for the C<ev_async> watcher does nothing: the watcher is used |
|
|
|