ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV-Loop-Async/Async.xs
(Generate patch)

Comparing EV-Loop-Async/Async.xs (file contents):
Revision 1.10 by root, Mon Jul 20 03:45:46 2009 UTC vs.
Revision 1.12 by root, Mon Nov 1 22:26:53 2010 UTC

10 10
11#include "EVAPI.h" 11#include "EVAPI.h"
12 12
13/* our userdata */ 13/* our userdata */
14typedef struct { 14typedef struct {
15 mutex_t lock; /* global loop lock */ 15 xmutex_t lock; /* global loop lock */
16 void (*signal_func) (void *signal_arg, int value); 16 void (*signal_func) (void *signal_arg, int value);
17 void *signal_arg; 17 void *signal_arg;
18 ev_async async_w; 18 ev_async async_w;
19 thread_t tid; 19 xthread_t tid;
20 unsigned int max_loops; 20 unsigned int max_loops;
21 unsigned int count; 21 unsigned int count;
22 22
23 cond_t invoke_cv; 23 xcond_t invoke_cv;
24 24
25 SV *interrupt; 25 SV *interrupt;
26#if defined(_WIN32) && defined(USE_ITHREADS) 26#if defined(_WIN32) && defined(USE_ITHREADS)
27 void *thx; 27 void *thx;
28#endif 28#endif
57 /* this is a bit tricky, but we can manage... */ 57 /* this is a bit tricky, but we can manage... */
58 u->count = 0; 58 u->count = 0;
59 59
60 ev_set_invoke_pending_cb (EV_A, fg_invoke_pending); 60 ev_set_invoke_pending_cb (EV_A, fg_invoke_pending);
61 ev_set_loop_release_cb (EV_A, 0, 0); 61 ev_set_loop_release_cb (EV_A, 0, 0);
62 ev_loop (EV_A, EVLOOP_NONBLOCK); 62 ev_run (EV_A, EVRUN_NOWAIT);
63 loop_set_cb (EV_A); 63 loop_set_cb (EV_A);
64 64
65 if (!u->count) 65 if (!u->count)
66 break; 66 break;
67 } 67 }
126 126
127 /* yeah */ 127 /* yeah */
128 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); 128 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
129 129
130 ev_ref (EV_A); 130 ev_ref (EV_A);
131 ev_loop (EV_A, 0); 131 ev_run (EV_A, 0);
132 ev_unref (EV_A); 132 ev_unref (EV_A);
133 133
134 l_release (EV_A); 134 l_release (EV_A);
135 135
136 return 0; 136 return 0;
163 PUSHs (sv_2mortal (newSViv (PTR2IV (c_func)))); 163 PUSHs (sv_2mortal (newSViv (PTR2IV (c_func))));
164 PUSHs (sv_2mortal (newSViv (SvIVX (SvRV (loop))))); 164 PUSHs (sv_2mortal (newSViv (SvIVX (SvRV (loop)))));
165 165
166void 166void
167_attach (SV *loop_, SV *interrupt, IV sig_func, void *sig_arg) 167_attach (SV *loop_, SV *interrupt, IV sig_func, void *sig_arg)
168 PROTOTYPE: @
168 CODE: 169 CODE:
169{ 170{
170 pthread_mutexattr_t ma; 171 pthread_mutexattr_t ma;
171 struct ev_loop *loop = (struct ev_loop *)SvIVX (SvRV (loop_)); 172 struct ev_loop *loop = (struct ev_loop *)SvIVX (SvRV (loop_));
172 udat *u; 173 udat *u;
181 182
182 ev_async_init (&u->async_w, async_cb); 183 ev_async_init (&u->async_w, async_cb);
183 ev_async_start (EV_A, &u->async_w); 184 ev_async_start (EV_A, &u->async_w);
184 185
185 pthread_mutexattr_init (&ma); 186 pthread_mutexattr_init (&ma);
187#ifdef PTHREAD_MUTEX_RECURSIVE
186 pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_RECURSIVE); 188 pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_RECURSIVE);
189#else
190 pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_RECURSIVE_NP);
191#endif
187 pthread_mutex_init (&u->lock, &ma); 192 pthread_mutex_init (&u->lock, &ma);
188 pthread_mutexattr_destroy (&ma); 193 pthread_mutexattr_destroy (&ma);
189 194
190 pthread_cond_init (&u->invoke_cv, 0); 195 pthread_cond_init (&u->invoke_cv, 0);
191 196

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines