ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Async-Interrupt/schmorp.h
(Generate patch)

Comparing cvsroot/Async-Interrupt/schmorp.h (file contents):
Revision 1.2 by root, Fri Jul 17 01:51:32 2009 UTC vs.
Revision 1.3 by root, Fri Jul 17 21:02:18 2009 UTC

337#endif 337#endif
338 338
339typedef struct { 339typedef struct {
340 int fd[2]; /* read, write fd, might be equal */ 340 int fd[2]; /* read, write fd, might be equal */
341 int len; /* write length (1 pipe/socket, 8 eventfd) */ 341 int len; /* write length (1 pipe/socket, 8 eventfd) */
342 volatile sig_atomic_t sent;
343} s_epipe; 342} s_epipe;
344 343
345static int 344static int
346s_epipe_new (s_epipe *epp) 345s_epipe_new (s_epipe *epp)
347{ 346{
368 } 367 }
369 368
370 ep.len = 1; 369 ep.len = 1;
371 } 370 }
372 371
373 ep.sent = 0;
374 *epp = ep; 372 *epp = ep;
375 return 0; 373 return 0;
376} 374}
377 375
378static void 376static void
387} 385}
388 386
389static void 387static void
390s_epipe_signal (s_epipe *epp) 388s_epipe_signal (s_epipe *epp)
391{ 389{
392 if (epp->sent)
393 return;
394
395 epp->sent = 1;
396 {
397#ifdef _WIN32 390#ifdef _WIN32
398 /* perl overrides send with a function that crashes in other threads. 391 /* perl overrides send with a function that crashes in other threads.
399 * unfortunately, it overrides it with an argument-less macro, so 392 * unfortunately, it overrides it with an argument-less macro, so
400 * there is no way to force usage of the real send function. 393 * there is no way to force usage of the real send function.
401 * incompetent windows programmers - is this redundant? 394 * incompetent windows programmers - is this redundant?
402 */ 395 */
403 DWORD dummy; 396 DWORD dummy;
404 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); 397 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0);
405#else 398#else
406 static uint64_t counter = 1; 399 static uint64_t counter = 1;
407 /* some modules accept fd's from outside, support eventfd here */ 400 /* some modules accept fd's from outside, support eventfd here */
408 if (write (epp->fd [1], &counter, epp->len) < 0 401 if (write (epp->fd [1], &counter, epp->len) < 0
409 && errno == EINVAL 402 && errno == EINVAL
410 && epp->len != 8) 403 && epp->len != 8)
411 write (epp->fd [1], &counter, (epp->len = 8)); 404 write (epp->fd [1], &counter, (epp->len = 8));
412#endif 405#endif
413 }
414} 406}
415 407
416static void 408static void
417s_epipe_drain (s_epipe *epp) 409s_epipe_drain (s_epipe *epp)
418{ 410{
419 char buf [9]; 411 char buf [9];
420 412
413 fprintf (stderr, "drain\n");//D
421#ifdef _WIN32 414#ifdef _WIN32
422 recv (epp->fd [0], buf, sizeof (buf), 0); 415 recv (epp->fd [0], buf, sizeof (buf), 0);
423#else 416#else
424 read (epp->fd [0], buf, sizeof (buf)); 417 read (epp->fd [0], buf, sizeof (buf));
425#endif 418#endif
426
427 epp->sent = 0;
428} 419}
429 420
430/* like new, but dups over old */ 421/* like new, but dups over old */
431static int 422static int
432s_epipe_renew (s_epipe *epp) 423s_epipe_renew (s_epipe *epp)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines